systemd系统服务管理

1.首先安装依赖包

yum install openssl-devel pcre-devel gcc -y

2.下载解压源码包

wget -O /opt/nginx-1.18.0.tar.gz http://nginx.org/download/nginx-1.18.0.tar.gz
tar zxvf nginx-1.18.0.tar.gz

3.创建用户

groupadd www -g 2000
useradd www -s /sbin/nologin -M -u 2000 -g 2000

4.配置编译参数

cd /opt/nginx-1.18.0
./configure --help#查看配置帮助
./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre 

5.编译安装

make && make install

6.启动命令

/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

#绝对命令启动的nginx也可以把nginx放到/usr/sbin里
cp /opt/nginx/sbin/nginx /usr/sbin/nginx

7.停止nginx命令

/opt/nginx/sbin/nginx -s stop

8.重新加载命令

/opt/nginx/sbin/nginx -s reload

9.编写systemd启动服务脚本

cat > /usr/lib/systemd/system/nginx.service << 'EOF'
[Unit]
Description=Hello Nginx

[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecStop=/opt/nginx/sbin/nginx -s stop
ExecReload=/opt/nginx/sbin/nginx -s reload

[Install]
WantedBy=multi-user.target
EOF

10.测试

systemctl start nginx
ps aux|grep nginx
systemctl stop nginx
ps aux|grep nginx
systemctl reload nginx
ps aux|grep nginx

image

posted @ 2021-04-08 15:35  ngwei  阅读(187)  评论(0)    收藏  举报