nacos的集群,需要后端的nginx代理,nginx需要做高可用,安装keepalived做vip,mysql需要做主从配置
nginx与keepalied的安装,
yum -y install nginx keepalived
keepalied的配置
在主的配置
[root@lb01 keepalived]# ls
keepalived.conf keepalived.conf.bak keepalived.conf.bak01 nginx_check.sh
yunwei01-[root@yunwei01 keepalived]# cat keepalived.conf
global_defs {
router_id nginx_001
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 101
unicast_src_ip 192.168.174.174
unicast_peer {
192.168.174.90
}
priority 250
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.174.254
}
track_script {
chk_nginx
}
}
[root@lb01 keepalived]# cat nginx_check.sh
#!/bin/bash
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then
systemctl start nginx #尝试重新启动nginx
sleep 2 #睡眠2秒
if [ `ps -C nginx --no-header | wc -l` -eq 0 ];then
#killall keepalived #启动失败,将keepalived服务杀死。将vip漂移到其它备份节点
systemctl stop keepalived #启动失败,将keepalived服务杀死。将vip漂移到其它备份节点
fi
fi
在备节点
[root@lb02 keepalived]# cat keepalived.conf
global_defs {
router_id nginx_001
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 101
unicast_src_ip 192.168.174.90
unicast_peer {
192.168.174.174
}
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.174.254
}
track_script {
chk_nginx
}
}
[root@lb02 keepalived]# cat nginx_check.sh
#!/bin/bash
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then
systemctl start nginx #尝试重新启动nginx
sleep 2 #睡眠2秒
if [ `ps -C nginx --no-header | wc -l` -eq 0 ];then
#killall keepalived #启动失败,将keepalived服务杀死。将vip漂移到其它备份节点
systemctl stop keepalived #启动失败,将keepalived服务杀死。将vip漂移到其它备份节点
fi
fi
启动服务
systemctl restart keepalived
systemctl enable keepalived
主和备的nginx都配置
[root@lb02 conf.d]# cat tps-nacos.conf
upstream nacos{
server 192.168.174.87:8848;
server 192.168.174.88:8848;
server 192.168.174.99:8848;
}
server {
listen 8080;
server_name localhost;
index index.html;
location /{
proxy_pass http://nacos;
}
}
启动nginx
systemctl restart nginx
systemctl enable nginx
naocs的安装请见博客的https://www.cnblogs.com/hao-guo/p/12673841.html
mysql的安装和主从的配置https://www.cnblogs.com/hao-guo/p/12557408.html,https://www.cnblogs.com/hao-guo/p/12780169.html
不过naocs都要的cluster.conf需要配置
192.168.174.87:8848
192.168.174.88:8848
192.168.174.99:8848
导入sql文件后,直接访问http://192.168.174.254:8080/nacos/,