CentOS7安装Nginx(tar包安装)

一. 安装环境 

操作系统:Centos 7. 最小化安装
服务器地址:***

二.安装过程:

1. 安装wget

yum install wget -y

2. 下载Nginx

wget http://nginx.org/download/nginx-1.25.1.tar.gz

# new
wget http://nginx.org/download/nginx-1.25.4.tar.gz

 官网下载 Nginx: http://nginx.org/en/download.html

在这里插入图片描述

3. 解压安装包, 并安装https, zlib

tar -xf nginx-1.25.1.tar.gz

# 安装https
yum -y install openssl openssl-devel

# 安装一个压缩和解压缩的环境。
yum -y install zlib zlib-devel

4. 编译安装Nginx

1)进入解压目录
cd nginx-1.25.1
yum install gcc automake autoconf libtool make -y

2)安装到指定目录并配置安装ssl证书,添加两个模块(推荐:需提前建好目录)
# prefix参数是指定固定目录
./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-stream \
--with-http_ssl_module \
--with-http_gzip_static_module

3)编译并安装(如没有权限,可使用sudo以root用户权限安装)
# 执行make命令
make distclean&make

# 执行make install命令
make install

4)安装后的目录
[root@rpp-vm00 nginx-1.25.1]# whereis nginx
nginx: /usr/local/nginx

[root@rpp-vm00 nginx-1.25.1]# cd /usr/local/nginx/
[root@rpp-vm00 nginx]# ll
总用量 0
drwxr-xr-x 2 root root 333 6月  27 09:53 conf
drwxr-xr-x 2 root root  40 6月  27 09:53 html
drwxr-xr-x 2 root root   6 6月  27 09:53 logs
drwxr-xr-x 2 root root  19 6月  27 09:53 sbin

三. 原始命令启动Nginx

[root@rpp-vm00 nginx]# cd /usr/local/nginx/sbin/
[root@rpp-vm00 sbin]# ll
总用量 5940
-rwxr-xr-x 1 root root 6079336 6月  27 09:53 nginx

# 不报错就是启动成功
[root@rpp-vm00 sbin]# ./nginx
[root@rpp-vm00 sbin]#

[root@rpp-vm00 sbin]# ps -ef | grep nginx
root      3960     1  0 09:57 ?        00:00:00 nginx: master process ./nginx
nobody    3961  3960  0 09:57 ?        00:00:00 nginx: worker process
root      3963  1155  0 09:57 pts/0    00:00:00 grep --color=auto nginx

四. 配置path路径 

# vi /etc/profile
PATH=$PATH:/usr/local/nginx/sbin

# source /etc/profile

五. systemctl配置

1. nginx.service 文件创建

vim /etc/systemd/system/nginx.service

2. 写入脚本

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

3. 重新加载配置

systemctl daemon-reload

# 启动命令
systemctl enable nginx
systemctl start nginx
systemctl status nginx
systemctl stop nginx
systemctl restart nginx

4. 启动并查看。

在这里插入图片描述

六. Nginx调优 

linux环境,nginx使用调优:	
	1.0 打开nginx配置文件  nginx.conf
		设置 worker_connections为64000
		设置 keepalive_timeout为60s
	…………………………………………………………………………
	1.1 设置最大可大开文件数
		# 临时修改
		ulimit -n 102400
		# 查看最大开文件数 ulimit -n

		# 永久修改:
		vi /etc/security/limits.conf
		…………………………………………………………………
		修改root用户:
			# open files  (-n)
			* soft nofile 65536
			* hard nofile 65536
			root soft nofile 65536
			root hard nofile 65536

			# max user processes   (-u)
			* soft nproc 65565
			* hard nproc 65565
			root soft nproc 65565
			root hard nproc 65565
		…………………………………………………………………
		修改所有用户:
			* soft nofile 4100
			* hard nofile 4100
			* soft nproc 65565
			* hard nproc 65565
		…………………………………………………………………
		以下是说明:
			* 代表针对所有用户
			nproc 是代表最大进程数
			nofile 是代表最大文件打开数
	…………………………………………………………………………
    1.2 TCP连接优化 
		# 查看连接数
		# 一般默认1024
		netstat -an|wc -l

		# 查看连接数范围
		cat /proc/sys/net/ipv4/ip_local_port_range。

		# 打开 vi /etc/sysctl.conf文件后在文件末尾加上如下配置: 
		net.ipv4.tcp_syncookies = 1
		net.ipv4.tcp_tw_reuse = 1
		net.ipv4.tcp_tw_recycle = 1
		net.ipv4.tcp_fin_timeout = 30

		# 端口范围, 或者执行: echo net.ipv4.ip_local_port_range = 1024 65000 >> /etc/sysctl.conf
		net.ipv4.ip_local_port_range = 1024 65000
		# 执行 sysctl -p 生效即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风情客家__

原创不易,觉得好的话给个打赏哈

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值