实验环境:

操作系统:CentOS7

任务:源码包软件安装

1.安装依赖环境

#yum  install gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel libtool

2.Nginx.org官网下载Nginx-1.14.0.tar.gz包

[root@localhost local]# wget http://nginx.org/download/nginx-1.14.0.tar.gz

3.源码包解压

[root@localhost src]# tar -xzf nginx-1.14.0.tar.gz 

[root@localhost src]# cd nginx-1.14.0

4.sed命令修改Nginx版本信息为SKY9890

[root@localhost nginx-1.14.0]#sed -i -e 's/1.14.0//g' -e 's/nginx\//SKY9890/g' -e 's/"NGINX"/"SKY9890"/g' src/core/nginx.h

5.预编译

[root@localhost nginx-1.14.0]# useradd www

[root@localhost nginx-1.14.0]# ./configure \

 --user=www \

 --group=www \

 --prefix=/usr/local/nginx \

 --with-http_stub_status_module \

 --with-http_ssl_module

6.make编译

[root@localhost nginx-1.14.0]# make

7.安装

[root@localhost nginx-1.14.0]# make install

8.测试Nginx服务安装是否成功

[root@localhost /]# /usr/local/nginx/sbin/nginx  -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost /]# lsof -i:80

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   1335 root    6u  IPv4  22074      0t0  TCP *:http (LISTEN)

nginx   1336  www    6u  IPv4  22074      0t0  TCP *:http (LISTEN)

[root@localhost /]# ps -aux|grep nginx

root      1335  0.0  0.1  45924  1128 ?        Ss   08:58   0:00 nginx: master process /usr/local/nginx/sbin/nginx

www       1336  0.0  0.2  46372  2144 ?        S    08:58   0:00 nginx: worker process

root      1341  0.0  0.0 112720   984 pts/0    R+   09:00   0:00 grep --color=auto nginx

9.实战经验:Nginx源码包软件安装步骤_第1张图片

一.安装源码包之前,先对CentOS服务器初始化设置,否则会出现各种各样的问题。

案例:

1、防火墙配置

CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1)、关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

2)、安装iptables防火墙

yum install iptables-services #安装

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

/usr/libexec/iptables/iptables.init restart #重启防火墙

2.养成操作习惯

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/软件名字