sunkezai 发表于 2018-11-12 13:26:01

Nginx源码包软件安装步骤

  实验环境:
  操作系统:CentOS7
  任务:源码包软件安装
  1.安装依赖环境
  #yuminstall 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包
  # wget http://nginx.org/download/nginx-1.14.0.tar.gz
  3.源码包解压
  # tar -xzf nginx-1.14.0.tar.gz
  # cd nginx-1.14.0
  4.sed命令修改Nginx版本信息为SKY9890
  #sed -i -e 's/1.14.0//g' -e 's/nginx\//SKY9890/g' -e 's/"NGINX"/"SKY9890"/g' src/core/nginx.h
  5.预编译
  # useradd www
  # ./configure \
  --user=www \
  --group=www \
  --prefix=/usr/local/nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module
  6.make编译
  # make
  7.安装
  # make install
  8.测试Nginx服务安装是否成功
  # /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
  # lsof -i:80

  COMMANDPID USER   FD   TYPE DEVICE>  nginx   1335 root    6uIPv422074      0t0TCP *:http (LISTEN)
  nginx   1336www    6uIPv422074      0t0TCP *:http (LISTEN)
  # ps -aux|grep nginx
  root      13350.00.1459241128 ?      Ss   08:58   0:00 nginx: master process /usr/local/nginx/sbin/nginx
  www       13360.00.2463722144 ?      S    08:58   0:00 nginx: worker process
  root      13410.00.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
  :FORWARD ACCEPT
  :OUTPUT ACCEPT

  -A INPUT -m state --state>  -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/软件名字

页: [1]
查看完整版本: Nginx源码包软件安装步骤