实验环境:RHEL7.2 x64-176,IP地址:192.168.1.176
实验工具:
实验步骤:
1、安装nginx服务器
2、配置nginx启动脚本
3、文件设置并验证结果
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1、安装nginx服务器
[root@localhost~]# useradd nginx -s /sbin/nologin -M #创建 nginx用户
[root@localhost~]# id nginx #验证
uid=1001(nginx)gid=1001(nginx) 组=1001(nginx)
[root@localhost ~]# yum install pcre pcre-devel openssl openssl-devel -y #安装依赖相关包
[root@localhost ~]# tar xf nginx-1.9.14.tar.gz #解压nginx源码包到当前目录
[root@localhost ~]# cd nginx-1.9.14/ #进入解压后的nginx目录
[root@localhost nginx-1.9.14]# ./configure --user=nginx --group=nginx #配置nginx
[root@localhostnginx-1.9.14]#make && make install #编译安装nginx
[root@localhostnginx-1.9.14]# /usr/local/nginx/sbin/nginx -t #检查语法
[root@localhostnginx-1.9.14]# /usr/local/nginx/sbin/nginx #启动nginx
2、配置nginx启动脚本
[root@localhost~]# vim nginx
==============================================================
#! /bin/bash
# chkconfig:2345 99 20
#description:nginx-server
nginx=/usr/local/nginx/sbin/nginx
case $1 in
start)
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx-server isalready running"
else
echo "nginx-server beginstart"
$nginx
fi
;;
stop)
$nginx -s stop
if [ $? -eq 0 ]
then
echo "nginx-server isstoped"
else
echo "nginx-server stopfail,try again"
fi
;;
status)
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx-server isrunning"
else
echo "nginx-server isstoped"
fi
;;
restart)
$nginx -s reload &>/dev/null
if [ $? -eq 0 ]
then
echo "nginx-server isbegin restart"
else
echo "nginx-server restartfail"
fi
;;
*)
echo "please enter {startrestart status stop}"
;;
esac
exit 0
================================================================
3、文件设置并验证结果
[root@localhost~]# cp nginx /etc/init.d/ #将启动文件复制到/etc/init.d目录下
[root@localhost ~]# chmod +x /etc/init.d/nginx #设置可执行权限
[root@localhost ~]# chkconfig --add nginx #将nginx添加为系统的服务
[root@localhost ~]# chkconfig --list nginx #查看nginx的开机运行级别
本文转自 维度2018 51CTO博客,原文链接:http://blog.51cto.com/xinsz08/1826562,如需转载请自行联系原作者