后端主机直接yum安装
yum install httpd -y
反向代理端采用源码编译安装
yum install apr-devel pcre-devel apr-util-devel openssl-devel -y
编译安装apache服务
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
sed -i "s#Listen 80#Listen 8080#g" /etc/httpd/conf/httpd.conf
/etc/init.d/httpd start
配置反向代理服务器
首先开启相关模块
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
修改配置文件
cat >>/usr/local/http/conf/httd.conf << EOF
ProxyPass /mgg balancer://mingongge
ProxyPassReverse /mgg balancer://mingongge
<Proxy balancer://mingongge>
BalancerMember :8080
BalancerMember 0:8080
</Proxy>
EOF
相关的配置参数解释可参考官方文档,有详细说明的!!!
启动服务
/usr/local/http/bin/apachectl -k start
3测试反向代理与负载均衡[root@centos6-001 ~]# curl 0:8080
welcome to mingongge.com
[root@centos6-001 ~]# curl :8080
welcont to 10.0.0.10
测试负载均衡
[root@centos6-001 ~]# curl 0/mgg
welcont to 10.0.0.10
[root@centos6-001 ~]# curl 0/mgg
welcome to mingongge.com
[root@centos6-001 ~]# curl 0/mgg
welcont to 10.0.0.10
[root@centos6-001 ~]# curl 0/mgg
welcome to mingongge.com
如有帮助,扫码打赏民工哥吧!