在虚拟机上安装CentOS7.4
去阿里云开源镜像站下载 我这下的是minimal版本的
设置完简体中文,安装位置确定一下,设置root密码
一开始很干净,连网卡IP地址也没有
修改网卡的IP (Linux一切皆文件)
ONBOOT指的是操作系统运行以后,要不要把网卡启动起来
重启网络服务,并ping一下 能成功平通
用Xshell链接一下 重新配置vi /etc/sysconfig/network-scripts/ifcfg-ens33 让他的IP地址从dhcp动态分配改为静态的
本人的nat模式下的网关为192.168.136.2
在重启一下网络服务 systemctl restart network
安装nginx
用xftp上传到/root目录下
[root@localhost ~]# tar zxvf nginx-1.21.6.tar.gz #解压缩
可以看到缺依赖 缺c语言编辑器
[root@localhost nginx-1.21.6]# yum install -y gcc
安装到指定的目录下
[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx
还是缺依赖
[root@localhost nginx-1.21.6]# yum install -y pcre pcre-devel
[root@localhost nginx-1.21.6]# yum install -y zlib zlib-devel
[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx 没有报错
[root@localhost nginx-1.21.6]# make
[root@localhost nginx-1.21.6]# make install
启动nginx
./nginx # 启动
./nginx -s stop #快速停止
./nginx -s quit #优雅关闭,在退出前完成已经接受的连接请求
./nginx -s reload #重新加载配置
关防火墙
[root@localhost sbin]# systemctl stop firewalld.service
安装成系统服务
创建服务脚本
[root@localhost sbin]# vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
[root@localhost sbin]# systemctl daemon-reload
为了避免和原来的脚本冲突,先停nginx,再开启
[root@localhost sbin]# ./nginx -s stop #停止服务
[root@localhost sbin]# systemctl start nginx #启动服务
[root@localhost sbin]# systemctl enable nginx.service #设置开机启动