[root@master-node ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base extras nginx-stable updates Cleaning up list of fastest mirrors Other repos take up 609 k of disk space (use --verbose for details) [root@master-node ~]# yum makecache
[root@master-node ~]# nginx -v nginx version: nginx/1.20.2 [root@master-node ~]# rpm -qi nginx Name : nginx Epoch : 1 Version : 1.20.2 ········· nginx [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server.
启动nginx
启动nginx 和 开机自启
1 2 3
[root@master-node ~]# systemctl start nginx [root@master-node ~]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
# 检测nginx配置是否正确 [root@master-node ~]# nginx -t nginx: the configuration file /etc/nginx/conf/nginx.conf syntax is ok nginx: configuration file /etc/nginx/conf/nginx.conf test is successful
#!/bin/bash ck_ok() { if [ $? -ne 0 ] then echo"$1 error." exit 1 fi }
download_ng() { cd /usr/local/src if [ -f nginx-1.23.0.tar.gz ] then echo"当前目录已经存在nginx-1.23.0.tar.gz" echo"检测md5" ng_md5=`md5sum nginx-1.23.0.tar.gz|awk '{print $1}'` if [ ${ng_md5} == 'e8768e388f26fb3d56a3c88055345219' ] then return 0 else sudo /bin/mv nginx-1.23.0.tar.gz nginx-1.23.0.tar.gz.old fi fi
sudo curl -O http://nginx.org/download/nginx-1.23.0.tar.gz ck_ok "下载Nginx" } install_ng() { cd /usr/local/src echo"解压Nginx" sudo tar zxf nginx-1.23.0.tar.gz ck_ok "解压Nginx" cd nginx-1.23.0
echo"安装依赖" ifwhich yum >/dev/null 2>&1 then ## RHEL/Rocky for pkg in gcc make pcre-devel zlib-devel openssl-devel do if ! rpm -q $pkg >/dev/null 2>&1 then sudo yum install -y $pkg ck_ok "yum 安装$pkg" else echo"$pkg已经安装" fi done fi
ifwhich apt >/dev/null 2>&1 then ##ubuntu for pkg in make libpcre++-dev libssl-dev zlib1g-dev do if ! dpkg -l $pkg >/dev/null 2>&1 then sudo apt install -y $pkg ck_ok "apt 安装$pkg" else echo"$pkg已经安装" fi done fi