分享一个使用的shell脚本

CentOS7最小化安装后的一些常用的工具初始化安装脚本

#!/bin/bash
yum update -y			#进行系统更新
if [ $? = 0 ];then
	echo "yum update succes!!!"
fi
yum install lrzsz -y		#文件传输的工具
if [ $? = 0 ];then
	echo "lrzsz install succes"
fi
yum install wget -y		#wget安装
if [ $? = 0 ];then
	echo "wget install succes"
fi
yum install vim -y		#vim编辑工具
if [ $? = 0 ];then
	echo "vim install succes"
fi
yum install net-tools -y		#net-tools网络工具
if [ $? = 0 ];then
	echo "net-tools install succes"
fi
yum install -y		#git工具
if [ $? = 0 ];then
	echo "net-tools install succes"
fi

MariaDB10.3 数据库安装脚本

#!/bin/bash
R_mariadb='rpm -qa | grep MariaDB'
echo "command(rpm -qa) results are: $R_mariadb"
if [[ $R_mariadb =~ " " ]]
then
    echo "MariaDB is not insatall "
else
    rpm -e --nodeps MariaDB-*
    if [ $? = 0 ]; then
        echo "old mariadb is remove"
    fi
fi

R_mysql='rpm -qa | grep mysql'
echo "command(rpm -qa) results are: $R_mysql"
if [[ $R_mysql =~ " " ]]
then
    echo "MySQL is not insatall "
else
    yum remove mysql mysql-server mysql-libs compat-mysql51
    if [ $? = 0 ]; then
        echo "Remove MySQL "
    fi
fi

function create_mariadbrepo(){
    V_repo1="[mariadb]"
    V_repo2="name = MariaDB"
    V_repo3="baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/"
    V_repo4="gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB"
    V_repo5="gpgcheck=1"
    
    echo $V_repo1 > /etc/yum.repos.d/MariaDB.repo
    echo $V_repo2 >> /etc/yum.repos.d/MariaDB.repo
    echo $V_repo3 >> /etc/yum.repos.d/MariaDB.repo
    echo $V_repo4 >> /etc/yum.repos.d/MariaDB.repo
    echo $V_repo5 >> /etc/yum.repos.d/MariaDB.repo 
}

create_mariadbrepo
if [ $? = 0 ];then 
  echo "MariaDB.repo 创建成功!"
fi

rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
if [ $? = 0 ];then
  echo "add RPM-GPG-KEY-MariaDB successful!"
fi

yum -y install MariaDB-server MariaDB-client
if [ $? = 0 ];then
  echo "MariaDB 安装成功!"
fi

systemctl start mariadb
if [ $? = 0 ];then
  echo "MariaDB 启动成功!"
fi
systemctl enable mariadb
if [ $? = 0 ];then
  echo "MariaDB 设置开机启动成功!"
fi

flag=true
while($flag)
do
    echo -n "是否初始化MariaDB数据库(y/n) -->"
    read var
    if [[ $var == 'y' || $var == 'n' ]];then
        var1=$var
        flag=false
    fi
done

if [[ $var1 == 'y' ]];then
    echo "初始化MariaDB数据库"
    mysql_secure_installation
else
    echo "安装结束,请手动初始化数据库"
    exit;
fi

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

编辑于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励