部署Nginx服务

 

IP 主机名 节点
192.168.233.17 nginx Nginx节点

 

 

一 修改主机名

使用远程连接工具CRT连接到192.168.233.17虚拟机,并进行修改主机名的操作,将192.168.233.17主机名修改为nginx

hostnamectl set-hostname nginx

hostnamectl

 

 二 关闭防火墙及SELinux服务

 setenforce 0

 systemctl stop firewalld

三 安装配置基础服务

使用CentOS-7-x86_64-DVD-1511.iso文件自行配置本地YUM源,编译安装基础环境

mkdir -p /opt/centos

mount /dev/sr0 /opt/centos

yum install gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel -y

 

 

创建指定用户,这个nginx用户要和PHP服务器上创建的nginx两者id一致,这里先创建用户

groupadd -g 1001 nginx 

useradd -u 900 nginx -g nginx -s /sbin/nologin  

 tail -1 /etc/passwd 

 

 四 安装配置Nginx服务

使用远程传输工具,将提供的nginx-1.12.2.tar.gz压缩包上传至nginx节点的/usr/local/src/目录下,并解压到当前目录

tar -zxvf nginx-1.12.2.tar.gz

进入nginx-1.12.2目录,编译并安装

[root@nginx src]# cd nginx-1.12.2/
[root@nginx-1.12.2]#./configure --prefix=/usr/local/nginx --with-http_dav_module \
--with-http_stub_status_module --with-http_addition_module \
--with-http_sub_module --with-http_flv_module --with-http_mp4_module \
--with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx

如果没有报错提示,请进行下一步安装

make && make install

编译安装完毕后,创建软连接并启动测试,命令如下:(netstat命令无法使用时,请自行使用YUM源安装net-tools工具)

[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  
[root@nginx nginx-1.12.2]# 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@nginx nginx-1.12.2]# nginx
[root@nginx nginx-1.12.2]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5726/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1400/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2274/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1400/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2274/master        

如果发现80端口启动,则表示Nginx服务启动成功。可以在浏览器访问地址192.168.233.17来查看是否出现Nginx的欢迎页面

 

 

posted @ 2021-12-06 15:15  年年哎  阅读(243)  评论(0)    收藏  举报