zoukankan      html  css  js  c++  java
  • linux安装jdk、MySQL、nginx、redis

    一、Linux安装jdk

    1、yum一键安装

    查看

    1.查看是否已安装JDK
    # yum list installed |grep java
    
    2.卸载CentOS系统Java环境
    # yum -y remove java-1.8.0-openjdk*   *表示卸载所有openjdk相关文件输入 
    # yum -y remove tzdata-java.noarch       卸载tzdata-java  
    
    3.查看JDK软件包版本
    # yum -y list java*      或者使用# yum searchjava | grep -i --color JDK 
    
    查看JDK软件包列表
    # yum search java|grep jdk

    查看jdk安装路径
    # which java

    下载

    安装JDK
    # yum install java-1.8.0-openjdk*  安装java1.8.0所有程序 
    yum install -y java-1.8.0-openjdk-devel.x86_64
    
    注意:输入确认(y)直到控制台返回Complete安装成功
    
    查看java版本信息
    # java -version
    
    输入javac    java命令后显示帮助信息就算是安装成功了
    使用yum安装环境变量自动就配好了

    2、手动安装

    1.去官网下载需要安装的jdk版本,我这里用的是jdk-8u221-linux-x64.tar.gz

    2.将该压缩包放到/usr/local目录下(java需要自己创建,名字自己随意取,见名知意),然后解压该压缩包,输入如下指令:

    3.解压

    tar zxvf jdk-8u211-linux-x64.tar.gz

    4.ls查看

    5.配置环境变量,输入以下指令进行配置:

    进⼊到/etc⽬录,找到profile⽂件

    cd /etc
    vim profile

    6.vim命令进入到文件里,输入i进入编辑状态,在最后加上一下内容

    输入

    export JAVA_HOME=/usr/local/jdk1.8.0_211
    export JRE_HOME=$JAVA_HOME/jre
    export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
    export PATH=$JAVA_HOME/bin:$PATH

    7.按下esc,冒号:wq退出。

    让配置⽣效

    source /etc/profile

    二、linux安装MySQL

    1、在线安装(推荐)

    以下命令都需要在在/usr/local目录下执行(这个目录不是固定的,可以在其他位置安装)

    打开网址:MySQL Yum存储库

    找到对应linux的版本进行下载
    查看自己的版本:

    [root@localhost ~]# cat /etc/redhat-release
    CentOS Linux release 7.8.2003 (Core)

    1.1、通过wget指令下载mysql的rpm文件

    wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

    1.2、rpm安装mysql

     rpm -ivh mysql57-community-release-el7-10.noarch.rpm

    1.3、通过yum安装mysql服务

    yum -y install mysql-community-server

    1.4、加⼊开机启动

    systemctl enable mysqld

    1.5、启动MySQL服务

     systemctl start mysqld //启动服务
    yum install lsof -y //安装lsof lsof
    -i:3306 //查看mysql端口

    或者使⽤: service mysqld start

    1.6、停⽌MySQL服务

    systemctl stop mysqld

    或者使⽤: service mysqld stop

    2 、离线下载安装

    2.1 windows下载mysql安装⽂件(2个)

    MySQL-server-5.6.45-1.el7.x86_64.rpm
    MySQL-client-5.6.45-1.el7.x86_64.rpm 

    2.2、将安装包上传到linux(/usr/local)

    2.3、清除centos⾃带的mariaDB

    [root@theo local] [root@theo local]# rpm -qa | grep mariadb
    [root@theo local] [root@theo local]# rpm -e --nodeps mariadb-libs-...

    2.4、安装mysql的服务和客户端

    oot@theo local] [root@theo local]#rpm -ivh MySQL-server-5.6.45-1.el7.x86_64.rpm
    [root@theo local] [root@theo local]#rpm -ivh MySQL-client-5.6.45-1.el7.x86_64.rpm

    3、 MySQL基本使⽤

    # 1.查找初始密码
    cat /var/log/mysqld.log | grep password
    # 2.登录到mysql
    [root@theo log] [root@theo log]# mysql -uroot -p
    Enter password:
    # 3.修改密码
    # 3-1 设置密码的检查机制为LOW
    set global validate_password_policy=LOW;
    # 3-2 修改密码
    set password=password('admin123');
    # 4.授权远程登录(否则在windows里是链接不了mysql的,允许远程所有机器的root用户密码123来进行链接)
    # 授予所有权限
    *.*(表示所有机器)
    GRANT ALL PRIVILEGES on *.* to 'root'@'%' IDENTIFIED by 'admin123' WITH GRANT OPTION; flush PRIVILEGES;

    三、Linux安装nginx

    1、 安装编译⼯具(nginx安装之前需要c语言环境编译)

    yum install -y gcc gcc-c++

    2、 安装PCRE

    2.1、下载

    wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

    2.2、解压

    [root@stucode local]# tar -zxvf pcre-8.35.tar.gz

    2.3、进⼊pcre⽬录

    [root@stucode local]# cd pcre-8.35
    [root@stucode pcre-8.35]#

    2.4、配置

    [root@stucode pcre-8.35]# ./configure

    2.5、编译安装

    make表示编译,make install表示安装(可以分开执行,也可以一起执行,用&&一起执行)

    [root@stucode pcre-8.35]# make && make install

    3、安装SSL


    [root@stucode pcre-8.35]# cd /usr/local
    [root@stucode local]# wget --no-check-certificate http://www.openssl.org/source/openssl-1.0.1j.tar.gz

    [root@stucode local]# tar -zxvf openssl-1.0.1j.tar.gz

    [root@stucode local]# cd openssl-1.0.1j
    [root@stucode openssl-1.0.1j]# ./config

    [root@stucode openssl-1.0.1j]# make && make install

    4、安装zlib

    cd /usr/local
    wget http://zlib.net/zlib-1.2.11.tar.gz
    tar -zxvf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure
    make && make install

    5 、安装Nginx

    # cd /usr/local
    # wget http://nginx.org/download/nginx-1.16.1.tar.gz
    # tar -zxvf nginx-1.16.1.tar.gz
    # mkdir -p server/nginx
    # cd nginx-1.16.1
    # ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35
    # make && make install
    # 如果在配置过程中出现了以下错误:
    ./configure: error: SSL modules require the OpenSSL library.
    You can either do not enable the modules, or install the OpenSSL library
    into the system, or build the OpenSSL library statically from the source
    with nginx by using --with-openssl=<path> option.
    # 执⾏: yum -y install openssl openssl-devel
    再次执行上边的命令

    Nginx目录结构分析

    在使用Nginx之前,我们先对安装好的Nginx目录文件进行一个分析,在这块给大家介绍一个工具tree,通过tree我们可以很方面的去查看centos系统上的文件目录结构,当然,如果想使用tree工具,就得先通过yum install -y tree来进行安装,安装成功后,可以通过执行tree /usr/local/nginx(tree后面跟的是Nginx的安装目录),获取的结果如下:

    6 、配置Nginx
    vim /usr/local/server/nginx/conf/nginx.conf

    7、 启动Nginx 

    [root@stucode ~]# cd /usr/local/server/nginx/sbin/
    [root@stucode sbin]# ./nginx
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] still could not bind()
    [root@stucode sbin]# ./nginx -s stop
    [root@stucode sbin]# ./nginx
    [root@stucode sbin]# lsof -i:80
    COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    AliYunDun 20638   root   20u  IPv4  84405      0t0  TCP stucode:37074->110.110.11.11:http (ESTABLISHED)
    nginx     25795   root    6u  IPv4 339202      0t0  TCP *:http (LISTEN)
    nginx     25796 nobody    6u  IPv4 339202      0t0  TCP *:http (LISTEN)
    [root@stucode sbin]#

    8、正常访问

    服务器地址:http://123.57.149.21/(默认端口是80的情况,否则要加上端口号)

    9、【Nginx】启动成功无法访问网页

    问题图如下,访问网页无效

    10、解决方案

    1、重新启动nginx

    cd /usr/local/server/nginx/sbin/
    ./nginx -s reload

    2、查看是否有nginx进程


    [root@stucode ~]# ps -ef | grep nginx
    root 25795 1 0 23:41 ? 00:00:00 nginx: master process ./nginx
    nobody 25796 25795 0 23:41 ? 00:00:00 nginx: worker process
    root 25836 25811 0 23:51 pts/7 00:00:00 grep --color=auto nginx

    3、查看nginx的80端口是否启动

    [root@stucode ~]# lsof -i:80
    COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    AliYunDun 20638   root   20u  IPv4  84405      0t0  TCP stucode:37074->111.100.11.11:http (ESTABLISHED)
    nginx     25795   root    6u  IPv4 339202      0t0  TCP *:http (LISTEN)
    nginx     25796 nobody    6u  IPv4 339202      0t0  TCP *:http (LISTEN)

    4、防护墙配置开放80端口

    第一步,对80端口进行防火墙配置:

    firewall-cmd --zone=public --add-port=80/tcp --permanent

    第二步,重启防火墙服务:

    systemctl restart firewalld.service

    5、服务器其配置安全组(我的是阿里云服务)

    四、linux安装redis

    Redis官方网站:http://redis.io

    Redis中文官方网站:http://redis.cn/

    1、安装C 语言的编译环境

    yum install centos-release-scl scl-utils-build

    yum install -y devtoolset-8-toolchain

    scl enable devtoolset-8 bash

    2、查看c语言是否安装

    如果未安装,参考三安装nginx里的安装c语言编译环境命令

    [root@stucode ~]# gcc --version
    gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
    Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    3、下载redis-6.2.1.tar.gz放/usr/local/目录

    4、 解压命令:tar -zxvf redis-6.2.1.tar.gz

    5、 解压完成后进入目录:cd redis-6.2.1

    6、执行命令进行编译和安装:make && make install

    7、进入到/usr/local/bin目录,查看默认安装目录

    [root@stucode redis-6.2.1]# cd /usr/local/bin
    [root@stucode bin]# ll
    total 19132
    -rwxr-xr-x 1 root root    2363 Jan 12 22:23 pcre-config
    -rwxr-xr-x 1 root root   97816 Jan 12 22:23 pcregrep
    -rwxr-xr-x 1 root root  195008 Jan 12 22:23 pcretest
    -rwxr-xr-x 1 root root 4832256 Jan 15 01:57 redis-benchmark
    lrwxrwxrwx 1 root root      12 Jan 15 01:57 redis-check-aof -> redis-server
    lrwxrwxrwx 1 root root      12 Jan 15 01:57 redis-check-rdb -> redis-server
    -rwxr-xr-x 1 root root 5002312 Jan 15 01:57 redis-cli
    lrwxrwxrwx 1 root root      12 Jan 15 01:57 redis-sentinel -> redis-server
    -rwxr-xr-x 1 root root 9450904 Jan 15 01:57 redis-server

    文件说明 

    redis-benchmark:性能测试工具,可以在自己本子运行,看看自己本子性能如何
    redis-check-aof:修复有问题的AOF文件,rdb和aof后面讲
    redis-check-dump:修复有问题的dump.rdb文件
    redis-sentinel:Redis集群使用
    redis-server:Redis服务器启动命令
    redis-cli:客户端,操作入口

    8、启动redis

    8.1、前台启动(不推荐)

    前台启动,命令行窗口不能关闭,否则服务器停止

    [root@stucode nginx-1.16.1]# cd /usr/local/bin
    [root@stucode bin]# redis-server

    ctrl+c退出

    8.2、后台启动(推荐)

    8.2.1、备份/usr/local/redis-6.2.1/redis.conf文件到/etc目录下
    [root@stucode redis-6.2.1]# cd /usr/local/redis-6.2.1/
    [root@stucode redis-6.2.1]# ls
    00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    TLS.md
    BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests  utils
    [root@stucode redis-6.2.1]# cp redis.conf /etc/redis.conf
    [root@stucode redis-6.2.1]# cd /etc
    [root@stucode etc]# ls
    adjtime                  depmod.d                 group-         libuser.conf              opt             redhat-release  sysconfig
    aliases                  dhcp                     grub2.cfg      locale.conf               os-release      redis.conf      sysctl.conf
    aliases.db               DIR_COLORS               grub.d         localtime                 pam.d           resolv.conf     sysctl.d
    alternatives             DIR_COLORS.256color      gshadow        login.defs                passwd          rpc             systemd
    anacrontab               DIR_COLORS.lightbgcolor  gshadow-       logrotate.conf            passwd-         rpm             system-release
    asound.conf              dnsmasq.conf             gss            logrotate.d               pkcs11          rsyslog.conf    system-release-cpe
    at.deny                  dnsmasq.d                host.conf      lsb-release.d             pki             rsyslog.d       tcsd.conf
    audisp                   dracut.conf              hostname       machine-id                plymouth        rwtab           terminfo
    audit                    dracut.conf.d            hosts          magic                     pm              rwtab.d         timezone
    avahi                    dracut.conf.d?           hosts.allow    mail.rc                   polkit-1        sasl2           tmpfiles.d
    bash_completion.d        e2fsck.conf              hosts.deny     makedumpfile.conf.sample  popt.d          securetty       tuned
    bashrc                   egl                      init.d         man_db.conf               postfix         security        udev
    binfmt.d                 eni_utils                inittab        maven                     ppp             selinux         vconsole.conf
    centos-release           environment              inputrc        mke2fs.conf               prelink.conf.d  services        vimrc
    centos-release-upstream  ethertypes               iproute2       modprobe.d                printcap        sestatus.conf   virc
    chkconfig.d              exports                  issue          modules-load.d            profile         shadow          wgetrc
    cloud                    favicon.png              issue.net      motd                      profile.d       shadow-         wpa_supplicant
    cron.d                   filesystems              java           mtab                      protocols       shells          X11
    cron.daily               firewalld                jvm            my.cnf                    python          skel            xdg
    cron.deny                fonts                    jvm-commmon    my.cnf.d                  rc0.d           ssh             xinetd.d
    cron.hourly              fstab                    kdump.conf     NetworkManager            rc1.d           ssl             yum
    cron.monthly             gcrypt                   kernel         networks                  rc2.d           statetab        yum.conf
    crontab                  GeoIP.conf               krb5.conf      nscd.conf                 rc3.d           statetab.d      yum.repos.d
    cron.weekly              GeoIP.conf.default       krb5.conf.d    nsswitch.conf             rc4.d           subgid
    crypttab                 glvnd                    ld.so.cache    nsswitch.conf.bak         rc5.d           subuid
    csh.cshrc                gnupg                    ld.so.conf     nsswitch.conf.rpmnew      rc6.d           sudo.conf
    csh.login                GREP_COLORS              ld.so.conf.d   ntp                       rc.d            sudoers
    dbus-1                   groff                    libaudit.conf  ntp.conf                  rc.local        sudoers.d
    default                  group                    libnl          openldap                  redhat-lsb      sudo-ldap.conf
    8.2.2、后台启动设置daemonize no改成yes

    修改redis.conf(128行)文件将里面的daemonize no 改成 yes,让服务在后台启动

    :wq!退出

    8.2.3、后台启动设置daemonize no改成yes

    redis-server /etc/redis.conf 启动redis
    ps -ef | grep redis 查看redis进程
    redis-cli 通过客户端链接redis
    ping 验证测试

    [root@stucode etc]# vi redis.conf
    [root@stucode etc]# cd /usr/local/bin
    [root@stucode bin]# ls
    dump.rdb  pcre-config  pcregrep  pcretest  redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
    [root@stucode bin]# redis-server /etc/redis.conf
    [root@stucode bin]# ps -ef | grep redis
    root     30565     1  0 02:22 ?        00:00:00 redis-server 127.0.0.1:6379
    root     30571 30524  0 02:23 pts/5    00:00:00 grep --color=auto redis
    [root@stucode bin]# redis-cli
    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379>
    8.2.3、Redis关闭

    单实例关闭:redis-cli shutdown

    通过杀进程的方式关闭:kill -9 进程号

     

  • 相关阅读:
    Linux下C程序的反汇编【转】
    数据在内存中的存储方式( Big Endian和Little Endian的区别 )(x86系列则采用little endian方式存储数据)【转】
    linux arm的存储分布那些事之一【转】
    linux arm mmu基础【转】
    linux 进程内存解析【转】
    如何更方便的查看Linux内核代码的更新记录【转】
    设备树解析【转】
    分析内核源码,设备树【转】
     Meltdown论文翻译【转】
    device tree --- #address-cells and #size-cells property【转】
  • 原文地址:https://www.cnblogs.com/konglxblog/p/15782645.html
Copyright © 2011-2022 走看看