Nginx服务安装及运行控制脚本

Nginx的安装

1.先准备要安装的Nginx的版本
在这里插入图片描述
解包

tar zxvf nginx-1.12.2.tar.gz

2.安装支持软件,以便提供应的库和头文件,确保安装顺利完全。

yum -y install pcre-devel zlib-devel '配置及运行需要pcre,zlib等软件包支持'

3.创建运行用户,组(默认以nobody身份运行)

useradd -M -s /sbin/nologin nginx '创建一个用户 不建立宿主文件夹,禁止登录shell环境'

5.编译安装Nginx

cd nginx-1.12.2/ '进入nginx-1.12.2 这里用的是1.12.2版本'
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
make && make install '编译安装'

为了以便管理员直接执行nginx命令 创建链接文件

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@server1 ~]# ls -l /usr/local/sbin/nginx '查看链接文件成功没有?'
lrwxrwxrwx 1 root root 27 1129 21:52 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx

6.查看nginx文件语法检测

nginx -t '以下是通过效果'
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok '语法ok'
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful '测试通过'

nginx '默认是启动服务'
 netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      15738/nginx: master 

制作管理脚本

为了服务的启动,停止,重载等操作更加的方便去编写Nginx服务的脚本,并使用chkconfig和service工具来管理,更加符合RHEL系统的管理习惯。

vi /etc/init.d/nginx
!/bin/bash
#chkconfig: 35 99 20
#description:Nginx HTTP Server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
reload)
kill -s HUP $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0


chmod +x /etc/init.d/nginx  '给权限'

chkconfig --add nginx
chkconfig --list
nginx           0:1:2:3:4:5:6:'验证35开启没有'

配置文件nginx.conf

ln -s /usr/local/nginx/conf/nginx.conf /etc/

vi /etc/nginx.conf '原来默认是/usr/local/nginx/conf/nginx.conf'

#user  nobody 改 user  nginx nginx;

worker_processes  4; '默认是1 一般设1就够用。'

#error_log  logs/error.log  info; '把#去掉'

events{}里面加上 use epoll;'使用epoll模型 'worker_connections  4096; '进程处理'

http{
#log_format  main '$remote_addr - $remote_user [$time_local] "$request" '   '#去掉'
#'$status $body_bytes_sent "$http_referer" ' ' #去掉'
#'"$http_user_agent" "$http_x_forwarded_for"'; '#去掉'
}

server{
'#去掉' charset  utf-8;
'#去掉' access_log  logs/aa.com.access.log  main;

}'在后面加入'

location ~ /status {  '配置统计功能'
 stub_status on;
 access_log off;
 }

报错

nginx -t' 报这错'
nginx: [warn] 4096 worker_connections exceed open file resource limit: 1024
'解决方法'
ulimit -n
1024
ulimit -n 65535 >> /etc/rc.local 也可以 ulimit -n 65535
ulimit -n
65535

在这里插入图片描述
配置统计功能效果在这里插入图片描述
配置文件nginx.conf 更改了access_log日志 默认的access.log就没有内容了在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值