集群架构-软件安装(nginx-tomcat -mysql-JDK-Redis)

随着项目的不断扩大,用户访问量的增长,为此搭建一个集群的环境来满足用户需求是很有必要的。通过本人的亲手安装配置,现将有关过程粗略记录如下,以备自己往后查阅或供刚入门的同学们参考(由于水平有限,欢迎大家一起交流学习)

安装系统环境:centos7.2  cup4核 ,64位

 JDK安装

     1. 下载   https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

     2  切换到root用户:(su  root

     3. 开始安装 : rpm -ivh jdk-8uversion-linux-x64.rpm

      4.  设置环境变量

        JDK默认目录,如:/usr/java/jdk1.8.0_201-amd64

        命令:vi /etc/profile

       #set_JDK-在文档末尾增加如下

       export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64

       export JRE_HOME=$JAVA_HOME/jre

       export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH

       export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

       保存文档 :按esc键,输入“:”,再输wq, 回车保存

      执行命令使配置生效:source /etc/profile

      5. 查看是否设置成功,如查看当前JDK版本: java  -version


二 安装tomcat

     1. 下载相关版本 ::https://tomcat.apache.org/download-80.cgi

     2. 解压及配置环境变量

    3 .Tomcat 多实例配置  参考:https://blog.51cto.com/elain/621663

   可能出现问题:

       在关闭tomcat某个实例时,无法通过pid正常关闭:

      解决方法:https://blog.youkuaiyun.com/u014137486/article/details/54381249

     https://www.jianshu.com/p/0530b5ca8d61

 


安装Mysql

    1. 下载软件包及安装说明

         https://dev.mysql.com/downloads/file/?id=484747

         https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html

    2. 以root用户登录

    3. 创建用户及用户组

          groupadd mysql

          useradd -r -g mysql -s /bin/false mysql

          创建mysql的数据存储目录及日志目录  如:

         mkdir   /data/mysqldir8015

         mkdir   /data/mysqllog8015

         chown mysql.mysql    /data/mysqldir8015

         chown mysql.mysql   /data/mysqllog8015

        [root@d8app bin]#tar -xvf    /data/soft/mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz

        [root@d8app bin]#mv  ./mysql-8.0.15-linux-glibc2.12-x86_64   /usr/local/mysql8015     //将解压后的文件夹移动到准备要指定安装的目录,如:/usr/local/mysql8015

      [root@d8app ]#cd /usr/local/mysql8015

      [root@d8app mysql8015]#chown -R mysql:mysql ./            ////将mysql8015目录及下面所有文件归mysql用户所属

      [root@d8app mysql8015]#cd   /usr/local/mysql8015/bin

     [root@d8app bin]#./mysqld --initialize --user=mysql --basedir=/usr/local/mysql8015  --datadir=/data/mysqldir8015

    执行成功后(会显示随机生成的数据库root用户的临时密码,请记下来)末尾会出现如下:

   ***********************************************************************************

2019-02-18T09:44:18.754864Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.

2019-02-18T09:44:18.755040Z 0 [System] [MY-013169] [Server] /usr/local/mysql8015/bin/mysqld (mysqld 8.0.15) initializing of server in progress as process 23383

2019-02-18T09:44:28.892784Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: nP-Da?TLf9nV

2019-02-18T09:44:34.167424Z 0 [System] [MY-013170] [Server] /usr/local/mysql8015/bin/mysqld (mysqld 8.0.15) initializing of server has completed

*************************************************************************************

  //将mysql的配置文件存放在/etc目录下

   [root@d8app mysql8015]#cp    /usr/local/mysql8015/support-files/my-default.cnf      /etc/mysql8015.cnf 

     复制过去,其实也就是空白页,一开始没有my-default.cnf这个文件,可以创建一个

    #touch   my-default.cnf    命令创建一个,并配置权限 

    # chmod  755   ./my-default.cnf 

    //配置mysql启动服务

    # cp  -p  /usr/local/mysql8015/support-files/mysql.server       /etc/init.d/mysql8015

    # vi  /etc/mysql8015.cnf     //修改mysql配置,参考网上资料

    # vi /etc/init.d/mysql8015        //修改mysql启动文件

   设置开机启动:

      [root@d8app  /etc/init.d/]#chkconfig --add mysql8015

      [root@d8app  /etc/init.d/]#chkconfig mysql8015 on

      [root@d8app  /etc/init.d/]## chkconfig --list       //查看系统已启动的相关服务

      [root@d8app  /etc/init.d/]#service mysql8015 start      //启动mysql

以上安装过程 ,可能出现错误,请查阅相关错误日志error.log ,这点很重要!!

如出现以下报错: 查看error.log

*********************************************************************

 启动报错: Starting MySQL. ERROR! The server quit without updating PID file (/data/mysqldir8015/mysql8015.pid).

*****************************************************************

以下日志文件:

2019-02-19T01:13:30.670741Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2019-02-19T01:13:30.670824Z 0 [System] [MY-010116] [Server] /usr/local/mysql8015/bin/mysqld (mysqld 8.0.15) starting as process 22539
2019-02-19T01:13:30.684262Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-02-19T01:13:30.684635Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-02-19T01:13:30.684785Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-02-19T01:13:30.685892Z 0 [System] [MY-010910] [Server] /usr/local/mysql8015/bin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.

解决办法(mysql.server):

     1. 查看指定的存放数据目录的读写权限

     2. mysql启动文件( /etc/init.d/mysql8015)中,【case "$mode" in  'start') 】代码前指定  

            datadir=/data/mysqldir8015

            mysqld_pid_file_path=/data/mysqldir8015/mysql8015.pid

      参考:https://blog.youkuaiyun.com/qq_39127024/article/details/83625137

*************************************************************************************************

启动成功后, 登录mysql, 创建和修改目录等

[root@d8app]#mysql --socket=/data/mysqldir8015/mysql.sock -uroot -p

[root@d8app]#use mysql;

[root@d8app]#show databases; 

[root@d8app]#ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root#1234';

select host,user,authentication_string,plugin from user;

CREATE USER 'root'@'%' IDENTIFIED BY 'root#1234';     //开启允许远程登录

GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;

flush privileges;

查询用户权限:SHOW GRANTS FOR 'root'@'%';

收回某些权限或所有:REVOKE ALL ON *.* FROM 'root'@'%';

开启端口: iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

报错:**************************************************************

登陆mysql show databases出现Ignoring query to other database错误,又试了几个命令和sql全部提示Ignoring query to other database错误

产生原因:连接mysql时没有"-u"参数导致的

解决方法:mysql   --socket=/data/mysqldir8015/mysql.sock  -uroot  -p

**************************************************************************

参考:https://www.cnblogs.com/xyabk/p/8967990.html


四  安装Redis

       参考:https://www.cnblogs.com/codersay/p/4301677.html

     1. 下载地址:https://redis.io/download

     安装过程如下:

     $ wget http://download.redis.io/releases/redis-5.0.3.tar.gz

     $ tar xzf redis-5.0.3.tar.gz

     $ cd redis-5.0.3

     $ make

    The binaries that are now compiled are available in the src directory. Run Redis with:

     $ src/redis-server            //启动

启动:/usr/local/redis-5.0.3/src/redis-server /etc/redis503.conf

开启端口: iptables -I INPUT -p tcp --dport 6379 -j ACCEPT

注:redis503.conf  ,需要根据实际情况配置

*****************************************************************************

安装过程中,可以出现如下错误:

root@~/workspace/redis5.0.3/src  $ make test

You need tcl 8.5 or newer in order to run the Redis test

make: *** [test] Error 1

  1. wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
  2. sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
  3. cd /usr/local/tcl8.6.1/unix/
  4. sudo ./configure
  5. sudo make
  6. sudo make install

五  安装nginx

      参考安装:[http://www.cnblogs.com/dennisit/archive/2012/12/26/2834719.html]

      1. 下载地址: http://nginx.org/en/download.html

      2. Nginx的安装需要依赖下面3个包

          gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )

          rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )

          ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )

         依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.

          openssl-1.1.1a.tar.gz https://www.openssl.org/source/

          openssl-fips-2.0.16.tar.gz

          zlib-1.2.11.tar.gz 

          pcre-8.42.tar.gz

          nginx-1.14.2.tar.gz

          nginx*******-1.14.2****************安装过程****************************************

         cd /data/soft/nginx-1.14.2

         tar -xvf   nginx-1.14.2.tar.gz

        [root@linux local]# cd /data/soft/nginx-1.14.2

        [root@linux nginx-1.14.2]# ls

          auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src

       /**************************************************

           ./configure  --prefix=/usr/local/nginx114

      /*************************************************

     [root@linux nginx-1.14.2]# make

......................

objs/ngx_modules.o \

-ldl -lpthread -lcrypt -lpcre -lz \

-Wl,-E

sed -e "s|%%PREFIX%%|/usr/local/nginx114|" \

-e "s|%%PID_PATH%%|/usr/local/nginx114/logs/nginx.pid|" \

-e "s|%%CONF_PATH%%|/usr/local/nginx114/conf/nginx.conf|" \

-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx114/logs/error.log|" \

< man/nginx.8 > objs/nginx.8

make[1]: 离开目录“/data/soft/nginx-1.14.2”

[root@linux nginx-1.14.2]# make install

make -f objs/Makefile install

make[1]: 进入目录“/data/soft/nginx-1.14.2”

 

查询nginx安装目录

[root@linux nginx-1.14.2]# ls /usr/local/

bin etc games include lib lib64 libexec nginx114 

[root@linux nginx-1.14.2]# cd /usr/local/nginx114/

[root@linux nginx114]# ll

总用量 4

drwxr-xr-x. 2 root root 4096 2月 16 08:30 conf

drwxr-xr-x. 2 root root 38 2月 16 08:30 html

drwxr-xr-x. 2 root root 6 2月 16 08:30 logs

drwxr-xr-x. 2 root root 18 2月 16 08:30 sbin

[root@linux nginx114]# cd /usr/local/nginx114/sbin/

[root@linux sbin]# ll

总用量 3660

-rwxr-xr-x. 1 root root 3747368 2月 16 08:30 nginx

[root@linux sbin]# ./nginx -t //查询是否安装成功

nginx: the configuration file /usr/local/nginx114/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx114/conf/nginx.conf test is successful

[root@linux sbin]#

启动nginx

[root@linux sbin]# ./nginx

查看端口6379

[root@linux sbin]# netstat -ntlp  

启动时指定配置文件(nginx.conf 配置文件需要根据实际情况具体配置,请查阅网上相关资料)

[root@linux sbin]# nginx -c /usr/local/nginx114/conf/nginx.conf

修改配置文件后,重新加载:nginx -s reload

运行时快速关闭nginx:  nginx -s stop            或   kill -9   xxxx

运行时优雅关闭nginx

所有的工作进程会停止接受新的连接,并继续服务旧的连接请求直到所有的请求完成后才退出。

nginx -s quit

 

至此安装完毕!!!

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值