目录
目录
2.2、 NFS-资源共享【192.168.200.125】
单节点部署zrlog【192.168.200.121】
[root@nginx ~]# vim /soft/tomcat/conf/server.xml
......
## 添加虚拟主机
<Host name="www.test-zrlog.org" appBase="/code/zrlog"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="zrlog_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
.....
- 创建目录、下载项目包、重启tomcat自动解压war包
- war包,重启tomcat会自动解压
[root@nginx ~]# mkdir /code/zrlog
[root@nginx ~]# cd /code/zrlog/
[root@nginx zrlog]# systemctl stop tomcat.service
[root@nginx zrlog]# systemctl start tomcat.service
[root@nginx zrlog]# ls
zrlog-2.2.1-efbe9f9-release zrlog-2.2.1-efbe9f9-release.war
[root@nginx zrlog]# mv zrlog-2.2.1-efbe9f9-release ROOT
[root@nginx zrlog]# ls
ROOT zrlog-2.2.1-efbe9f9-release.war
创建数据库、远程登录用户
MariaDB [(none)]> grant all on *.* to zrlog@'%' identified by '111';
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> create database zrlog;
Query OK, 1 row affected (0.00 sec)
浏览器访问
LB集群-构建-部署zrlog-NFS共享存储
将192.168.200.121的zrlog项目拷贝到192.168.200.122
[root@nginx ~]# yum -y install java
[root@nginx ~]# scp -rp 192.168.200.121:/soft /
[root@nginx ~]# scp -rp 192.168.200.121:/etc/systemd/system/tomcat.service /etc/systemd/system/tomcat.service
[root@nginx ~]# systemctl daemon-reload
[root@nginx ~]# systemctl status tomcat.service
● tomcat.service - Apache Tomcat Server
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@nginx ~]# systemctl enable tomcat.service
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /etc/systemd/system/tomcat.service.
[root@nginx ~]# scp -rp 192.168.200.121:/code /
[root@nginx ~]# ls /code/
tomcat zrlog
[root@nginx ~]# systemctl start tomcat.service
安装、配置LB【192.168.200.120】
cat > /etc/yum.repos.d/nginx.repo << OK
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
OK
[root@nginx ~]# yum -y install nginx
[root@nginx ~]# mv /etc/nginx/conf.d/default.conf{,.bak}
[root@nginx ~]# groupadd -g666 www
[root@nginx ~]# useradd -u666 -g666 www
[root@nginx ~]# id www
uid=666(www) gid=666(www) groups=666(www)
[root@nginx ~]# sed -i '/^user/c user www;' /etc/nginx/nginx.conf
[root@nginx ~]# systemctl start nginx
[root@nginx ~]# systemctl enable nginx
[root@nginx ~]# vim /etc/nginx/conf.d/zrlog.conf
upstream zrlog {
server 192.168.200.121:8080;
server 192.168.200.122:8080;
}
server {
listen 443 ssl;
server_name www.test-zrlog.org;
charset utf-8;
default_type text/html;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_certificate ssl_key/server.crt;
ssl_certificate_key ssl_key/server.key;
location / {
proxy_pass http://zrlog;
include proxy_params;
}
}
server {
listen 80;
server_name www.test-zrlog.org;
return 302 https://$http_host$request_uri;
}
[root@nginx nginx]# vim /etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_connect_timeout 60s; # nginx连接后端的超时时间
proxy_read_timeout 60s; # 响应头部超时时间
proxy_send_timeout 60s; # 响应数据主体的超时时间
proxy_buffering on; # 开启缓冲区
proxy_buffer_size 8k; # 缓冲区Header大小
proxy_buffers 4 64k; # 缓冲区数量 * 大小 = 最大接收
[root@nginx nginx]# systemctl reload nginx.service
NFS-资源共享【192.168.200.125】
[root@nfs ~]# yum -y install nfs-utils.x86_64
## 配置NFS共享目录
[root@nfs ~]# cat /etc/exports
/data/zrlog 192.168.200.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
## 创建目录、修改权限
[root@nfs ~]# mkdir /data/zrlog
[root@nfs ~]# chown -R www.www /data/zrlog/
[root@nfs ~]# systemctl restart nfs
## web节点将nfs共享目录挂在到图片存放目录
mount -t nfs 192.168.200.125:/data/zrlog /zrlog/ROOT/attached/
配置tomcat访问日志中记录真实IP
- 记录真实IP(X-Forwarded-For)
- 添加用户使用设备信息(User-Agent)
<Host name="www.test-zrlog.org" appBase="/code/zrlog"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="zrlog_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b %{User-Agent}i %{X-Forwarded-For}i" />