Nginx是广为流行的轻量级Web服务器软件。它开源,短小精悍,简单易用,深受广大互联网企业以及IT运维人员所喜爱。很多时候,我们在生产环境基于编译方式安装Nginx后,Nginx需要手工配置自启动服务,以确保服务器异常宕机后自动重启该服务。以下描述的是基于CentOS 7下来配置自启动服务,供大家参考。
一、yum 安装方式Nginx自启动
当前环境
[root@node142 ~]# more /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
查看是否保护nginx rpm包
[root@node142 ~]# rpm -qa|grep nginx nginx-mod-http-geoip-1.12.2-2.el7.x86_64 nginx-1.12.2-2.el7.x86_64 nginx-filesystem-1.12.2-2.el7.noarch nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 nginx-mod-stream-1.12.2-2.el7.x86_64 nginx-mod-http-perl-1.12.2-2.el7.x86_64 nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 nginx-all-modules-1.12.2-2.el7.noarch nginx-mod-mail-1.12.2-2.el7.x86_64
查看是否存在相应的服务,如下,有nginx.service
[root@node142 ~]# systemctl list-unit-files |grep nginx nginx.service disabled
将其配置为自动
[root@node142 ~]# systemctl enable nginx.service
查看nginx.service文件
[root@node142 ~]# more /lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi"_blank" href="https://www.nginx.com/resources/wiki/start/topics/examples/systemd/" rel="external nofollow" >https://www.nginx.com/resources/wiki/start/topics/examples/systemd/
二、编译安装后的自启动配置
由于是编译安装,因此,对于这个自启动的脚本我们需要自行配制。
具体则是参考上面的链接或者上面给出的nginx.service文件内容。
然后将其保存为 /lib/systemd/system/nginx.service。
看下面的例子
# more /etc/redhat-release CentOS Linux release 7.4.1708 (Core) # ps -ef|grep nginx root 10092 10014 0 16:23 pts/0 00:00:00 grep --color=auto nginx root 20791 1 0 Mar20 "htmlcode"># rpm -qa|grep nginx也没有添加相应的自启动服务
# systemctl list-unit-files |grep nginxnginx版本
# /u01/app/nginx/sbin/nginx -v nginx version: nginx/1.8.1获取nginx编译模块,然后查看诸如pid,二进制位置并记录以便修改启动文件
# /u01/app/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/u01/app/nginx --sbin-path=/u01/app/nginx/sbin/nginx --conf-path=/u01/app/nginx/nginx.conf --error-log-path=/u01/app/nginx/log/error.log --http-log-path=/u01/app/nginx/log/access.log --pid-path=/u01/app/nginx/nginx.pid --lock-path=/u01/app/nginx/nginx.lock --http-client-body-temp-path=/u01/app/nginx/client_temp --http-proxy-temp-path=/u01/app/nginx/proxy_temp --http-fastcgi-temp-path=/u01/app/nginx/fastcgi_temp --http-uwsgi-temp-path=/u01/app/nginx/uwsgi_temp --http-scgi-temp-path=/u01/app/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-ipv6下面我们生成一个新的nginx.service文件
# vim /lib/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/u01/app/nginx/nginx.pid ExecStartPre=/u01/app/nginx/sbin/nginx -t ExecStart=/u01/app/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target下面我们先手工停止nginx
# /u01/app/nginx/sbin/nginx -s stop配置自启动
# systemctl enable nginx.service使用systemctl工具启动nginx服务
# systemctl start nginx.service # systemctl status nginx.service ● 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 Thu 2018-03-29 16:37:47 CST; 6s ago Process: 10588 ExecStart=/u01/app/nginx/sbin/nginx (code=exited, status=0/SUCCESS) Process: 10586 ExecStartPre=/u01/app/nginx/sbin/nginx -t (code=exited, status=0/SUCCESS) Main PID: 10590 (nginx) CGroup: /system.slice/nginx.service ├─10590 nginx: master process /u01/app/nginx/sbin/nginx ├─10591 nginx: worker process # Author : Leshami ├─10592 nginx: worker process # Blog : https://blog.csdn.net/leshami ├─10593 nginx: worker process ├─10594 nginx: worker process ├─10595 nginx: worker process ├─10596 nginx: worker process ├─10597 nginx: worker process ├─10598 nginx: worker process ├─10599 nginx: cache manager process └─10600 nginx: cache loader process Mar 29 16:37:47 ydq-std systemd[1]: Starting The NGINX HTTP and reverse proxy server... Mar 29 16:37:47 ydq-std nginx[10586]: nginx: the configuration file /u01/app/nginx/nginx.conf syntax is ok Mar 29 16:37:47 ydq-std nginx[10586]: nginx: configuration file /u01/app/nginx/nginx.conf test is successful Mar 29 16:37:47 ydq-std systemd[1]: Started The NGINX HTTP and reverse proxy server.以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]