不言不语

您现在的位置是: 首页 >  Linux

Linux

CentOS7编译安装nginx

2022-03-12Linux
CentOS7编译安装nginx

系统环境-nginx

1. 轻量级,占用资源少

2. 抗并发,nginx 以 epoll 作为开发模型,处理请求是异步非阻塞的

3. nginx 配置方便 负载均衡… 正则 lua 扩展


系统版本

[root@localhost ~]# cat /etc/redhat-release 

CentOS Linux release 7.0.1406 (Core) 


yum install net-tools   安装查看端口

yum install wget -y   安装wget


下载

 

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


解压tar xf 压缩文件名称


进入文件夹 cd nginx-1.20.2


image.png



添加nginx组,用户

[root@localhost nginx-1.20.2]# groupadd nginx    (创建组)

[root@localhost nginx-1.20.2]# useradd nginx -g nginx -s /sbin/nologin -M

安装nginx(编译)

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module


image.png


需要安装gcc


[root@localhost nginx-1.20.2]# yum install gcc gcc-c++ -y


image.png


没有pcre,需要安装


[root@localhost nginx-1.20.2]# yum install pcre-devel -y


image.png


缺少openssl


[root@localhost nginx-1.20.2]# yum install openssl-devel  -y


#查看是否配置成功($? 是显示最后命令的退出状态,0表示没有错误,其他表示有错误)

[root@n1 nginx-1.14.2]# echo $?

0

image.png



安装

make && make install

查找安装路径:

whereis nginx
查看所有端口

netstat -ntlp

如果提示-bash: netstat: command not found

yum install net-tools

启动、停止nginx

cd /usr/local/nginx/sbin/

./nginx         ---启动
./nginx -h      ---查看命令
./nginx -v      ---查看版本
./nginx -V      ---编译参数
./nginx -s stop   ----停机
./nginx -s quit
./nginx -s reload   ---不影响正在运行的进程
killall nginx   ---杀掉进程


killall出现-bash: killall: command not found及使用方法


1. centos下

如果出现: -bash: killall: command not found

yum install psmisc -y 
1

2. debian、ubuntu系统下

apt-get install psmisc

3. 使用

       killall命令用于杀死指定名字的进程(kill processes by name),即结束同名的的所有进程。在使用kill命令终止进程需要先获取进程PID,而使用killall命令直接使用进程名称,即可终止进程。


 实例
killall nginx


关闭防火墙


systemctl stop firewalld.service   (服务器如果重启,防火墙自己就开了)


image.png


文章评论