案例环境:
系统类型 |
IP地址 |
主机名 |
所需软件 |
Centos 7.4 1708 64bit |
192.168.100.101 |
Nginx |
nginx-1.12.2.tar.gz |
Centos 7.4 1708 64bit |
192.168.100.102 |
Tomcat1 |
apache-tomcat-9.0.10.tar.gz jdk-8u171-linux-x64.tar.gz nfs-utils、rpcbind |
Centos 7.4 1708 64bit |
192.168.100.103 |
Tomcat2 |
apache-tomcat-9.0.10.tar.gz jdk-8u171-linux-x64.tar.gz nfs-utils、rpcbind |
Centos 7.4 1708 64bit |
192.168.100.104 |
NFS |
nfs-utils、rpcbind、JAVA项目 |
Centos 7.4 1708 64bit |
192.168.100.105 |
MySQL |
MySQL 、项目smbms_db.sql |
Nginx反向代理服务器的配置192.168.100.101
[root@nginx ~]#yum -y install pcre-devel zlib-devel
[root@nginx ~]#useradd -M -s /sbin/nologin nginx
[root@nginx ~]#tar zxvf nginx-1.12.2.tar.gz -C /usr/src/
[root@nginx ~]# cd /usr/src/nginx-1.12.2/
[root@nginx nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@nginx nginx-1.12.2]# make && make install
[root@nginx nginx-1.12.2]# cd
[root@nginx ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx ~]#vim /usr/lib/systemd/system/nginx.service #nginx的启动脚本
[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
[root@nginx ~]#yum -y remove httpd
[root@nginx ~]#systemctl start nginx
[root@nginx ~]#systemctl enable nginx
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
upstream tomcat{
ip_hash;
server 192.168.100.102:8080 weight=1; #负载均衡轮询算法
server 192.168.100.103:8080 weight=1;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ \.(js|asp|aspx|php|jsp|do|css|jpg|png) {
proxy_pass http://tomcat;
}
[root@nginx ~]# systemctl stop nginx
[root@nginx ~]#systemctl start nginx
[root@nginx ~]# netstat -tunlp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4747/nginx: master
NFS服务器的部署192.168.100.104
[root@nfs ~]#yum -y install rpcbind nfs-utils
[root@nfs ~]# for I in rpcbind nfs; do systemctl enable $I; done #加入开机自启
[root@nfs ~]#vim /etc/exports
/opt/webapp 192.168.100.0/24(rw,sync,no_root_squash) #配置文件自己编写
[root@nfs ~]# mkdir /opt/webapp
[root@nfs ~]#chmod 777 /opt/webapp
[root@nfs ~]# cp -rf WebRoot/ /opt/webapp/
[root@nfs ~]#for I in rpcbind nfs; do systemctl start $I; done
[root@nfs ~]# netstat -tunlp | grep rpc
tcp 0 0 0.0.0.0:42315 0.0.0.0:* LISTEN 2998/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3296/rpcbind
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 3314/rpc.mountd
tcp6 0 0 :::111 :::* LISTEN 3296/rpcbind
tcp6 0 0 :::20048 :::* LISTEN 3314/rpc.mountd
tcp6 0 0 :::35578 :::* LISTEN 2998/rpc.statd
udp 0 0 0.0.0.0:49042 0.0.0.0:* 2998/rpc.statd
udp 0 0 127.0.0.1:659 0.0.0.0:* 2998/rpc.statd
udp 0 0 0.0.0.0:927 0.0.0.0:* 3296/rpcbind
udp 0 0 0.0.0.0:20048 0.0.0.0:* 3314/rpc.mountd
udp 0 0 0.0.0.0:111 0.0.0.0:* 3296/rpcbind
udp6 0 0 :::927 :::* 3296/rpcbind
udp6 0 0 :::49330 :::* 2998/rpc.statd
udp6 0 0 :::20048 :::* 3314/rpc.mountd
udp6 0 0 :::111 :::* 3296/rpcbind
[root@nfs ~]# showmount -e 192.168.100.104
Export list for 192.168.100.104:
/opt/webapp 192.168.100.0/24
[root@nfs ~]# vim /opt/webapp/WebRoot/WEB-INF/classes/database.properties
driver=com.mysql.jdbc.Driver
#在和mysql传递数据的过程中,使用unicode编码格式,并且字符集设置为utf-8
url=jdbc:mysql://192.168.100.105:3306/smbms?useUnicode=true&characterEncoding=utf-8
user=linux
password=123123
Tomcat1服务器的部署192.168.100.102
[root@tomcat1 ~]#tar zxvf jdk-8u171-linux-x64.tar.gz
[root@tomcat1 ~]#mv jdk1.8.0_171/ /usr/local/java
[root@tomcat1 ~]#cat <
export JAVA_HOME=/usr/local/java
export PATH=$PATH:/usr/local/java/bin
END
[root@tomcat1 ~]#source /etc/profile
[root@tomcat1 ~]# java -version
[root@tomcat1 ~]#tar zxvf apache-tomcat-9.0.10.tar.gz
[root@tomcat1 ~]#mv apache-tomcat-9.0.10 /usr/local/tomcat
[root@tomcat1 ~]#/usr/local/tomcat/bin/startup.sh
[root@tomcat1 ~]#mkdir /web
[root@tomcat1 ~]#vim /usr/local/tomcat/conf/server.xml
unpackWARs="true" autoDeploy="true">
[root@tomcat1 ~]#/usr/local/tomcat/bin/shutdown.sh
[root@tomcat1 ~]#/usr/local/tomcat/bin/startup.sh
[root@tomcat1 ~]# netstat -tunlp | grep java
tcp6 0 0 :::8080 :::* LISTEN 2056/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2056/java
tcp6 0 0 :::8009 :::* LISTEN 2056/java
[root@tomcat1 ~]#yum -y install rpcbind nfs-utils
[root@tomcat1 ~]#systemctl enable rpcbind
[root@tomcat1 ~]# systemctl enable nfs
[root@tomcat1 ~]# systemctl start rpcbind
[root@tomcat1 ~]# systemctl start nfs
[root@tomcat1 ~]#echo 3 >/proc/sys/vm/drop_caches
[root@tomcat1 ~]# showmount -e 192.168.100.104
Export list for 192.168.100.104:
/opt/webapp 192.168.100.0/24
[root@tomcat1 ~]# cat /etc/fstab | tail -1
192.168.100.104:/opt/webapp /usr/local/tomcat/wbeapps nfs defaults,_netdev 0 0 #进行挂载
[root@tomcat1 ~]# mount -a
[root@tomcat1 ~]# df -hT | tail -1
192.168.100.104:/opt/webapp nfs4 17G 5.7G 12G 34% /usr/local/tomcat/weapps
Tomcat2服务器的部署192.168.100.103
[root@tomcat2 ~]#tar zxvf jdk-8u171-linux-x64.tar.gz
[root@tomcat2 ~]#mv jdk1.8.0_171/ /usr/local/java
[root@tomcat2 ~]#cat <
export JAVA_HOME=/usr/local/java
export PATH=$PATH:/usr/local/java/bin
END
[root@tomcat2 ~]#source /etc/profile
[root@tomcat2 ~]# java -version
[root@tomcat2 ~]#tar zxvf apache-tomcat-9.0.10.tar.gz
[root@tomcat2 ~]#mv apache-tomcat-9.0.10 /usr/local/tomcat
[root@tomcat2 ~]#/usr/local/tomcat/bin/startup.sh
[root@tomcat2 ~]#mkdir /web
[root@tomcat2 ~]#vim /usr/local/tomcat/conf/server.xml
unpackWARs="true" autoDeploy="true">
[root@tomcat2 ~]#/usr/local/tomcat/bin/shutdown.sh
[root@tomcat2 ~]#/usr/local/tomcat/bin/startup.sh
[root@tomcat2 ~]# netstat -tunlp | grep java
tcp6 0 0 :::8080 :::* LISTEN 2056/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2056/java
tcp6 0 0 :::8009 :::* LISTEN 2056/java
[root@tomcat2 ~]#yum -y install rpcbind nfs-utils
[root@tomcat2 ~]#systemctl enable rpcbind
[root@tomcat2 ~]# systemctl enable nfs
[root@tomcat2 ~]# systemctl start rpcbind
[root@tomcat2 ~]# systemctl start nfs
[root@tomcat2 ~]#echo 3 >/proc/sys/vm/drop_caches
[root@tomcat2 ~]# showmount -e 192.168.100.104
Export list for 192.168.100.104:
/opt/webapp 192.168.100.0/24
[root@tomcat2 ~]# cat /etc/fstab | tail -1
192.168.100.104:/opt/webapp /usr/local/tomcat/webapps nfs defaults,_netdev 0 0 #进行挂载
[root@tomcat2 ~]# mount -a
[root@tomcat2 ~]# df -hT | tail -1
192.168.100.104:/opt/webapp nfs4 17G 5.7G 12G 34% /usr/local/tomcat/weapps
MySQL服务器的部署
[root@mysql ~]# yum -y install mariadb-server mysql
[root@mysql ~]# systemctl start mariadb
[root@mysql ~]# mysqladmin -uroot password 123123
[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 |
+--------------------+
MariaDB [(none)]> grant all on smbms.* to 'linux'@'192.168.100.102' identified by '123123';
MariaDB [(none)]> grant all on smbms.* to 'linux'@'192.168.100.103' identified by '123123';
访问测试