点击蓝色“DevOps架构实战”关注我哟
分享到“朋友圈”,每天上午 08:06,干货推送!
一、部署mysql
[root@k8s-node1 ~]#moremysql_install.sh
#!/usr/bin/bash
#1.检查是否存在mysql对应的软件包
rpm_install_mysql(){
rpm_check_mysql=$(rpm -qa|grep mysql-community-server|wc -l)
rpm_check_mysql_version=$(rpm -qa|grep mysql-community-server)
if [ $rpm_check_mysql -eq 0 ];then
cat >/etc/yum.repos.d/mysql.repo<
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF
yum clean all && yum makecache
yum install -y mysql-community-server
else
echo "${rpm_check_mysql_version%-*} Installed Ok"
fi
}
#2.初始化MySQL数据库
clear_mysql(){
systemctl start mysqld
if [ $? -eq 0 ];then
Mysql_old_pass=$(grep "temporary password" var/log/mysqld.log |tail -n1|awk -F '[ :]' '{print $NF}')
mysqladmin -uroot -p"$Mysql_old_pass" password "hahashen.com"
fi
}
rpm_install_mysql
clear_mysql
----------------------------------------------------------------
二、创建用户和密码
[root@k8s-node1 ~]# more user_passwd.sh
#!/usr/bin/bash
if [ $UID -ne 0 ];then
echo "请使用root账户执行创建用户"
exit 1
fi
for i in $(seq -w 00 10)
do
username=user_$i
pass=$(mkpasswd -l 10 -C 3 -c 3 -d 2 -s 2)
id $username &>/dev/null
if [ $? -eq 1 ];then
useradd $username && \
echo "$pass"|passwd --stdin $username &>/dev/null
id $username &>/dev/null
if [ $? -eq 0 ];then
echo "Useradd $username is OK"
else
echo "Useradd $username is Err"
fi
else
echo "Useradd $username is already exists"
fi
echo -e "$username \t $pass" >> tmp/user.txt
done
----------------------end---------------------
推荐阅读: