1
安装apache
后端主机直接yum安装
代码语言:javascript复制yum install httpd -y
反向代理端采用源码编译安装
代码语言:javascript复制yum install apr-devel pcre-devel apr-util-devel openssl-devel -y
编译安装apache服务
代码语言:javascript复制cd /usr/local/src/
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.34.tar.gz
tar zxf httpd-2.2.34.tar.gz
cd httpd-2.2.34
./configure --prefix=/usr/local/http --enable-so --enable-modules="all"
make && make install
2
配置apache
修改后端主机的端口为8080
代码语言:javascript复制sed -i "s#Listen 80#Listen 8080#g" /etc/httpd/conf/httpd.conf
/etc/init.d/httpd start
配置反向代理服务器
首先开启相关模块
代码语言:javascript复制LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
修改配置文件
代码语言:javascript复制cat >>/usr/local/http/conf/httd.conf << EOF
ProxyPass /mgg balancer://mingongge
ProxyPassReverse /mgg balancer://mingongge
<Proxy balancer://mingongge>
BalancerMember http://10.0.0.10:8080
BalancerMember http://10.0.0.100:8080
</Proxy>
EOF
相关的配置参数解释可参考官方文档,有详细说明的!!!
启动服务
代码语言:javascript复制/usr/local/http/bin/apachectl -k start
3
测试反向代理与负载均衡
代码语言:javascript复制[root@centos6-001 ~]# curl http://10.0.0.100:8080
welcome to mingongge.com
[root@centos6-001 ~]# curl http://10.0.0.10:8080
welcont to 10.0.0.10
测试负载均衡
代码语言:javascript复制[root@centos6-001 ~]# curl http://10.0.0.100/mgg
welcont to 10.0.0.10
[root@centos6-001 ~]# curl http://10.0.0.100/mgg
welcome to mingongge.com
代码语言:javascript复制[root@centos6-001 ~]# curl http://10.0.0.100/mgg
welcont to 10.0.0.10
[root@centos6-001 ~]# curl http://10.0.0.100/mgg
welcome to mingongge.com