赤水市住房和城乡建设局网站网站建设刷赞和vip
news/
2025/9/23 23:26:59/
文章来源:
赤水市住房和城乡建设局网站,网站建设刷赞和vip,浙江省工程建设协会网站,招聘网站做精准 置顶目录
1、源码编译安装nginx
2、分别编写基于RHEL6和RHEL7的脚本。
2.1 RHEL6的nginx系统服务脚本
2.2 RHEL7的nginx系统服务脚本 1、源码编译安装nginx
1.首先关闭防火墙和selinux
[rootnode13 ~]# systemctl stop firewalld
[rootnode13 ~]# setenforce 0
2.准备环境node13 ~]# systemctl stop firewalld
[rootnode13 ~]# setenforce 0
2.准备环境C和C的编译环境
[rootnode13 ~]# yum install -y gcc gcc-c make
3.下载nginx安装包或者使用wget直接上传
链接http://nginx.org/download/
4.解压安装包
[rootnode13 ~]# tar xf nginx-1.22.0.tar.gz -C /usr/local/src/
[rootnode13 ~]# cd /usr/local/src/nginx-1.22.0/
5.安装依赖项配置nginx
[rootnode13 nginx-1.22.0]# yum install -y pcre-devel zlib-devel
[rootnode13 nginx-1.22.0]# ./configure --prefix/usr/local/nginx
6.进行编译安装
[rootnode13 nginx-1.22.0]# make
[rootnode13 nginx-1.22.0]# make install
2、分别编写基于RHEL6和RHEL7的脚本。
2.1 RHEL6的nginx系统服务脚本
【1】编写系统服务脚本/etc/init.d/nginx [rootnode13 ~]# vim /etc/init.d/nginx # 主要修改以下两句 nginx${NGINX-/usr/local/nginx/sbin/nginx} conffile${CONFFILE-/usr/local/nginx/conf/nginx.conf} #!/bin/sh
#
# nginx Startup script for nginx
#
# chkconfig: - 85 15
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# description: nginx is an HTTP and reverse proxy server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop nginx
### END INIT INFO# Source function library.
. /etc/rc.d/init.d/functionsif [ -L $0 ]; theninitscript/bin/readlink -f $0
elseinitscript$0
fisysconfig/bin/basename $initscriptif [ -f /etc/sysconfig/$sysconfig ]; then. /etc/sysconfig/$sysconfig
finginx${NGINX-/usr/local/nginx/sbin/nginx}
prog/bin/basename $nginx
conffile${CONFFILE-/usr/local/nginx/conf/nginx.conf}
lockfile${LOCKFILE-/var/lock/subsys/nginx}
pidfile${PIDFILE-/var/run/nginx.pid}
SLEEPMSEC${SLEEPMSEC-200000}
UPGRADEWAITLOOPS${UPGRADEWAITLOOPS-5}
RETVAL0start() {echo -n $Starting $prog: daemon --pidfile${pidfile} ${nginx} -c ${conffile}RETVAL$?echo[ $RETVAL 0 ] touch ${lockfile}return $RETVAL
}stop() {echo -n $Stopping $prog: killproc -p ${pidfile} ${prog}RETVAL$?echo[ $RETVAL 0 ] rm -f ${lockfile} ${pidfile}
}reload() {echo -n $Reloading $prog: killproc -p ${pidfile} ${prog} -HUPRETVAL$?echo
}upgrade() {oldbinpidfile${pidfile}.oldbinconfigtest -q || returnecho -n $Starting new master $prog: killproc -p ${pidfile} ${prog} -USR2echofor i in /usr/bin/seq $UPGRADEWAITLOOPS; do/bin/usleep $SLEEPMSECif [ -f ${oldbinpidfile} -a -f ${pidfile} ]; thenecho -n $Graceful shutdown of old $prog: killproc -p ${oldbinpidfile} ${prog} -QUITRETVAL$?echoreturnfidoneecho $Upgrade failed!RETVAL1
}configtest() {if [ $# -ne 0 ] ; thencase $1 in-q)FLAG$1;;*);;esacshiftfi${nginx} -t -c ${conffile} $FLAGRETVAL$?return $RETVAL
}rh_status() {status -p ${pidfile} -b ${nginx} ${nginx}
}# See how we were called.
case $1 instart)rh_status /dev/null 21 exit 0start;;stop)stop;;status)rh_statusRETVAL$?;;restart)configtest -q || exit $RETVALstopstart;;upgrade)rh_status /dev/null 21 || exit 0upgrade;;condrestart|try-restart)if rh_status /dev/null 21; thenstopstartfi;;force-reload|reload)reload;;configtest)configtest;;*)echo $Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}RETVAL2
esacexit $RETVAL 【2】修改配置文件/usr/local/nginx/conf/nginx.conf # 找到配置以下pid: pid /var/run/nginx.pid; 【3】增加执行权限 [rootnode13 init.d]# chmod x nginx 【4】添加系统服务设置开机自启动 [rootnode13 init.d]# chkconfig --add nginx [rootnode13 init.d]# chkconfig nginx on [rootnode13 init.d]# chkconfig --list nginx # 查看服务列表 Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use systemctl list-unit-files. To see services enabled on particular target use systemctl list-dependencies [target]. nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off 【5】测试脚本 [rootnode13 init.d]# service nginx start Starting nginx (via systemctl): [ OK ] [rootnode13 init.d]# netstat -lnupt | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7026/nginx: master 在浏览器上输入自己的IP地址看是否可以访问到nginx首页 [rootnode13 init.d]# service nginx stop # 停止服务看能否停止 Stopping nginx (via systemctl): [ OK ] [rootnode13 init.d]# netstat -lnupt | grep 80 # 查看端口 再次访问浏览器就访问不到了
2.2 RHEL7的nginx系统服务脚本
【1】编写系统服务脚本/usr/lib/systemd/system/nginx.service
[Unit]
DescriptionThe nginx HTTP and reverse proxy server
Afternetwork-online.target remote-fs.target nss-lookup.target
Wantsnetwork-online.target[Service]
Typeforking
PIDFile/run/nginx.pid
ExecStartPre/usr/bin/rm -f /run/nginx.pid
ExecStartPre/usr/local/nginx/sbin/nginx -t
ExecStart/usr/local/nginx/sbin/nginx
ExecReload/usr/sbin/nginx -s reload
KillSignalSIGQUIT
TimeoutStopSec5
KillModeprocess
PrivateTmptrue[Install]
WantedBymulti-user.target
【2】修改配置文件/usr/local/nginx/conf/nginx.conf # 找到配置以下pid: pid /var/run/nginx.pid; 【3】增加执行权限 [rootnode13 system]# chmod x nginx.service 【4】测试脚本 [rootnode13 system]# systemctl daemon-reload [rootnode13 system]# systemctl start nginx [rootnode13 system]# netstat -lnupt | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17196/nginx: master [rootnode13 system]# systemctl stop nginx [rootnode13 system]# netstat -lnupt | grep 80
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914223.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!