方案概览
如需详细信息可点击下列链接进行视频观看
- B站
- 7分钟弄懂啥是高可用基石-VIP
- 从零开始实操VIP
- 抖音
- 7分钟弄懂啥是高可用基石-VIP
- 从零开始实操VIP
Centos7 yum更新
- 安装阿里yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
-
yum makecache检查安装是否正确,并进行yum源更新
-
安装vim, yum install -y vim
Nginx yum安装
- 新建/etc/yum.repos.d/nginx.repo,填入如下配置
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
-
安装Nginx, yum install nginx
-
启动Nginx, systemctl start nginx
systemctl enable nginx
-
为测试用,关闭防火墙, systemctl stop firewalld
systemctl disable firewalld -
修改Nginx欢迎页面,分别是哪一个机器上的Nginx
vim /usr/share/nginx/html/index.html
加入
VM1/VM2/VM3
Keepalived安装
- 下载安装keepalived
curl -o keepalived-2.3.1.tar.gz https://www.keepalived.org/software/keepalived-2.3.1.tar.gz
tar zxvf keepalived-2.3.1.tar.gz
cd keepalived-2.3.1
yum install make gcc libnl3-devel openssl-devel libnfnetlink-devel net-snmp-devel
./configure --prefix=/usr/local/keepalived
make && make install
/usr/local/keepalived/sbin/keepalived -v
cp keepalived/etc/init.d/keepalived /etc/init.d
cp keepalived/etc/sysconfig/keepalived /etc/sysconfig/
systemctl enable keepalived
mkdir /etc/keepalived
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_101.250 {
state MASTER #备机写BACKIP
interface ens33 #网卡名字
virtual_router_id 110 #备机和主机的虚拟路由ID要一样
priority 200 #优先级备机应该比主低
advert_int 1 #发送arp包间隔
authentication {
auth_type PASS #授权账号密码主备相同
auth_pass 123456
}
virtual_ipaddress {
192.168.169.100 #指定VIP,可以指定多个,一个一行,可以指定当前能访问的通的任意子网IP
}
}
-
启动 keepalived, systemctl start keepalived
-
重启后,启动
systemctl start nginx
systemctl start keepalived