本文共 3619 字,大约阅读时间需要 12 分钟。
系统环境:192.168.56.11 linux-node1.example.com centos 7.1
192.168.56.12 linux-node2.example.com centos 7.1
[root@linux-node1 ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@linux-node1 ~]# yum install -y gcc glibc gcc-c++ make screen tree lrzsz
在两台虚拟机中均使用Yum安装一个Apache用于做真实机,监听8080端口
###linux-node1.example.com
[root@linux-node1 ~]# yum install -y httpd
[root@linux-node1 ~]# sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf
[root@linux-node1 ~]# systemctl start httpd
[root@linux-node1 ~]# echo "linux-node1.example.com" > /var/www/html/index.html
[root@linux-node1 ~]# curl http://192.168.56.11:8080/
linux-node1.example.com
###linux-node2.example.com
[root@linux-node2 ~]# yum install -y httpd
[root@linux-node2 ~]# sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf
[root@linux-node2 ~]# systemctl start httpd
[root@linux-node2 ~]# echo "linux-node2.example.com" > /var/www/html/index.html
[root@linux-node2 ~]# curl http://192.168.56.12:8080/
linux-node2.example.com
下面操作只在linux-node1.example.com上操作
#linux-node1.example.com
## Apache 源码编译安装
[root@linux-node1 ~]# yum install -y apr-devel apr-util-devel pcre-devel openssl-devel
[root@linux-node1 ~]# cd /usr/local/src
[root@linux-node1 src]# wget http://www-eu.apache.org/dist//httpd/httpd-2.4.18.tar.gz
[root@vpn-node3 src]# tar zxf httpd-2.4.18.tar.gz
[root@vpn-node3 src]# cd httpd-2.4.18/
[root@linux-node1 httpd-2.4.18]# ./configure --prefix=/usr/local/httpd-2.4.18 --enable-so --enable-modules="all"
[root@linux-node1 httpd-2.4.18]# make && make install
[root@linux-node1 ~]# ln -s /usr/local/httpd-2.4.18/ /usr/local/httpd
### 测试配置并启动Nginx
[root@linux-node1 ~]# /usr/local/httpd/bin/apachectl -t
Syntax OK
[root@linux-node1 ~]# /usr/local/httpd/bin/apachectl -k start
## Nginx 源码编译安装
[root@linux-node1 ~]# useradd -s /sbin/nologin -M www
[root@vpn-node3 src]# wget http://nginx.org/download/nginx-1.9.12.tar.gz
[root@linux-node1 src]# tar zxf nginx-1.9.12.tar.gz
[root@linux-node1 src]# cd nginx-1.9.12
[root@linux-node1 nginx-1.9.12]#./configure --prefix=/usr/local/nginx-1.9.12 \
--user=www --group=www --with-http_ssl_module \
--with-http_stub_status_module --with-file-aio
[root@linux-node1 nginx-1.9.12]# make && make install
[root@linux-node1 ~]# ln -s /usr/local/nginx-1.9.12/ /usr/local/nginx
### 测试配置并启动Nginx
[root@linux-node1 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.9.12/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.9.12/conf/nginx.conf test is successful
[root@linux-node1 ~]# /usr/local/nginx/sbin/nginx
## Haproxy源码编译安装
[root@linux-node1 ~]# cd /usr/local/src
[root@linux-node1 src]# wget http://www.haproxy.org/download/1.6/src/haproxy-1.6.3.tar.gz
[root@linux-node1 src]# tar zxf haproxy-1.6.3.tar.gz
[root@linux-node1 src]# cd haproxy-1.6.3
[root@linux-node1 src]# make TARGET=linux2628 PREFIX=/usr/local/haproxy-1.6.3
[root@linux-node1 src]# make install
[root@linux-node1 ~]# cp /usr/local/sbin/haproxy /usr/sbin/
[root@linux-node1 ~]# haproxy -v
HA-Proxy version 1.6.3 2015/12/25
Copyright 2000-2015 Willy Tarreau <willy@haproxy.org>
### Haproxy启动脚本
[root@linux-node1 ~]# cd /usr/local/src/haproxy-1.6.3
[root@linux-node1 haproxy-1.6.3]# cp examples/haproxy.init /etc/init.d/haproxy
[root@linux-node1 haproxy-1.6.3]# chmod 755 /etc/init.d/haproxy
### Haproxy配置文件
[root@linux-node1 ~]# useradd -r haproxy
[root@linux-node1 ~]# mkdir /etc/haproxy
[root@linux-node1 ~]# mkdir /var/lib/haproxy
[root@linux-node1 ~]# mkdir /var/run/haproxy