部署nginx服务

规划节点

IP主机名节点
192.168.200.50nginxNginx节点

基础准备
使用本地PC环境的VMWare Workstation软件进行实操练习,镜像使用提供的CentOS-7-x86_64-DVD-1511.iso。虚拟机配置为1核/2G内存/20G硬盘。

基础环境安装

修改主机名
使用远程连接工具xshell连接到192.168.200.50虚拟机,并进行修改主机名的操作,将192.168.200.50主机名修改为nginx。命令如下:

# hostnamectl set-hostname nginx

关闭防火墙及SELinux服务

# setenforce 0
# systemctl stop firewalld

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

# mv /etc/yum.repos.d/* /media/
# cd /opt/
# mkdir centos
# cd
# mount /dev/cdrom /opt/centos/
mount: /dev/sr0 is write-protected, mounting read-only
# cat /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
# yum install -y gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel

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

[root@nginx ~]# groupadd -g 1001 nginx  
[root@nginx ~]#useradd -u 900 nginx -g nginx -s /sbin/nologin  
[root@nginx ~]# tail -1 /etc/passwd  
nginx:x:900:1001::/home/nginx:/sbin/nologin  

安装配置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 ~]# cd nginx-1.12.2/
[root@nginx 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.200.50来查看是否出现Nginx的欢迎页面。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值