keepalived+nginx 高可用有主备和双活两种方式. 主备方式下对外提供一个 vip, 同时只有一台服务器工作, 另一台作备机; 双活方式下对外提供两个 vip, 两台机器互为备份, 下面详细说明搭建测试步骤.
主备模式
架构图:
配置:
主机 < br ztid="85" ow="0" oh="0"> | ip | 操作系统 < br ztid="89" ow="0" oh="0"> | 软件 < br ztid="91" ow="0" oh="0"> | 备注 < br ztid="93" ow="0" oh="0"> |
nginx01 | 172.27.9.91 | Centos7 | nginx 端口 82 keepalived | 关闭防火墙和 selinu |
nginx02 | 172.27.9.92 | Centos7 | nginx 端口 82 keepalived | 关闭防火墙和 selinu |
web01 | 172.27.9.125 | Centos7 | apache 端口 1180 | 关闭防火墙和 selinu |
web02 | 172.27.9.126 | Centos7 | apache 端口 1180 | 关闭防火墙和 selinu |
1.nginx 安装
nginx01 和 nginx02 安装 nginx 参见 Centos7 安装 nginx
2.nginx 配置
两台 nginx 服务器配置相同, 如下:
- [root@nginx01 ~]# more /usr/local/nginx/conf/nginx.conf
- #user nobody;
- worker_processes 1;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- #log_format main '$remote_addr - $remote_user [$time_local]"$request" '
- # '$status $body_bytes_sent"$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #gzip on;
- upstream webser{
来源: http://blog.51cto.com/3241766/2103154