centos7安装nginx自动启动

安装nginx

一.安装依赖包

每次安装软件都必须,默认会少几个包,必须安装

yum install autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc

二.安装nginx

1去nginx官网下载安装包然后解压

2./configure --prefix=/usr/local/nginx(安装路径)

3. make & make install

  4.将配好的配置文件覆盖到conf内

配置文件设置:

client_max_body_size 10m;    #允许客户端请求的最大单文件字节数

        client_body_buffer_size 128k;  #缓冲区代理缓冲用户端请求的最大字节数,

proxy_buffer_size 4k;             #设置代理服务器(nginx)保存用户头信息的缓冲区大小

proxy_buffers 4 32k;               #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置

        proxy_busy_buffers_size 64k;    #高负荷下缓冲大小(proxy_buffers*2)

proxy_temp_file_write_size 64k;  #设定缓存文件夹大小,大于这个值,将从upstream服务器传

         安装Nginx时报错解决

./configure:  error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题

yum -y install pcre-devel

错误提示:./configure: error: the HTTP cache module requires md5 functions

from OpenSSL library.   You can either disable the module by using

--without-http-cache option, or install the OpenSSL library into the system,

or build the OpenSSL library statically from the source with nginx by using

--with-http_ssl_module --with-openssl=<path> options.

解决办法:

yum  -y install openssl openssl-devel

yum -y install pcre-devel openssl openssl-devel

./configure --prefix=/usr/local/nginx

make

make install

三.环境支持

         firewall-cmd --permanent --add-port=27017/tcp(永久性设置防火墙加入参数,红色为端口号   就是允许其他计算机telnet此端口,此命令重启有效)

         firewall-cmd --add-port=27017/tcp(临时设置防火墙,即可生效)

设置自启动

1、方法一,编辑rc.loacl脚本

Ubuntu开机之后会执行/etc/rc.local文件中的脚本,

所以我们可以直接在/etc/rc.local中添加启动脚本。

当然要添加到语句:exit 0 前面才行。

如:

复制代码

代码如下:

sudo vi /etc/rc.local

然后在 exit 0 前面添加好脚本代码。

方法二,在/etc/rc5.d/下建立软连接

 先在/etc/init.d/下建立nginx 内容如下:

#!/bin/bash

/usr/local/nginx/sbin/nginx

然后进入:/etc/rc5.d/

创建:软连接 ln -s ../init.d/nginx S06nginx

完成

最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/etc/rc.local文件内容的就发现了问题的原因了

#!/bin/bash

# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES

#

# It is highly advisable to create own systemd services or udev rules

# to run scripts during boot instead of using this file.

#

# In constrast to previous versions due to parallel execution during boot

# this script will NOT be run after all other services.

#

# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure

# that this script will be executed during boot.

翻译:

#这个文件是为了兼容性的问题而添加的。

#

#强烈建议创建自己的systemd服务或udev规则来在开机时运行脚本而不是使用这个文件。

#

#与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。

#

#请记住,你必须执行“chmod +x /etc/rc.d/rc.local”来确保确保这个脚本在引导时执行。

于是我有确认了下/etc/rc.local的权限

[root@localhost ~]# ll /etc/rc.local

lrwxrwxrwx. 1 root root 13 8月  12 06:09 /etc/rc.local -> rc.d/rc.local

[root@localhost ~]# ll /etc/rc.d/rc.local

-rw-r--r--. 1 root root 477 6月  10 13:35 /etc/rc.d/rc.local

/etc/rc.d/rc.local没有执行权限,于是按说明的内容执行

 

chmod +x /etc/rc.d/rc.local

重启后发现/etc/rc.local能够执行了。

看样子是版本的变迁,/etc/rc.local /etc/rc.d/rc.local正在弃用的路上。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值