编译安装 ngnix及实现systemctl管理服务

  1. cd /opt

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

tar xf nginx-1.18.0.tar.gz

cd nginx-1.18.0

yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel

  1. mkdir /apps/nginx -p

./configure --prefix=/apps/nginx

  1. make 将源代码转换成二进制

make install 将服务写进硬盘中

4.ln -s /apps/nginx/sbin/nginx /usr/sbin/nginx

做软链接 可以补全

5.命令

systemctl stop firewalld 关闭防火墙

setenforce 0 关闭防护

nginx 开启服务

ss -natp|grep 80 检测服务开启 (httpd服务端口是80)

curl IP地址 检测服务开启

nginx -s stop 关闭服务

6.编译安装配置文件编写使得可以使用systemctl管理

进入目录创建一个对应服务的.service文件

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

7.将模板复制进去,然后按照备注修改自己的服务安装路径即可,i键插入,鼠标右键粘贴,

shift+:wq(保存退出) ,回车

Unit

Description=The nginx HTTP and reverse proxy server

#描述软件的功能

Service

PIDFile=/apps/nginx/logs/nginx.pid

方便使用 pid 号 进行操作 , 指明进程的 pid 号

ExecStart=/apps/nginx/sbin/nginx

#使用绝对路径启动

ExecStop=/usr/bin/kill -s TERM $MAINPID

#杀死进程

ExecReload=/apps/nginx/sbin/nginx -s reload

#重新加载

Install

WantedBy=multi-user.target

安装子字符界面

systemctl daemon-reload

#nginx 要 告诉 systemd 我加入你了

相关推荐
tmacfrank20 分钟前
网络编程中的直接内存与零拷贝
java·linux·网络
瀚高PG实验室3 小时前
连接指定数据库时提示not currently accepting connections
运维·数据库
QQ2740287563 小时前
Soundness Gitpod 部署教程
linux·运维·服务器·前端·chrome·web3
淡忘_cx3 小时前
【frp XTCP 穿透配置教程
运维
qwfys2003 小时前
How to configure Linux mint desktop
linux·desktop·configure·mint
南方以南_3 小时前
Ubuntu操作合集
linux·运维·ubuntu
冼紫菜4 小时前
[特殊字符]CentOS 7.6 安装 JDK 11(适配国内服务器环境)
java·linux·服务器·后端·centos
Chuncheng's blog5 小时前
RedHat7 如何更换yum镜像源
linux
爱莉希雅&&&5 小时前
shell脚本之条件判断,循环控制,exit详解
linux·运维·服务器·ssh
wei_work@5 小时前
【linux】Web服务—搭建nginx+ssl的加密认证web服务器
linux·服务器·ssl