如何搭建keepalived+nginx+httpd+dns高可用双主反向代理服务器
如何搭建keepalived+nginx+httpd+dns高可用双主反向代理服务器
一、背景介绍
由于需要提供高可用的Web服务,所以需要搭建一套keepalived+nginx+httpd+dns高可用双主反向代理服务器。
二、硬件环境
两台物理服务器,配置如下:
CPU:4核
内存:8G
硬盘:500G
操作系统:CentOS 6.5
网络:1Gbps
三、软件环境
1、keepalived:用于高可用性负载均衡和故障转移
2、nginx:Web服务器
3、httpd:Web服务器
4、dns:域名解析服务器
四、架构设计
1、系统架构图
2、 keepalived配置
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.100 } }
3、 nginx配置
upstream keepalived_cluster { server 192.168.0.100:80; server 192.168.0.101:80; } server { listen 80; server_name www.test.com; index index.html index.htm; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://keepalived_cluster; } }
4、httpd配置
ServerAdmin webmaster@dummy-host2.x DocumentRoot /usr/local/apache2/htdocs ServerName www.test.com ErrorLog logs/dummy-host2.x-error_log CustomLog logs/dummy-host2.x-access_log common
5、dns配置
zone "test.com" IN { type master; file "test.com.zone"; allow-update { none; }; };
五、实施步骤
1、在两台服务器上安装keepalived、nginx、httpd、dns软件
2、配置keepalived、nginx、httpd、dns
3、启动keepalived、nginx、httpd、dns
4、设置域名解析
6、验证
1、查看keepalived状态
[root@node1 ~]# service keepalived status keepalived (pid 4598) is running... [root@node2 ~]# service keepalived status keepalived (pid 4602) is running...
2、查看nginx状态
[root@node1 ~]# service nginx status nginx is running [root@node2 ~]# service nginx status nginx is running
3、查看httpd状态
[root@node1 ~]# service httpd status httpd (pid 4485) is running... [root@node2 ~]# service httpd status httpd (pid 4489) is running...
4、查看dns状态
[root@node1 ~]# service named status named (pid 4473) is running... [root@node2 ~]# service named status named (pid 4477) is running...
5、访问Web服务
通过域名www.test.com访问Web服务,可以看到页面正常访问。
相关文章