系统类型 |
IP地址 |
主机名 |
所需软件 |
centos7.8 |
192.168.100.101 |
nginx.linux.cn |
nginx-1.22.0.tar.gz |
centos7.8 |
192.168.100.102 |
tomcat1.linux.cn |
apache-tomcat-9.0.10.tar.gz jdk-8u171-linux-x64.tar.gz |
centos7.8 |
192.168.100.103 |
tomcat2.linux.cn |
apache-tomcat-9.0.10.tar.gz jdk-8u171-linux-x64.tar.gz |
centos7.8 |
192.168.100.104 |
mysql.linux.cn |
mariadb-server、mysql |
[root@nginx ~]# yum -y install pcre-devel zlib-devel
[root@nginx ~]# useradd -M -s /sbin/nologin nginx
[root@nginx ~]# tar xf nginx-1.22.0.tar.gz -C /usr/src/
[root@nginx ~]# cd /usr/src/nginx-1.22.0/
[root@nginx nginx-1.22.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@nginx nginx-1.22.0]# make && make install
[root@nginx nginx-1.22.0]# cd
[root@nginx ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx ~]# cat <<END >>/usr/lib/systemd/system/nginx.service
[Unit]
Description=nginxapi
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=kill -s HUP \$(cat /usr/local/nginx/logs/nginx.pid)
ExecStop=kill -s QUIT \$(cat /usr/local/nginx/logs/nginx.pid)
PrivateTmp=Flase
[Install]
WantedBy=multi-user.target
END
[root@nginx ~]# systemctl start nginx
[root@nginx ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@nginx ~]# netstat -utpln |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6005/nginx: master

[root@tomcat1 ~]# vi /usr/local/tomcat/conf/server.xml
150 <Context docBase="/web/webapp" path="" reloadable="false"></Context> #在150行左右位置添加
[root@tomcat1 ~]# mkdir -p /web/webapp
[root@tomcat1 ~]# cat <<END >>/web/webapp/index.jsp
192.168.100.102
END
[root@tomcat1 ~]# /usr/local/tomcat/bin/shutdown.sh
[root@tomcat1 ~]# /usr/local/tomcat/bin/startup.sh


[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
34 upstream tomserver {
35 server 192.168.100.102:8080 weight=1;
36 server 192.168.100.103:8080 weight=2;
37 }
52 location ~\.(jsp|do|js|css|png|jpg|jpeg)$ {
53 proxy_pass http://tomserver;
54 }
[root@nginx ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
-
访问测试Nginx验证页面切换



-
安装部署MySQL程序
[root@mysql ~]# yum -y install mariadb-server mysql
[root@mysql ~]# systemctl start mariadb
[root@mysql ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@mysql ~]# netstat -utpln |grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1423/mysqld
[root@mysql ~]# mysqladmin -u root password 123123
[root@mysql ~]# mysql -uroot -p123123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>exit
[root@mysql ~]# ls
smbms_db.sql
[root@mysql ~]# mysql -uroot -p123123 <smbms_db.sql
[root@mysql ~]# mysql -uroot -p123123
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| smbms |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> use smbms;
MariaDB [smbms]> show tables;
+-----------------+
| Tables_in_smbms |
+-----------------+
| smbms_address |
| smbms_bill |
| smbms_provider |
| smbms_role |
| smbms_user |
+-----------------+
5 rows in set (0.00 sec)
MariaDB [smbms]> grant all on smbms.* to 'linux'@'192.168.100.102' identified by '123123';
MariaDB [smbms]> grant all on smbms.* to 'linux'@'192.168.100.103' identified by '123123';
MariaDB [smbms]> flush privileges;
MariaDB [smbms]> exit
- 将测试项目的文件部署到Tocmat节点(两个tomcat节点配置一致,在此列举tomcat1)
[root@tomcat1 webapp]# ls
WebRoot
[root@tomcat1 webapp]# vi /web/webapp/WebRoot/WEB-INF/classes/database.properties
driver=com.mysql.jdbc.Driver
#在和mysql传递数据的过程中,使用unicode编码格式,并且字符集设置为utf-8
url=jdbc:mysql://192.168.100.104:3306/smbms?useUnicode=true&characterEncoding=utf-8
user=linux
password=123123
[root@tomcat1 webapp]# vi /usr/local/tomcat/conf/server.xml
150 <Context docBase="/web/webapp/WebRoot/" path="" reloadable="false"></Context>
root@tomcat1 webapp]# /usr/local/tomcat/bin/shutdown.sh
[root@tomcat1 webapp]# /usr/local/tomcat/bin/startup.sh
-
测试访问tomcat单点,登录超时管理系统


-
修改Nginx配置,实现会话保持,避免登录错误
[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
34 upstream tomserver {
35 ip_hash;
36 server 192.168.100.102:8080 weight=1;
37 server 192.168.100.103:8080 weight=2;
38 }

[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
56 location /shopping {
57 rewrite ^/(.*) http://192.168.100.101/login.jsp permanent;
58 }
[root@nginx ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# /usr/local/nginx/sbin/nginx -s reload
