Nginx系列之Linux系统安装部署Nginx环境
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
- 1
nginx官网下载nginx,解压到/usr/local/src
tar -xzvf nginx-1.11.4.tar.gz
- 1
cd nginx-1.11.4
- 1
执行配置文件
./configure
- 1
编译
make && make install
- 1
启动
cd /usr/local/nginx/sbin
- 1
./nginx
- 1
重启
cd /usr/local/nginx/sbin
- 1
./nginx -s reload
- 1
检验配置文件是否正确
检验:
ps -ef|grep nginx
- 1
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
- 1
或者
cd /usr/local/nginx/sbin
- 1
./nginx -t
- 1
查看nginx版本信息
nginx -V
- 1
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;
}
- 1
- 2
- 3
- 4
upstream可以自己定义名称
然后再http{}的server{}里修改,加入proxy_pass
location / { proxy_pass http://mynginxserver; root html; index index.html index.htm index.jsp; }
- 1
- 2
- 3
- 4
- 5
然后重启nginx
cd /usr/local/nginx/sbin
./nginx -s reload
- 1
- 2
5、keepalived安装
下载keepalived到/usr/local/src
tar -xzvf keepalived-1.2.19.tar.gz
cd /usr/local/src/keepalived-1.2.19
- 1
- 2
配置
./configure --prefix=/usr/local/keepalived
- 1
编译
make && make install
- 1
复制建立服务启动脚本,以便使用service命令控制之:
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
- 1
chmod +x /etc/init.d/keepalived
- 1
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
- 1
mkdir /etc/keepalived
- 1
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
- 1
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
- 1
启动keepalived
service keepalived start|stop
- 1
详细使用可以参考nginx官方文档
文章来源: smilenicky.blog.csdn.net,作者:smileNicky,版权归原作者所有,如需转载,请联系作者。
原文链接:smilenicky.blog.csdn.net/article/details/110942751
- 点赞
- 收藏
- 关注作者
评论(0)