# yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -ynode
① 下載nginxnginx
# wget -c https://nginx.org/download/nginx-1.12.1.tar.gz
② 解壓c++
# tar -zxvf nginx-1.17.0.tar.gz # cd nginx-1.17.0
③ 使用默認配置session
# ./configure
④ 編譯、安裝dom
# make # make install
⑤ 啓動nginxssh
# cd /usr/local/nginx/sbin/ # ./nginx 其它命令 # ./nginx -s stop # ./nginx -s quit # ./nginx -s reload
一、 進入到 /usr/lib/systemd/system 目錄下,編輯文件 nginx.servicepost
# cd /usr/lib/systemd/system # vi nginx.service
二、在nginx.service文件中加入如下代碼ui
[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
參數說明:spa
注意:[Service]的啓動、重啓、中止命令所有要求使用絕對路徑.net
[Unit]:服務的說明 Description:描述服務 After:描述服務類別 [Service]服務運行參數的設置 Type=forking是後臺運行的形式 ExecStart爲服務的具體運行命令 ExecReload爲重啓命令 ExecStop爲中止命令 PrivateTmp=True表示給服務分配獨立的臨時空間 [Install]運行級別下服務安裝的相關設置,可設置爲多用戶,即系統運行級別爲3
三、設置開機啓動
# systemctl enable nginx.service
四、取消開機自啓動
# systemctl disable nginx.service
五、其餘命令
啓動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 2019-03-23 07:08:49 CST; 7s ago Process: 18942 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS) Main PID: 18943 (nginx) CGroup: /system.slice/nginx.service ├─18943 nginx: master process /usr/local/nginx/sbin/nginx └─18944 nginx: worker process Mar 23 07:08:49 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server... Mar 23 07:08:49 localhost.localdomain systemd[1]: 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@8:2.service loaded active exited LVM2 PV scan on device 8:2 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. 35 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