示意图:
代码展示
[root@ localhost ~]# vim nginx.sh #!/bin/bash service iptables stop setenforce 0 netstat -ntlp |grep nginx if [ $? -eq 0 ];then echo "nginx安装完成" else echo "nginx 开始安装" yum -y install wget gcc gcc-c++ pcre-devel zlib-devel wget http://nginx.org/download/nginx-1.16.1.tar.gz tar -zxvf nginx-1.16.1.tar.gz cd /root/nginx-1.16.1 ./configure make make install /usr/local/nginx/sbin/nginx
代码详细解释
[root@ localhost ~]# vim nginx.sh #!/bin/bash //脚本开头 作用是指定当前脚本使用什么解释器来执行 service iptables stop //关闭防火墙 setenforce 0 // 关闭selinux netstat -ntlp |grep nginx // if [ $? -eq 0 ];then //if判断 ($? 上一条语句成功 返回值为0 ) (-eq 等于的意思) echo "nginx安装完成" else //不符合if条件的时候执行else 里面的语句 echo "nginx 开始安装" yum -y install wget gcc gcc-c++ pcre-devel zlib-devel //安装编译工具 和依赖 wget http://nginx.org/download/nginx-1.16.1.tar.gz // 拉取nginx包 tar -zxvf nginx-1.16.1.tar.gz // tar 解压nginx包 cd /root/nginx-1.16.1 //到nginx目录下 ./configure // 测试环境 make //编译 make install //安装 /usr/local/nginx/sbin/nginx //启动nginx fi
代码所用到的命令详细解释:
tar: https://www.cnblogs.com/gaiting/p/12158017.html
netstat https://www.cnblogs.com/gaiting/p/12246083.html