实验架构图
客户机:192.168.111.128
NGINX1:192.168.111.20
NGINX1:192.168.111.21
tomcat1:192.168.111.22
tomcat2:192.168.111.23
tomcat3:192.168.111.24
NFS :192.168.111.19
NFS:192.168.111.19
[root@19 ~]# systemctl stop firewalld [root@19 ~]# setenforce 0 [root@19 ~]# yum install -y rpcbind nfs-utils [root@19 ~]# mkdir /web1 [root@19 ~]# mkdir /web2 [root@19 ~]# mkdir /web3 [root@19 ~]# echo "this is 1" > /web1/index.html [root@19 ~]# echo "this is 2" > /web2/index.html [root@19 ~]# echo "this is 3" > /web3/index.html [root@19 ~]# vim /etc/exports [root@19 ~]# vim /etc/exports [root@19 ~]# systemctl restart rpcbind [root@19 ~]# systemctl restart nfs [root@19 ~]# exportfs -rv exporting 192.168.111.24/24:/web3 exporting 192.168.111.23/24:/web2 exporting 192.168.111.22/24:/web1 [root@19 ~]# showmount -e
TOMCAT:
tomcat1:192.168.111.24
tomcat2:192.168.111.23
tomcat3:192.168.111.22
[root@24 ~]# cd /opt/ [root@24 opt]# ls apache-tomcat-9.0.16.tar.gz jdk-8u201-linux-x64.rpm nginx-1.22.1.tar.gz rh [root@24 opt]# useradd -M -s /sbin/nologin nginx [root@24 opt]# tar nginx-1.22.1.tar.gz [root@24 ~]# systemctl stop firewalld [root@24 ~]# setenforce 0 [root@24 ~]# yum -y install gcc gcc-c++ make pcre-devel zlib-devel [root@24 opt]# cd nginx-1.22.1/ [root@24 nginx-1.22.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=ngin x [root@24 nginx-1.22.1]# cd ~ [root@24 ~]# mount 192.168.111.19:/web1 /usr/local/nginx/html/ [root@24 ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 50G 3.6G 47G 8% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 9.1M 3.9G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 5.0G 179M 4.9G 4% /boot tmpfs tmpfs 781M 48K 781M 1% /run/user/0 /dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt 192.168.111.19:/web1 nfs4 50G 14G 37G 27% /usr/local/nginx/html [root@24 ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin [root@24 ~]# nginx [root@24 ~]# netstat -anpt | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 56110/nginx: master [root@24 ~]# curl http://localhost this is 1 [root@24 ~]# showmount -e clnt_create: RPC: Port mapper failure - Unable to send: errno 22 (Invalid argument) [root@24 ~]# showmount -e 192.168.111.19 Export list for 192.168.111.19: /web3 192.168.111.24/24 /web2 192.168.111.23/24 /web1 192.168.111.22/24 [root@24 ~]# systemctl stop firewalld [root@24 ~]# systemctl disable firewalld [root@24 ~]# setenforce 0
22,23,24,步骤相同
NGINX
Vim Keepalive.conf中配置文件 #!/bin/bash A=`ps -C nginx --no-header | wc -l` 查询进程数 if [ $A -eq 0 ] then /usr/local/nginx/sbin/nginx if [ `ps -C nginx --no-header | wc -l` -eq 0 ] then exit 1 else exit 0 fi else exit 0 fi Vim /usr/local/src/nginx.sh中配置文件 ! Configuration File for keepalived global_defs { router_id master #本服务器的名称 } vrrp_script chk_http_port { #vrrp脚本 script "/usr/local/src/nginx.sh" #脚本路径 最后手动执行此脚本,以确保脚本能 够正常运行 interval 2 #检测间隔时间 单位秒 weight 2 } vrrp_instance vi_1 { #实例名称 state MASTER #指定keepalived的角色,MASTER为主,BACKUP为备 interface ens33 #当前进行vrrp通讯的网络接口卡 virtual_router_id 51 #虚拟路由编号,主从要一致 priority 110 #优先级,数值越大,获取地址优先级越大 adver_int 1 #检查间隔,默认为1s (vrrp组播周期秒数) authentication { #认证方式 auth_type PASS auth_pass 1111 } track_script { chk_http_port #调用检测脚本 } virtual_ipaddress { 192.168.111.66 #定义虚拟ip(VIP) } }
NGINX2 配置
NGINX2 配置与1相同,第一个配置文件中 Vim /usr/local/src/nginx.sh,把MASTER改为backup优先级改为100
[root@localhost ~]# cd /usr/local/src/nginx.sh -bash: cd: /usr/local/src/nginx.sh: 不是目录 [root@localhost ~]# cd /usr/local/src [root@localhost src]# ls nginx.sh [root@localhost src]# yum install keepalived.x86_64 -y [root@localhost keepalived]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:a7:ad:ee brd ff:ff:ff:ff:ff:ff inet 192.168.111.21/24 brd 192.168.111.255 scope global ens33 valid_lft forever preferred_lft forever inet 192.168.111.66/32 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::b35f:ce2c:af94:1af0/64 scope link valid_lft forever preferred_lft forever 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000 link/ether 52:54:00:b4:0d:30 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000 link/ether 52:54:00:b4:0d:30 brd ff:ff:ff:ff:ff:ff [root@localhost keepalived]# ^C [root@localhost keepalived]#
虚拟IP
标签:24,tomcat,19,Keepalived,192.168,nginx,nfs,ff,root From: https://www.cnblogs.com/123456789SI/p/16925563.html