没有合适的资源?快使用搜索试试~ 我知道了~
nginx架构综合部署
资源推荐
资源详情
资源评论
实验目标:高可用,负载均衡,网站加密,lnmp
实验拓扑:
实验步骤:
一、搭建负载均衡
1、 使用 xftp 上传 nginx-rpm 安装包到 lb1,lb2,web1,web2 主机上
2、 使用 xftp 上传 mysql-rpm 包到 8.11 主机上,mysql-rpm 包到 8.10 主机上
3、 在四台 nginx 主机上安装 nginx 软件
[root@lb1 ~]# cd nginx-rpm/
[root@lb1 nginx-rpm]# rpm -ivh *.rpm --nodeps –force
[root@lb2 ~]# cd nginx-rpm/
[root@lb2 nginx-rpm]# rpm -ivh *.rpm --nodeps –force
[root@web1 ~]# cd nginx-rpm/
[root@web1nginx-rpm]# rpm -ivh *.rpm --nodeps –force
[root@web2 ~]# cd nginx-rpm/
[root@web2 nginx-rpm]# rpm -ivh *.rpm --nodeps –force
4、 配置 lb1 主机:
[root@lb1 ~]# cd /etc/nginx/conf.d/
[root@lb1 conf.d]# rm -rf * #删除 default 默认配置文件
[root@lb1 conf.d]# vim lb.conf #编写负载均衡配置文件
upstream webcluster {
server 192.168.8.8:80;
server 192.168.8.9:80;
}
server {
listen 80;
server_name blog.benet.com;
location / {
proxy_pass http://webcluster;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
5、 重新启动 nginx
[root@lb1 ~]# systemctl restart nginx
[root@lb1 ~]# systemctl enable nginx #开机自启
6、 上传 lb.conf 配置文件到 lb2 主机上
[root@lb1 ~]# scp -rp /etc/nginx/conf.d/lb.conf root@192.168.8.7:/etc/nginx/conf.d
7、 配置 lb2 主机
[root@lb1 ~]# rm -rf /etc/nginx/conf.d/default.conf #删除 default 默认文件
第一台 lb1 配置和第二台 lb2 文件一样,已经上传到 lb2 无需编写,重启服务
[root@lb2 ~]# systemctl restart nginx
[root@lb2 ~]# systemctl enable nginx #开机自启
二、搭建高可用
1、[root@lb1 ~]# yum -y install keepalived
配置 lb1 主机:
[root@lb1 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
router_id lb1 #master 名称为 lb1,两台不能重名
}
vrrp_script check_nginx_proxy {
script “/sh/check_nginx_proxy.sh” #nginx 网站异常自动关闭漂移地址
interval 2
weight 5
}
vrrp_instance VI_1 {
state MASTER #主服务器为大写 master
interface ens33 #网卡名称
virtual_router_id 51
priority 100 #优先级,backup 优先级不能高于 master
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.8.254 #漂移地址
}
track_script {
check_nginx_proxy
}
}
剩余10页未读,继续阅读
资源评论
Linux…
- 粉丝: 211
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功