目录
一、环境
二、配置tomcat
三、配置nfs共享
四、配置nginx
1、两台都需要折磨配置
2、在http下面插入这两条信息
五、配置keepalived
1、安装
2、重新启动一下keepalived查看IP
六、验证双机热备
1、查看调度器备的IP,ip漂移说明keepalived生效
2、访问静态页面
3、 访问动态页面
一、环境
三台主机分别为
192.168.28.3 tomcat
192.168.28.4 nfs
192.168.28.5 tomcat
192.168.28.6 nginx,keepalived
192.168.28.7 nginx,keepalived
二、配置tomcat
两台tomcat配置把解压包拖进主机解压移动
tar xf apache-tomcat-8.5.16.tar.gz
tar xf apache-tomcat-8.5.16.tar.gz
mv apache-tomcat-8.5.16 /usr/local/tomcat
mv apache-tomcat-8.5.16 /usr/local/tomcat
ln -s /usr/local/tomcat/bin/startup.sh /usr/bin/qd1
ln -s /usr/local/tomcat/bin/shutdown.sh /usr/bin/tz1
###创建挂载目录
/usr/local/tomcat
mkdir webapps1
###修改tomcat的访问目录
vim /usr/local/tomcat/conf/server.xml
###修改host字段插入
<Context path="" docBase="/usr/local/tomcat/webapps1" />
三、配置nfs共享
mkdir /opt/web1
mkdir /opt/web2
vim /etc/exports
systemctl restart nfs
exportfs
##安装nfs服务
yum -y install nfs
##创建共享目录
mkdir /opt/web1
mkdir /opt/web2
##配置nfs的配置文件vim /etc/exports
systemctl restart nfs
回到两台Tomcat的上查看共享目录
[root@localhost tomcat]# mkdir webapps1
showmount -e 192.168.28.4
mount 192.168.28.4:opt/web2 /usr/local/tomcat/webapps1
echo tomcat2 > webapps1/index.jsp
qd1
##查看挂载情况
df
###分别书写测试页面
echo tomcat1 > webapps1/index.jsp
echo tomcat2 > webapps1/index.jsp
##启动Tomcat
qd1
qd0
##查看端口
netstat -anptu |grep java
测试页面
四、配置nginx
1、两台都需要折磨配置
192.168.28.6
192.168.28.7
#安装
yum -y install epel-release.noarch
yum -y install nginx
vim /etc/nginx/nginx.conf
2、在http下面插入这两条信息
在server字段插入下方这句话
启动nginx
访问一下测试页面
查看调度器
五、配置keepalived
1、安装
192.168.28.6
192.168.28.7
yum -y install keepalived
vim /etc/keepalived/keepalived.conf
systemctl restart keepalived.service
scp /etc/keepalived/keepalived.conf 192.168.28.7:/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL ###从的编号要改动一下 LVS_DEVEL1
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER ###从改为BACKUP
interface ens33 ###网卡名
virtual_router_id 51
priority 100 ###从的优先级要比主低
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.28.200 ###VIP用来访问的虚拟IP
}
}
virtual_server 192.168.28.200 8080 { ###vip对应的真是IP 在下面
delay_loop 6
lb_algo rr
persistence_timeout 50
protocol TCP
real_server 192.168.28.3 8080 { ###这是Tomcat服务器的IP
weight 1
HTTP_GET {
url {
path /testurl/test.jsp
}
url {
path /testurl2/test.jsp
}
url {
path /testurl3/test.jsp
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.28.5 8080 { ###这是Tomcat服务器的IP
weight 1
HTTP_GET {
url {
path /testurl/test.jsp
}
url {
path /testurl2/test.jsp
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
2、重新启动一下keepalived查看IP
systemctl restart keepalived.service
ip a
VIP页面访问测试
静态页面
动态页面
六、验证双机热备
模拟调度器主宕机systemctl stop keepalived,使用调度器备访问
1、查看调度器备的IP,ip漂移说明keepalived生效
2、访问静态页面
3、 访问动态页面
文章来源:https://www.toymoban.com/news/detail-685220.html
文章来源地址https://www.toymoban.com/news/detail-685220.html
到了这里,关于LNMT的多机部署和双机热备的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!