一.Nginx:
1.什么是Nginx:
Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。
2.Nginx的特点:
1)热部署
2)可以高并发连接
3)低的内存消耗
4)处理响应请求很快
5)具有很高的可靠性
二.实验:
(一)负载均衡:和反向代理
实验环境:
三台6.5的虚拟机。yum源配置相同,关闭selinux,关闭iptables
Server2,3下载阿帕奇服务。
yum源配置:
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.152.250/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.152.250/rhel6.5/LoadBalancer
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.152.250/rhel6.5/HighAvailability
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.152.250/rhel6.5/ResilientStorage
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.152.250/rhel6.5/ScalableFileSystem
gpgcheck=0
IP:172.25.152.1 server1
IP:172.25.152.2 server2(RS主机)
IP:172.25.152.3 server3(RS主机)
Server1:
1下载nginx安装压缩包
2解压:tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
3修改配置文件中可视版本:vim src/core/nginx.h
4修改gcc指定值:vim auto/cc/gcc
5对安装包进行编译:./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
##执行此操作时必须在进入解压后的文件夹中才能进行
####################################
如果编译不能成功执行,需要解决依赖性:
(1)Checking for C compiler ... Not found -----> yum install -y gcc
(2)./configure: error: the HTTP rewrite module requires the PCRE library. -----> yum install -y pcre-devel
(3)./configure: error: SSL module require the OpenSSL library. -----> yum install -y openssl-devel
#####################################
make && make install
##如果前期编译成功后想进行修改,例如修改安装文件夹的位置,需要执行make clean
6查看编译大小:du -sh
##由此确定编译是否成功
7建立链接:ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
##可以用which nginx检查连接是否正确
8创建nginx新用户:useradd -M -d /usr/local/nginx/ -u 800 nginx
9修改安全权限文件最大数:vim /etc/security/limits.conf
10查看权限修改:su - nginx
ulimit -a
##open files (-n) 65535时即为修改成功
11修改配置文件:vim /usr/local/nginx/conf/nginx.conf
##在此之前,将此虚拟机设置为两个CPU
12检查语法错误:nginx -t
13重新加载服务:nginx -s reload
14开启nginx服务:nginx
15查看服务进程情况:ps -aux
Server2,3:
1开启http服务:/etc/init.d/httpd start
测试:
物理机:for i in {1..10}; do curl www.westos.org; done
页面访问www.westos.org
################################
vim /usr/local/nginx/conf/nginx.conf
1)可以设置论寻的权重:weight=数字
2)可以直接down掉一个IP:down
3)可以设置一个备用IP:backup
##注意修改备用IP的http服务监听端口为8080防止端口发生冲突
##备用IP用于两个服务器都发生问题时对客户的提示
4)可以设置同一台主机访问同一个IP的客户端:ip_hash
##################################
##每次修改完都需要nginx -s reload来重新加载服务