1、什么是nginx?
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。如图,nginx常被用于做代理
2、 安装环境准备
- XFTP(linux文件上传)
- XShell(Linux远程软件)
- nginx-1.11.4(nginx linux版本)
3、安装部署Nginx
nginx安装之前要先安装pcre、openssl、zlib
注意:./configure --prefix=/usr/local/keepalived configure:error:!!!
OpenSSL is not properly installed on your system. !!! !!! Can not
include OpenSSL headers files.
解决方法:安装openssl,同时pcre也一起安装一下,gcc、zlib没有安装也可以安装一下
yum -y install pcre pcre-devel openssl openssl-devel zlib* gcc
nginx官网下载nginx,解压到/usr/local/src
tar -xzvf nginx-1.11.4.tar.gz
cd nginx-1.11.4
执行配置文件
./configure
编译
make && make install
启动
cd /usr/local/nginx/sbin
./nginx
重启
cd /usr/local/nginx/sbin
./nginx -s reload
检验配置文件是否正确
检验:
ps -ef|grep nginx
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd /usr/local/nginx/sbin
./nginx -t
查看nginx版本信息
nginx -V
4、Nginx负载均衡
cd /usr/local/nginx/conf,找到nginx.conf配置文件
在http{}里面加入,ip1就是你的一台服务器的ip,ip2同理
upstream mynginxserver{
server ip1:8080 weight=1 max_fails=1 fail_timeout=10s;
server ip2:8081 weight=2 max_fails=1 fail_timeout=10s;
}
upstream可以自己定义名称
然后再http{}的server{}里修改,加入proxy_pass
location / {
proxy_pass http://mynginxserver;
root html;
index index.html index.htm index.jsp;
}
然后重启nginx
cd /usr/local/nginx/sbin
./nginx -s reload
5、keepalived安装
下载keepalived到/usr/local/src
tar -xzvf keepalived-1.2.19.tar.gz
cd /usr/local/src/keepalived-1.2.19
配置
./configure --prefix=/usr/local/keepalived
编译
make && make install
复制建立服务启动脚本,以便使用service命令控制之:
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
chmod +x /etc/init.d/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
启动keepalived
service keepalived start|stop
详细使用可以参考nginx官方文档
本文同步分享在 博客“smileNicky”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。