keepalived+jumpserver+mysql双主热备+sersync+邮件通知,实现jumpserver双机热备
前言
资源有限,没法实现应用服务器和存储服务器分离,没法进行高大上的配置,考虑到可能会出现脑裂的情况,也没使用负载均衡,就两台设备,于是就萌生了这个想法,使得一台设备宕机,另一台能实时接管,并且数据同步,故障服务器向管理员发送通知,并告知故障原因,同时宕机设备恢复时又能继续工作。
提示:以下是本篇文章正文内容,下面案例可供参考
一、准备工作
服务器 | IP | 版本号 |
---|---|---|
ServerA | 192.168.1.100 | Ubuntu 20.04.3 |
ServerB | 192.168.1.101 | Ubuntu 20.04.3 |
VIP | 192.168.1.200 | |
使用de工具 | ||
工具 | 版本号 | |
-------- | ----- | |
keepalived | v2.0.19 | |
jumpserver | v2.12.2 | |
mysql | 8.0.26 | |
sersync | ||
PS:为保证网络畅通,本文默认已关闭防火墙、selinux。
二、拓扑图
三、实现
1.修改 IP地址
server1:
打开配置文件:
root@tjsc:~#vim /etc/netplan/00-installer-config.yaml
配置文件:
network:
ethernets:
ens33: #配置的网卡的名称
addresses: [192.168.1.100/24] #配置的静态ip地址和掩码
dhcp4: no #关闭DHCP,如果需要打开DHCP则写yes
optional: true
gateway4: 192.168.1.1 #网关地址
nameservers:
addresses: [192.168.1.1,114.114.114.114] #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
version: 2
renderer: networkd
server2:
server2同server1只是需要将192.168.1.100改为192.168.1.101
修改好后,执行
root@tjsc:~# sudo netplan apply
检查配置是否正确,执行
root@tjsc:~# ip addr
#输出结果
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 fq_codel state UP group default qlen 1000
link/ether 00:0c:29:a8:73:8a brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea8:738a/64 scope link
valid_lft forever preferred_lft forever
ps:注意网卡名称,不要照抄。
2.安装mysql
sever1和server2:
- apt安装mysql(使用的阿里源)
root@tjsc:~#apt install -y mysql-server
- 初始化mysql
root@tjsc:~#sudo mysql_secure_installation
配置项
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)
#2
Please set the password for root here...(输入root用户密码)
New password: (输入密码)
Re-enter new password: (重复输入)
#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)(移除匿名用户)
#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...(设置是否只允许本地登录)
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)
#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)
#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
- 检查mysql服务状态
root@tjsc:~#systemctl status mysql.service
#显示结果
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-17 06:55:32 UTC; 27min ago
Main PID: 3310 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 2245)
Memory: 355.0M
CGroup: /system.slice/mysql.service
└─3310 /usr/sbin/mysqld
Aug 17 06:55:32 tjsc systemd[1]: Starting MySQL Community Server...
Aug 17 06:55:32 tjsc systemd[1]: Started MySQL Community Server.
3.安装jumpserver
sever1和server2:
- 手动部署jumpserver
cd /opt #进入opt目录
wget https://github.com/jumpserver/installer/releases/download/v2.12.2/jumpserver-installer-v2.12.2.tar.gz #下载安装包
tar -xf jumpserver-installer-v2.12.2.tar.gz #解压安装包
cd jumpserver-installer-v2.12.2 #进入安装目录
root@tjsc:/opt/jumpserver-installer-v2.12.2#./jmsctl.sh install #启动jumpserver安装脚本
过一会会有配置项:
2. Configure Docker
Do you need custom docker root dir, will use the default directory /var/lib/docker? (y/n) (default n): (默认即可)
1. Configure Network(是否支持IPV6)
Do you want to support IPv6? (y/n) (default n):
3. Configure Persistent Directory(设置配置文件目录,一般默认)
Do you need custom persistent store, will use the default directory /opt/jumpserver? (y/n) (default n)
4. Configure MySQL
Do you want to use external MySQL? (y/n) (default y): #(使用刚才安装的mysql,所以一定要选y)
Please enter MySQL server IP (default 192.168.1.100): #(本地IP地址,可以为localhost)
Please enter MySQL server port (default 3306): #(端口)
Please enter MySQL database name (default jumpserver): #(jumpserver的数据库,需要事先创建好)
Please enter MySQL username (default root): #(使用的连接数据库的账号)
Please enter MySQL password (default ): #(数据库密码)
#其余选项默认即可
ps:
创建数据库 mysql> create database jumpserver;
创建用户 mysql>create user 'admin' @'%' identified with mysql_native_password by 'xxxxxxx.';
修改用户权限:mysql>GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%';
安装完成后,显示
>>> The Installation is Complete
1. You can use the following command to start, and then visit
cd /opt/jumpserver-installer-v2.12.2
./jmsctl.sh start
2. Other management commands
./jmsctl.sh stop
./jmsctl.sh restart
./jmsctl.sh backup
./jmsctl.sh upgrade
For more commands, you can enter ./jmsctl.sh --help to understand
3