Tomcat【部署zrlog】

目录

目录

1、单节点部署zrlog【192.168.200.121】

1.1、 创建数据库、远程登录用户

1.2、 浏览器访问

2、 LB集群-构建-部署zrlog-NFS共享存储

2.1、 安装、配置LB【192.168.200.120】

2.2、 NFS-资源共享【192.168.200.125】

3、配置tomcat访问日志中记录真实IP


1、单节点部署zrlog【192.168.200.121】

创建数据库、远程登录用户

浏览器访问

2、 LB集群-构建-部署zrlog-NFS共享存储

安装、配置LB【192.168.200.120

NFS-资源共享【192.168.200.125】

3、配置tomcat访问日志中记录真实IP


单节点部署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 &quot;%r&quot; %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 &quot;%r&quot; %s %b %{User-Agent}i %{X-Forwarded-For}i" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦有一把琐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值