- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章详解基于CentOS 7配置Nginx自启动由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
Nginx是广为流行的轻量级Web服务器软件。它开源,短小精悍,简单易用,深受广大互联网企业以及IT运维人员所喜爱。很多时候,我们在生产环境基于编译方式安装Nginx后,Nginx需要手工配置自启动服务,以确保服务器异常宕机后自动重启该服务。以下描述的是基于CentOS 7下来配置自启动服务,供大家参考.
1、yum 安装方式Nginx自启动 。
当前环境 。
1
2
|
[root@node142 ~]
# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
|
查看是否保护nginx rpm包 。
1
2
3
4
5
6
7
8
9
10
|
[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 。
1
2
|
[root@node142 ~]
# systemctl list-unit-files |grep nginx
nginx.service disabled
|
将其配置为自动 。
1
|
[root@node142 ~]
# systemctl enable nginx.service
|
查看nginx.service文件 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[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?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
|
上述配置文件中的内容和官网提供的一模一样 。
https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ 。
2、编译安装后的自启动配置 。
由于是编译安装,因此,对于这个自启动的脚本我们需要自行配制.
具体则是参考上面的链接或者上面给出的nginx.service文件内容.
然后将其保存为 /lib/systemd/system/nginx.service.
看下面的例子 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# 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 ? 00:00:00 nginx: master process ./sbin/nginx -c /u01/app/nginx/nginx.conf
nobody 20792 20791 0 Mar20 ? 00:00:44 nginx: worker process
nobody 20793 20791 0 Mar20 ? 00:00:42 nginx: worker process
nobody 20794 20791 0 Mar20 ? 00:00:50 nginx: worker process
nobody 20795 20791 0 Mar20 ? 00:00:44 nginx: worker process
nobody 20796 20791 0 Mar20 ? 00:00:43 nginx: worker process
nobody 20797 20791 0 Mar20 ? 00:00:43 nginx: worker process
nobody 20798 20791 0 Mar20 ? 00:00:37 nginx: worker process
nobody 20799 20791 0 Mar20 ? 00:00:48 nginx: worker process
nobody 20800 20791 0 Mar20 ? 00:00:04 nginx: cache manager process
#
|
无相应的rpm包,如下查询,此处为编译安装 。
1
|
# rpm -qa|grep nginx
|
也没有添加相应的自启动服务 。
1
|
# systemctl list-unit-files |grep nginx
|
nginx版本 。
1
2
|
# /u01/app/nginx/sbin/nginx -v
nginx version: nginx/1.8.1
|
获取nginx编译模块,然后查看诸如pid,二进制位置并记录以便修改启动文件 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# /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文件 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# 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 。
1
|
# /u01/app/nginx/sbin/nginx -s stop
|
配置自启动 。
1
|
# systemctl enable nginx.service
|
使用systemctl工具启动nginx服务 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# 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.
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/leshami/article/details/79745487 。
最后此篇关于详解基于CentOS 7配置Nginx自启动的文章就讲到这里了,如果你想了解更多关于详解基于CentOS 7配置Nginx自启动的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在使用 CentOS 6 机器。我尝试遵循以下指南: How to open port in centOS http://ask.xmodulo.com/open-port-firewall-ce
我正在为 CentOS 7 创建一个脚本,但我正在努力根据变量连接值,这与我工作的其他发行版不同。例如,在下面的代码中: DIR_BKP=/tmp/_bkp_local PATH_LOG=$DIR_B
我从以下位置下载了文件: https://github.com/christiangalsterer/httpbeat/releaseshttpbeat-4.0.0-x86_64.rpm 并尝试通过以
我想在我的 Centos 8 中使用命令 mkimage。 我尝试使用命令 dnf install uboot-tools 以 root 身份安装 uboot-tools 但这不可用。 谁能指导我如何
我有一个 Centos 服务器。 结果 $ cat /etc/centos-release CentOS Linux release 7.9.2009 (Core) 和 $ yum list i
我在CentOs7 上安装Gitlab 后遇到了麻烦。我第一次被重定向到管理员密码创建页面,在输入管理员用户密码后,服务器发送错误。 422 The change you requested was
因此,我正在尝试从我的一个运行 centos 的邮箱中发送电子邮件,并且我已经安装并打开了 sendmail,但是发送一封电子邮件实际上需要几分钟时间。电子邮件不是应该几乎是即时的吗? 这是我的/et
我正在尝试在虚拟 Centos 7 发行版上构建一些 C++ 库。由于我还没有发现这个操作系统看不到/usr/local/lib 或/usr/local/lib64 的原因,这些库安装在其他 linu
我正在尝试通过以下网址在我的服务器(centos 7.1 minimal)上安装 imagemagick: imagemagick installation steps 在第 1 步得到这个错误: L
当我尝试安装 rpmforge(我需要安装 phpmyadmin)时出现此错误,将不胜感激任何帮助! [root@plasticarmy ~]# yum http://pkgs.repoforge.o
我需要安装一个centos 5 repo 来在centos 7 机器上下载用于el5 的dhclient,以便在centos 5 机器上传输dhclient rpms。有可能的 ? 谢谢! 最佳答案
我正在开发一个可以在 CentOS 8 和 CentOS 7 系统上运行的程序。在其中,我使用 gethostbyname 将 DNS 名称解析为 IP 地址。 为了尝试使代码可移植,我正在使用以下命
我想在 CentOS7(或 CentOS6)上安装 cgal 模块。它需要 pgrouting 才能使用 PostGIS。 我一直用 CGAL Manual Installation 安装 cgal
我在 CentOS 平台上使用 R/RStudio。我需要查看二进制日志文件(/var/log/messages)是否包含有关图形设备绘图问题的更多信息,但我无法从 RStudio 中读取它。 我在社
我正在尝试在我的 CentOS 上本地安装 Kubernetes。我正在关注这个博客 http://containertutorials.com/get_started_kubernetes/inde
来自 http://kubernetes.io/docs/getting-started-guides/kubeadm/ CentOS Linux 版本 7.2.1511(核心) (1/4) 在主机上
使用tcpdump监控网络流量时,发现很多dns反向查询记录。 像这样: A_IP.55276 > DNS_IP.domain: 9247+ PTR?查询 IP.in-addr.arpa。 (45)
我正在尝试在 CentOS 6.7 和 ./configure --prefix=$HOME/local 上安装 mutt运行良好,但在 make install步骤,我在下面遇到了这个错误,我不知道
如何在 CENTOS 中删除所有以 *0x0.jpg 结尾的文件?我需要删除嵌套在文件夹和子文件夹中的多个文件 最佳答案 我假设你有一个外壳 - 试试 find /mydirectory -type
我需要检索安装在我的 Linux (Centos) 主机上的所有软件包的软件包版本。 rpm -qa 给了我所有已安装软件包的列表。 我知道 rpm -qi "package name"给了我包信息。
我是一名优秀的程序员,十分优秀!