1. 内核参数配置, 默认的 Linux 内核参数考虑的是通用的场景, 明显不符合用于支持高并发访问 web 服务的定义, 所以需要修改 Linux 内核参数, 使得 Nginx 可以拥有更高的性能. 可以通过修改 /etc/sysctl.conf 来更改内核参数, 常用的配置:
- fs.file-max = 999999
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_keepalive_time = 600
- net.ipv4.tcp_fin_timeout = 30
- net.ipv4.tcp_max_tw_buckets = 5000
- net.ipv4.ip_local_port_range = 1024
- net.ipv4.tcp_rmem = 4096 32768 262142
- net.ipv4.tcp_wmem = 4096 32768 262142
- net.core.netdev_max_backlog = 8096
- net.core.rmem_default = 262144
- net.core.wmem_default = 262144
- net.core.rmem_max = 2097152
- net.core.wmem_max = 2097152
- net.ipv4.tcp_syncookies = 1
更改完后执行 sysctl -p 生效.
2. 安装前需要安装 gcc 编译器, PCRE 库, zlib 库, OpenSSL 开发库等.
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
3. 下载 Nginx 编译安装
下载:
wget http://nginx.org/download/nginx-1.14.2.tar.gz
解压缩:
tar -zxvf nginx-1.14.2.tar.gz
cd 到解压后的目录执行:
- ./configure
- make
- make install
4. 常用命令
检查配置文件语法
/usr/local/nginx/sbin/nginx -t
启动服务:
/usr/local/nginx/sbin/nginx
停止服务:
/usr/local/nginx/sbin/nginx -s stop
重新加载服务:
/usr/local/nginx/sbin/nginx -s reload
优雅地停止服务:
/usr/local/nginx/sbin/nginx -s quit
指定配置文件启动:
/usr/local/nginx/sbin/nginx -c /path/to/file
查看版本:
/usr/local/nginx/sbin/nginx -v
来源: http://www.bubuko.com/infodetail-3298439.html