这里我们准备四台虚拟机,二台负载均衡(LB01,LB02),二台web服务器(WEB01,WEB02)。
这里默认所有软件都安装在/data目录下。
四台虚拟机的初始安装是centos7的最小安装,并执行如下命令。
> yum -y install gcc gcc-c++ kernel-devel
配置网络(虚拟机的网络连接设置成桥接模式)
> vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
修改如下
BOOTPROTO=static
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.10.111
GATEWAY=192.168.10.1
重启网络
> service network restart
剩余的三台配置如上,IP分别为(192.168.10.122,192.168.10.133,192.168.10.144)
然后分别给四台虚拟机设置hostname,便于区分。
> hostname LB01
> hostname LB02
> hostname WEB01
> hostname WEB02
分别在四台虚拟机上安装pcre和nginx服务器
> cd /data
> tar xf pcre-8.39.tar.gz
> cd pcre-8.39
> ./configure --prefix=/data/pcre
> make && make install
> cd /data
> tar xf nginx-1.10.2.tar.gz
> cd nginx-1.10.2
> ./configure --prefix=/data/nginx \
--with-pcre=/data/pcre-8.39 \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module
> make && make install
(*--with-pcre指定的是pcre的源码目录,不是安装目录)
如果出现如下错误:
./configure: error: the HTTP gzip module requires the zlib library
./configure: error: SSL modules require the OpenSSL library
安装zlib
> yum -y install zlib zlib-devel openssl openssl-devel
启动nginx
> /data/nginx/sbin/nginx
如果出现如下问题:
nginx: [emerg] getpwnam("nginx") failed
说明没有nginx这个用户
> useradd nginx -s /sbin/nologin -M