二进制编译安装nginx并加入systemctl管理服务
一、安装nginx所需环境
# yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
二、安装nginx
① 下载nginx
# wget -c https://nginx.org/download/nginx-1.12.1.tar.gz
② 解压
# tar -zxvf nginx-1.17..tar.gz
# cd nginx-1.17.
③ 使用默认配置
# ./configure
④ 编译、安装
# make
# make install
⑤ 启动nginx
# cd /usr/local/nginx/sbin/
# ./nginx 其它命令
# ./nginx -s stop
# ./nginx -s quit
# ./nginx -s reload
三、加入systemctl管理服务
1、 进入到 /usr/lib/systemd/system 目录下,编辑文件 nginx.service
# cd /usr/lib/systemd/system
# vi nginx.service
2、在nginx.service文件中加入以下代码
[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true [Install]
WantedBy=multi-user.target
参数说明:
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
3、设置开机启动
# systemctl enable nginx.service
4、取消开机自启动
# systemctl disable nginx.service
5、其他命令
启动nginx服务
# systemctl start nginx.service
查看服务当前状态
# systemctl status nginx
[root@localhost system]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Sat -- :: CST; 7s ago
Process: ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=/SUCCESS)
Main PID: (nginx)
CGroup: /system.slice/nginx.service
├─ nginx: master process /usr/local/nginx/sbin/nginx
└─ nginx: worker process Mar :: localhost.localdomain systemd[]: Starting The nginx HTTP and reverse proxy server...
Mar :: localhost.localdomain systemd[]: Started The nginx HTTP and reverse proxy server.
停止nginx服务
# systemctl stop nginx
重新启动服务
# systemctl restart nginx
查看所有已启动的服务
# systemctl list-units --type=service
[root@localhost ~]# systemctl list-units --type=service
UNIT LOAD ACTIVE SUB DESCRIPTION
auditd.service loaded active running Security Auditing Service
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
getty@tty1.service loaded active running Getty on tty1
kdump.service loaded active exited Crash recovery kernel arming
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
lvm2-pvscan@:.service loaded active exited LVM2 PV scan on device :
mariadb.service loaded active running MariaDB database server
network.service loaded active exited LSB: Bring up/down networking
NetworkManager.service loaded active running Network Manager
nginx.service loaded active running The nginx HTTP and reverse proxy server
polkit.service loaded active running Authorization Manager
postfix.service loaded active running Postfix Mail Transport Agent
rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg
rhel-import-state.service loaded active exited Import network configuration from initramfs
rhel-readonly.service loaded active exited Configure read-only root support
rsyslog.service loaded active running System Logging Service
sshd.service loaded active running OpenSSH server daemon
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
systemd-user-sessions.service loaded active exited Permit User Sessions
systemd-vconsole-setup.service loaded active exited Setup Virtual Console
tuned.service loaded active running Dynamic System Tuning Daemon
wpa_supplicant.service loaded active running WPA Supplicant daemon LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type. loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@localhost ~]#
参考博客:https://blog.csdn.net/qq_36441027/article/details/80636526
二进制编译安装nginx并加入systemctl管理服务的更多相关文章
- 源码安装Nginx以及用systemctl管理
一.源码安装Nginx: 先安装gcc编译器(安装过的可以忽略) [root@localhost ~]# yum -y install gcc gcc-c++ wget 进入src目录 [root@l ...
- 手动编译安装Libvirt之后利用systemctl管理libvirtd服务
因为要给特殊的虚拟机关联文件指定selinux标签,而默认的Libvirt没有这个功能,所以需要修改LIbvirt源代码,重新编译安装Libvirt,而手动编译安装的LIbvirt,没有办法使用sys ...
- linux软件管理之------编译安装nginx服务器并手动编写自动化运行脚本
红帽系列的 linux软件管理分为三类:1. rpm 安装软件.2. yum 安装软件.3. 源码包编译安装.前面两种会在相关专题给出详细讲解.源码包的编译安装是非常关键的,我们知道linux的相关版 ...
- 源码编译安装nginx
安装依赖软件 1.安装编译工具gcc gcc是一个开源编译器集合,用于处理各种各样的语言:C.C++.Java.Ada等,在linux世界中是最通用的编译器,支持大量处理器:x86.AMD64.Pow ...
- 初识Nginx及编译安装Nginx
初识Nginx及编译安装Nginx 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 nginx-1.12.2 1.什么是Nginx? 如果你听说或使用过Apache软件 ...
- Ubuntu编译安装nginx以及配置自动启动
本文主要介绍ubuntu如何编译安装nginx以及遇到的问题 和 配置系统自动启动服务 查看操作系统版本 cat /etc/issue Ubuntu 18.04.3 LTS \n \l 更改镜 ...
- 源码编译安装nginx及设置开机启动项
1.上传nginx文档:解压到/data目录下,并安装依赖包tar xf nginx-1.20.1.tar.gz -C /data/cd /data/nginx-1.20.1/ && ...
- Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Mariadb 10.1.20 + Nginx 1.10.2 + PHP 7.1.0 + Laravel 5.3 )
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...
- CentOS7 编译安装 Nginx (实测 笔记 Centos 7.0 + nginx 1.6.2)
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...
随机推荐
- [LOJ#3022][网络流]「CQOI2017」老 C 的方块
题目传送门 定义有特殊边相邻的格子颜色为黑,否则为白 可以看出,题目给出的限制条件的本质是如果两个小方块所在的格子 \(x\) 和 \(y\) 为两个相邻的黑格,那么 \(x\) 和 \(y\) 之间 ...
- CF6B President's Office 题解
看到大致思路一致的题解,决定发一篇运用STL不用dfs的题解 好久不发题解,心里不爽 思路: 1.输入的同时找到总统桌子的位置,用vector<pair <int,int> ...
- 去除空白字符串trim
let str = ' foo ' //去除开头空格 console.log(str.trimLeft()) console.log(str.trimStart()) //去除尾部空格 console ...
- 《ASP.NET Core 高性能系列》关于性能的闲聊
一.通常的性能问题类型 让我们一起看看那些公共的性能问题,看看他们是或者不是.我们将了解到为什么我们常常在开发期间会错过这些问题.我们也会看看当我们考虑性能时语言的选择.延迟.带宽.计算等因素. 二. ...
- 手把手写一个基于Spring Boot框架下的参数校验组件(JSR-303)
前言 之前参与的新开放平台研发的过程中,由于不同的接口需要对不同的入参进行校验,这就涉及到通用参数的校验封装,如果不进行封装,那么写出来的校验代码将会风格不统一.校验工具类不一致.维护风险高等其它因素 ...
- Quartz.Net和队列应用demo
using System; using System.Collections.Generic; using System.Threading; namespace ConsoleApplication ...
- 前端url参数中带有callback并产生错误
错误截图: 初步诊断是由于后端返回值的数据格式不正确造成的 解决方式: 1).接受在springmvc中接受callback参数 2).将对象转为Object 3).拼接callback方法,其中返回 ...
- JDK源码系列总索引
一 目标 记录学习jdk源码的一些笔记和心得,jdk版本使用11.0.1,工具idea Class后面序号为优先级1-4,优先级递减 目录转载自博客: https://blog.csdn.net/qq ...
- <状压DP>solution-POJ3311_Hie with the Pie
Hie with the Pie Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...
- <背包>solution_CF366C_Dima and Salad
Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. T ...