Devops实现之 nginx(一)

1.手动安装部署

1.0 检查软件安装的系统环境

[root@web01 ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

[root@web01 ~]# uname –r

3.10.0-693.2.2.el7.x86_64

安装nginx的依赖包(pcre-devel openssl-devel)

yum install -y pcre-devel openssl-devel ###安装依赖包

pcre:兼容perl语言正则表达式,perl compatible regular expressions

rewirte模块 参数信息(perl方式定义正则表达式)

openssl:ssh—openssh/openssl—https

总结:所有安装依赖软件,后面都要加上-devel

2.0 下载nginx软件

wget http://nginx.org/download/nginx-1.10.2.tar.gz

解压软件

tar xf nginx-1.10.2.tar.gz

创建管理用户 www

useradd -M -s /sbin/nologin www

3.0 nginx软件编译安装过程

1、配置软件,在软件的解压目录中

[root@web01 nginx-1.10.2]# ./configure --prefix=/application/nginx-1.10.2
–user=www --group=www --with-http_stub_status_module --with-http_ssl_module

编译参数说明:

官网查询地址

–prefix 表示指定软件安装到哪个目录中,指定目录不存在会自动创建

–user/–group nginx工作进程由哪个用户运行管理

–with-http_stub_status_module 启动nginx状态模块功能(用户访问nginx的网络信息)

–with-http_ssl_module 启动https功能模块

通过软件编译过程中的返回值是否正确,确认配置是否正确

[root@web01 nginx-1.10.2]# echo $?

0

2、编译软件

[root@web01 nginx-1.10.2]# make

3、编译安装

[root@web01 nginx-1.10.2]# make install

3.1.6 创建软连接

[root@web01 application]# ln -s /application/nginx-1.10.2/ /application/nginx

3.1.7 精简化nginx.conf 主配置文件内容

[root@web01 conf]# egrep -v “#|^$” nginx.conf.default >nginx.conf

3.1.8 启动程序

[root@web01 application]# /application/nginx/sbin/nginx

检查是否启动

[root@web01 application]# ps -ef |grep nginx

root 26548 1 0 20:13 ? 00:00:00 nginx: master process
/application/nginx/sbin/nginx

www 26549 26548 0 20:13 ? 00:00:00 nginx: worker process

root 26551 23431 3 20:13 pts/0 00:00:00 grep –color=auto nginx

检查端口信息

[root@web01 application]# netstat -lntup |grep 80

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26548/nginx

服务部署完成

nginx命令简化方法

echo ‘export PATH=/application/nginx/sbin:$PATH’ >>/etc/profile

source /etc/profile

which nginx

安装后的nginx 目录结构

[root@web01 nginx]# ll

total 36

drwxr-xr-x 2 root root 4096 Oct 21 19:34 conf #配置文件保存目录

drwxr-xr-x 2 root root 4096 Oct 21 19:34 html #站点目录

drwxr-xr-x 2 root root 4096 Oct 21 20:26 logs #nginx
服务相关日志文件保存目录(错误日志访问日志)

drwxr-xr-x 2 root root 4096 Oct 21 19:34 sbin #
服务命令目录(只有一个nginx文件)

2.nginx软件的编译安装常见错误说明

2.0.1 nginx软件安装过程中遇到的问题

软件依赖包未正确安装问题—PCRE依赖包没有安装

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

You can either disable the module by using –without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using –with-pcre= option.

解决方法:yum install pcre pcre-devel -y

软件依赖包未正确安装问题—OPENSSL依赖包没有安装

./configure: error: SSL modules require the OpenSSL library.

You can either do not enable the modules, or install the OpenSSL library

into the system, or build the OpenSSL library statically from the source

with nginx by using –with-openssl= option.

解决方法:yum install openssl openssl-devel -y

2.0.2 nginx软件启动过程中遇到的问题

nginx软件重复启动产生的错误信息

[root@web01 nginx-1.10.2]# /application/nginx/sbin/nginx

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

解决方法:

nginx软件已经启动无需反复启动,如果需要重新启动需要停止nginx进程或者用reload方式进行重启

2.0.3 启动 Nginx 时如下报错“nginx:[emerg]getpwnam(“nginx”〉failed”

解答这是因为没有对应的Nginx服务用户,执行useradd
nginx-s/sbin/no丨ogin-M创建 Nginx

用户即可。为了让读者理解问题,重现上述错误过程,命令如下:

[root@web01 tools]# pkill nginx

[root@web01 tools]# userdel nginx

[root@web01 tools]# /application/nginx/sbin/nginx

nginx: [emerg] getpwnam(Mnginx”) failed

[root@web01 tools]# useradd nginx -s /sbin/nologin -M

[root@web01 tools]# /application/nginx/sbin/nginx

2.0.4 编译安装pcre编译软件时,gcc不全导致报错(本文使用yum安装不存在此问题)。

报错信息如下:

[root@gjlin2 pcre-8.30]# make && make install

make all-am

make[l] : Entering directory 7home/gjlin/tools/pcre-8.30′

CXX pcrecpp.lo

libtool : compile : unrecognized option ‘-DHAVE_CONFIG_H’

libtool :

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值