nginx 源码编译安装并编写服务启动脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 源码编译安装并编写服务启动脚本相关的知识,希望对你有一定的参考价值。
1. 使用xshell将nginx源码包上传到server
2. 安装依赖的软件包工具 zlib-devel?? pcre-devel?? gcc? gcc-c++
yum -y install zlib-devel pcere-devel gcc gcc-c++
验证一下:
3. 指定nginx的运行用户 (创建nginx用户不使其登录系统、-M不创建宿主目录)
[[email protected] ~]# useradd -s /sbin/nologin -M nginx
4. 编译安装nginx
[[email protected] ~]# tar zxf nginx-1.11.2.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/nginx-1.11.2/
[[email protected] nginx-1.11.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
[[email protected] nginx-1.11.2]# make -j 4 && make install
编译安装成功
现在service不受控制,需要
5、编写nginx 服务启动脚本
vim nginx
代码复制如下:
# chkconfig: 2345 99 20
#description: nginx-server
nginx=/usr/local/nginx/sbin/nginx
case $1 in
??????? start)
????????????? netstat -anptu | grep nginx
????????????? if [ $? -eq 0 ]
???????????????? then
??????????????????? echo "nginx-server is already running"
????????????????? else
???????????????????? echo "nginx-server begin start"
??????????????????? $nginx
???????????????? fi
???????? ;;
??????? stop)
??????????????? $nginx -s stop
???????????????? if [ $? -eq 0 ]
???????????????? then
??????????????????? echo "nginx-server is stoped"
???????????????? else
??????????????????? echo "nginx-server stop fail,try again"
???????????????? fi
;;
??????? status)
???????????? netstat -anlpt | grep nginx
???????????????? if [ $? -eq 0 ]
???????????????? then
??????????????????? echo "nginx-server is running"
???????????????? else
??????????????????? echo "nginx-server is stoped"
fi
;;
??????? restart)
???????????????? $nginx -s reload
???????????????? if [ $? -eq 0 ]
???????????????? then
???????????????????? echo "nginx-server is begin restart"
???????????????? else
???????????????????? echo "nginx-server restart fail"
???????????????? fi
;;
???????? *)
???????? echo "please enter {start restart status stop}"
;;
6、将脚本文件拷贝到/etc/init.d/目录下
测试:
以上是关于nginx 源码编译安装并编写服务启动脚本的主要内容,如果未能解决你的问题,请参考以下文章