1、服务器环境:centos7.5
2、安装nginx
首先下载:wget http://nginx.org/download/nginx-1.14.0.tar.gz
解压:tar zxvf nginx-1.14.0.tar.gz得到解压包nginx-1.14.0
进入nginx-1.14.0,执行编译命令:./configure --with-stream --without-http
(注意:要系统支持c编译环境,安装方法yum -y install gcc gcc-c++)
make
make install
3、修改配置文件,nginx默认安装路径:/usr/local/nginx
vim /usr/local/nginx/conf/nginx.conf,内容如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#use epoll;
worker_connections 1024;
}
stream {
upstream socket{
server 192.168.1.155:8000;
server 192.168.1.154:8000;
}
server {
listen 80;
proxy_pass socket;
}
}
4、启动:/usr/local/nginx/sbin/nginx
停止:/usr/local/nginx/sbin/nginx -s stop
退出:/usr/local/nginx/sbin/nginx -s quit
重启:/usr/local/nginx/sbin/nginx -s reload