實驗環境:
操作系統: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.實戰經驗:
一.安裝源碼包之前,先對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/軟件名字