1、创建两台虚拟机,分别为主机和从机,区别两台虚拟机的IP地址 2、 将keepalived上传到linux系统当中
5、 cd keepalived-1.2.18目录
6、 yum install -y openssl openssl-devel (需要安装一个软件包)
7、 ./configure --prefix=/usr/local/keepalived 编译,将编译文件放到/usr/local/keepalived
8、 make
9、 make install
10、 在/etc/keepalived 创建目录: mkdir /etc/keepalived 11、 cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
12、 cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
13、 cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
14、 ln -s /usr/local/sbin/keepalived /usr/sbin/
(ln -s /usr/local/keepalived/sbin/keepalived /sbin/) 15、 将nginx启动脚本和keepalived.conf配置上传到/etc/keepalived
interface 配置成与主机相同的网络 ip a
mcast_src_ip 配置成自己机器的IP
virtual_ipaddress {
192.168.33.135 # 虚拟ip,也就是解决写死程序的ip怎么能切换的ip,也可扩展,用途广泛。可配置多个。
}
如果报错:Job for keepalived.service failed because the control process exited with error code. See "systemctl status keepalived.service" and "journalctl -xe" for details.
18、解决办法:rm /usr/sbin/keepalived
19、ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/
20、再次启动
查看脚本是否有运行的权限,如果你是 root 登陆的话(不是的话,切换到 root 用户,对*.sh 赋可执行的权限)
赋予权限命令:chmod 777 *.sh
赋予所有权限:chmod +x *.sh
然后运行就 OK 了,即有权限对文件进行删除等操作。
23、备机安装步骤同上,备机修改配置文件步骤如下 24、备机:修改keepalived.conf配置文件 vim /etc/keepalived/keepalived.conf state BACKUP 备机名称
interface 配置成与主机相同的网络 ip a
mcast_src_ip 配置成自己机器的IP
priority 90 权重配置
virtual_ipaddress {
192.168.33.135 # 虚拟ip,也就是解决写死程序的ip怎么能切换的ip,也可扩展,用途广泛。可配置多个。
}