#web服务已经设定完成#在rs中设定lo添加vip2 172.25.254.200、32#在rs中搭建数据库[root@rs1+2 ~]# dnf install mariadb-server -y[root@rs1+2 ~]# systemctl enable --now mariadb[root@rs1+2 ~]# mysqlWelcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis3Server version:10.5.27-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>CREATEUSERlee@'%'identified by'lee';Query OK,0rows affected(0.001sec)MariaDB[(none)]>GRANT ALL ON *.* TO lee@'%';Query OK,0rows affected(0.001sec)#测试[root@rs1 ~]# mysql -ulee -plee -h172.25.254.10Welcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis4Server version:10.5.27-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>quit[root@rs1 ~]# mysql -ulee -plee -h172.25.254.20Welcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis4Server version:10.5.27-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>quit
2.实现不同vip代理不同业务
#KA1和KA2虚拟服务器配置[root@KA1+2 ~]# vim /etc/keepalived/keepalived.confinclude /etc/keepalived/conf.d/webserver.conf include /etc/keepalived/conf.d/datebase.conf[root@KA1+2 ~]# vim /etc/keepalived/conf.d/webserver.conf#172.25.254.100:80 Web 服务virtual_server172.25.254.10080{delay_loop6# 后端节点健康检查间隔,单位秒,每6秒检查一次RSlb_algo rr# 调度算法:轮询 rr,请求依次分给10、20两台机器lb_kind DR# LVS工作模式:DR直接路由模式protocol TCP# 检测TCP协议real_server172.25.254.1080{weight1# 权重,两台一样,流量均分HTTP_GET{# 对172.25.254.10 使用HTTP方式健康检查url{path /# 访问根目录 /status_code200# 返回码200代表节点正常}connect_timeout1# 连接超时1sretry3# 失败最多重试3次delay_before_retry1# 重试间隔1s}}real_server172.25.254.2080{weight1TCP_CHECK{# 对172.25.254.20 使用TCP端口探测,只探测80端口通不通,不做http访问connect_timeout5retry3delay_before_retry3connect_port80}}}[root@KA1 ~]# vim /etc/keepalived/conf.d/datebase.conf#172.25.254.200:3306 MySQL 数据库服务virtual_server172.25.254.2003306{delay_loop6lb_algo rr lb_kind DR protocol TCP real_server172.25.254.103306{weight1TCP_CHECK{# MySQL只能TCP探测,不能HTTP_GETconnect_timeout5retry3delay_before_retry3connect_port3306}}real_server172.25.254.203306{weight1TCP_CHECK{# MySQL只能TCP探测,不能HTTP_GETconnect_timeout5retry3delay_before_retry3connect_port3306}}}[root@KA1+2 ~]# systemctl restart keepalived.service
3.测试
[root@rs2 ~]# mysql -ulee -plee -h172.25.254.200Welcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis89Server version:10.5.27-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>[Administrator.DESKTOP-VJ307M3]➤curl172.25.254.100 RS1 -172.25.254.10[2026-01-2911:58.55]~[Administrator.DESKTOP-VJ307M3]➤curl172.25.254.100 RS2 -172.25.254.20