keepalived简单配置

在两台机器上下载nginx,keepalived

yum install -y nginx keepalived

编辑文件 cp keepalived.conf.sample keepalived.conf

vim /etc/keepalived/keepalived.conf

​​​​​​​​​​​​​​

在每台服务器上开启服务:systemctl start keepalived.service

systemctl start nginx

写一个监测nginx是否运行的脚本

root@LB-1-master keepalived# vim /etc/keepalived/check_nginx.sh

给执行权限 chmod +x check_nginx.sh

再写一个拉起脚本vim /etc/keepalived/rescure.sh

给执行权限 chmod +x rescure.sh

在后台运行:nohup /etc/keepalived/rescure.sh &

脚本有问题会在创建目录下nohup.out文件中体现

三台机器都要配置

编辑负载均衡 vim /etc/nginx/nginx.conf

下载docker容器实现在三台服务器上运行其他网段web

第一步:配置阿里源

cat <<EOF >> /etc/yum.repos.d/docker-ce.repo

docker-ce-stable

name=Docker CE Stable - $basearch

baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/9/x86_64/stable/

enabled=1

gpgcheck=1

gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

EOF

yum安装docker

yum install -y docker-ce

(ce安装是实验室环境下,ee是传统生产环境下)

启动docker,要给 docker 配置国内镜像加速

cat <<EOF >>/etc/docker/daemon.json

{

"registry-mirrors": [

"https://0vmzj3q6.mirror.aliyuncs.com",

"https://docker.m.daocloud.io",

"https://mirror.baidubce.com",

"https://dockerproxy.com",

"https://mirror.iscas.ac.cn",

"https://huecker.io",

"https://dockerhub.timeweb.cloud",

"https://noohub.ru",

"https://vlgh0kqj.mirror.aliyuncs.com"

]

}

EOF

更新配置后要重新读取:systemctl daemon-reload

设置开机自启:systemctl enable --now docker

拉取nginx:docker pull nginx

指定网桥

在三台服务器上都执行

docker network create \ --subnet=172.20.2.0/24 \ --gateway=172.20.2.1 \ mybridge

启动容器时,直接指定固定 IP

docker run -d \ --name nginx-web \ --restart always \ --net mybridge \ --ip 172.20.2.11 \ -p 8080:80 \ nginx:stable

docker run -d \ --name nginx-web \ --net mybridge \ --ip 172.20.2.12 \ -p 8080:80 \ nginx:stable

docker run -d \ --name nginx-web \ --net mybridge \ --ip 172.20.2.13 \ --restart always \ -p 8080:80 \ nginx:stable

做完以上docker操作,更改负载均衡配置文件

upstream backend { server 172.20.2.11:8080; server 172.20.2.12:8080; server 172.20.2.13:8080; }

相关推荐
Hello_Pyhx4 分钟前
Ventoy:Linux制盘与排障
linux·运维·服务器
pt10439 分钟前
从阿波罗13号到命令行的网络实验转向
运维·网络
Jason_zhao_MR26 分钟前
电力数据采集核心板选型指南
linux·嵌入式硬件·fpga开发·嵌入式
见闻小天地30 分钟前
空调机房赛莱默B&G冷冻泵/冷却泵的核心技术特性分析
大数据·运维·数据库
microxiaoxiao33 分钟前
MobaXterm vs Aeroshell
linux·运维·ssh
东城居士1 小时前
理解设备树下的platform驱动编写
linux·嵌入式系统
小义_1 小时前
Linux 补充
linux·服务器
晴天的雨.9921 小时前
【Linux】Shell 命令以及运行原理+权限管理
linux·运维·服务器
djjjx.1 小时前
Linux工具篇 (六):GDB 调试从底层逻辑到高阶实战
linux·运维·服务器·gdb
IT大白鼠1 小时前
彭大帅的AI运维助手实战案例 5 · 新接手的服务器,先让 AI 摸底
运维·服务器·人工智能