nginx部署与systemctl控制启动

部署nginx

下载nginx

  • nginx下载地址
  • Stable version:最新稳定版,生产环境上建议使用的版本

安装nginx前置环境

  • yum install gcc-c++
  • yum install -y pcre pcre-devel
  • yum install -y zlib zlib-devel
  • yum install -y openssl openssl-devel

解压nginx安装包并编译

tar -xvf nginx-1.14.0.tar.gz  # 不要解压在/usr/local下
./configure && make && make install		#运行安装配置
/usr/local/nginx/sbin/nginx -t		 # 测试nginx安装是否成功
# 安装成功后nginx的目录为/usr/local/nginx下	
conf/nginx.conf         #nginx 配置文件  
sbin/nginx              #nginx 启动文件  
sbin/nginx -s reload    #nginx 重启命令  

配置systemctl 启动

vim /usr/lib/systemd/system/nginx.service

[Unit]                                                          #对服务的说明
Description=nginx - high performance web server                 #描述服务
After=network.target remote-fs.target nss-lookup.target         #描述服务类别

[Service]                                                       #服务的一些具体运行参数的设置
Type=forking                                                    #后台运行的形式
PIDFile=/usr/local/nginx/logs/nginx.pid                         #PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf     #启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf           #启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload                                    #重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop                                        #停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit                                        #快速停止
PrivateTmp=true                                                                     #给服务分配临时空间

[Install]
WantedBy=multi-user.target                                                          #服务用户的模式

#在启动服务之前,需要先重载systemctl命令
systemctl daemon-reload
systemctl start nginx.service

查看nginx的启动状态

[root@localhost conf]#  systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2023-05-09 11:26:32 CST; 5s ago
  Process: 57306 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
  Process: 57303 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 57309 (nginx)
    Tasks: 2
   Memory: 968.0K
   CGroup: /system.slice/nginx.service
           ├─57309 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
           └─57310 nginx: worker process

5月 09 11:26:32 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
5月 09 11:26:32 localhost.localdomain nginx[57303]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
5月 09 11:26:32 localhost.localdomain nginx[57303]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5月 09 11:26:32 localhost.localdomain systemd[1]: Started nginx - high performance web server.
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值