nginx 安装
yum install openssh-clients -y
nginx官网上下载nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
ls
cd src/core
vim nginx.h
删除nginx的版本
cd ..
cd ..
cd auto/cc
vim gcc 注释debug调试信息
cd /root/nginx-1.14.0
./configure --help # 查看帮助
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio # 报错时解决错误(检查安装环境)
yum install gcc -y pcre-devel openssl-devel
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio(继续检查环境,直到不报错)
make
make install
ln -s /usr/local/nginx/sbin/nginx /sbin/
nginx -t # 检测nginx语法是否错误
nginx # 开启nginx
nginx -s stop # 关闭
nginx -s reload # 重新加载
浏览器测试 172.25.11.5
cd /usr/local/nginx/html
vim test.html
<h1>www.westos.org</h1>
浏览器验证:172.25.11.5/test.html
nginx负载均衡
cd /usr/local/nginx/conf
vim nginx.conf
user nginx nginx;
worker_processes 1;
events {
worker_connections 65535;
}
http {
upstream westos {
#ip_hash;
server 172.25.11.2:80;
server 172.25.11.3:80;
server 127.0.01:80 backup;
}
server{
listen 80;
server_name www.westos.org;
location / {
proxy_pass http://westos;
}
}
lscpu # 查看cpu个数
sysctl -a | grep file #查看最大文件数
vim /etc/security/limits.conf
nginx - nofile 65536
useradd -M -d /usr/local/nginx/ nginx
nginx -t
nginx -s reload
在server 2,3打开httpd
在server1中ip_hash
weight=2
server 127.0.0.1:80 backup
物理机上测试:
当两台服务器都挂掉之后,输出vs的界面。
安装nginx-1.10.1
更改安装路径/opt/nginx(和1.14.0版本安装大同小异,可以参考)
最好可以去查看官网
./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --add-module=/root/nginx-sticky-module-ng
make
make install
cp /usr/local/nginx/conf/nginx.conf .
http {
upstream westos {
#ip_hash;
sticky;
server 172.25.11.2:80;
server 172.25.11.3:80;
#server 127.0.01:80 backup;
}
浏览器验证:
www.westos.org
这种模式会通过绑定(实现长连接)达到负载均衡。