shell练习-nginx安装卸载

文章目录

安装nginx

#!/bin/bash
# date 2021.10.27
# install nginx
[ $(id -u) != "0" ]&& echo "error,not root user" && exit 1
# 配置yum的软件仓库
echo "-------------配置yum的软件仓库-------------"
sudo yum install epel-release

# 安装nginx
echo "-------------安装nginx-------------"
sudo yum install -y nginx

# 开启nginx
echo "-------------开启nginx-------------"
sudo systemctl start nginx

# 开机启动
echo "-------------配置开机启动-------------"
sudo systemctl enable nginx

# 查看状态
echo "-------------查看nginx服务状态-------------"
sudo systemctl status nginx

卸载nginx

#!/bin/bash
# date 2021.10.27
# remove nginx
# 停止nginx服务
echo "==============停止nginx服务=============="
sudo systemctl start nginx

# 删除nginx自启动
echo "==============删除nginx自启动配置=============="
chkconfig nginx off

# 删除nginx配置
echo "==============删除nginx配置文件=============="
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx

# 删除nginx
echo "==============remove nginx=============="
yum remove -y nginx

# 判断是否移除
EXISTS_RPMS=`rpm -qa | grep -i nginx`
if [[ $EXISTS_RPMS = "" ]] 
then 
  	echo "==============nginx卸载完成=============="
else 
    for RPM in ${EXISTS_RPMS}
    do
            rpm -e --nodeps ${RPM}
    done

 fi

おすすめ

転載: blog.csdn.net/qq_25672165/article/details/120997008