🦄 个人主页——🎐个人主页 🎐✨🍁
🪁🍁🪁🍁🪁🍁🪁🍁 感谢点赞和关注 ,每天进步一点点!加油!🪁🍁🪁🍁🪁🍁🪁🍁
目录
一、安装下载
二、执行安装
一、安装下载
下载地址:
https://dev.MySQL.***/get/Downloads/MySQL-5.7/mysql-5.7.44-el7-x86_64.tar.gz
脚本和tar包结构
my.***f 配置文件
[root@windp-aio opt]# cat config/my.***f
[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8
[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port
port = 3306
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
[mysql.server]
user=mysql
basedir=/usr/local/mysql
二、执行安装
install_mysql.sh 安装脚本
#! /bin/bash
#
# Author: kangll
# CreateTime: 2023-11-10
# Desc: install mysql5.7.44
#
echo "******** INSTALL MYSQL *********"
BASEDIR=$(cd "$(dirname "$0")"; pwd)
# 卸载原有的mariadb
OLD_MYSQL=`rpm -qa|grep mariadb`
profile=/etc/profile
for mariadb in $OLD_MYSQL
do
rpm -e --nodeps $mariadb
done
# 删除原有的my.***f
rm -rf /etc/my.***f
#添加用户组 用户
groupadd mysql
useradd -g mysql mysql
#解压mysql包并修改名称
tar -zxvf $BASEDIR/mysql-5.7.44-el7-x86_64.tar.gz -C /usr/local
mv /usr/local/mysql-5.7.44-el7-x86_64 /usr/local/mysql
#更改所属的组和用户
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql/log
chown -R mysql:mysql /usr/local/mysql/data
#粘贴配置文件my.***f 内容见八 中的 my.***f
cp $BASEDIR/config/my.***f /usr/local/mysql/
# 安装mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
# 设置文件及目录权限:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chown 777 /usr/local/mysql/my.***f
chmod +x /etc/init.d/mysqld
mkdir /var/lib/mysql
chmod 777 /var/lib/mysql
# 启动mysql
/etc/init.d/mysqld start
# 设置开机启动
chkconfig --level 35 mysqld on
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
# 修改环境变量
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /var/lib/mysql/mysql.sock /tmp/
cat > /etc/profile.d/mysql.sh<<EOF
export PATH=$PATH:/usr/local/mysql/bin
EOF
mysqlPw=`sed -n 2p /root/.mysql_secret`
mysqlPwTMP=`sed -n 2p /root/.mysql_secret`1
mysqlNewPw=Winner001
hostname=`"hostname"`
#ssh $hostname "source /etc/profile;java -version"
ssh $hostname "source /etc/profile;mysqladmin -h127.0.0.1 -uroot -p'$mysqlPw' password '$mysqlPwTMP';mysqladmin -h127.0.0.1 -uroot -p'$mysqlPwTMP' password '$mysqlNewPw';exit"
echo "******** MYSQL installation ***pleted *******
执行完脚本 成功登录
ssh 操作需要免密 附上 本机免密脚本 ssh_keygen.sh
#! /bin/bash
#
#Author: kangll
#CreateTime: 2023-11-10
#Desc: 本机免密
#
set -x
# get ip
ip=$(ip addr show | grep -E 'i*** [0-9]' | awk '{print $2}' | awk -F '/' '{print $1}' | sed -n '$p')
ssh_hosts=${ip}
ssh_***workname=(windp-aio)
ssh_passwd=winner@001
# 定义修改/etc/hosts文件的方法
#echo "开始修改地址映射"
#for ((i=0;i<${#ssh_hosts[*]};i++));do
# sed -i '/^'"${ssh_hosts[$i]}"'/d' /etc/hosts
# echo "尝试连接: ${ssh_***workname[$i]}"
# timeout 5 ssh root@${ssh_***workname[$i]} "echo ${ssh_***workname[$i]}: 'This is su***ess!'"
# if [[ $? -ne 0 ]];then
# echo "添加地址映射:${ssh_hosts[$i]} ${ssh_***workname[$i]}"
# echo "${ssh_hosts[$i]} ${ssh_***workname[$i]}" >> /etc/hosts
# fi
#done
expect -v
if [ `echo $?` -ne 0 ];then
echo "安装expect命令"
yum install -y expect
fi
################################
#
################################
create_ssh_pub(){
echo "生成本地ssh公钥"
/usr/bin/expect << eof
# 设置捕获字符串后,期待回复的超时时间
set timeout 30
spawn ssh-keygen -t rsa -b 1024
## 开始进连续捕获
expect {
".ssh/id_rsa)" { send "\n"; exp_continue }
"Overwrite (y/n)?" { send "y\n"; exp_continue }
"no passphrase):" { send "\n"; exp_continue }
"passphrase again:" { send "\n"; exp_continue }
}
eof
}
if [ ! -f /root/.ssh/id_rsa.pub ];then
create_ssh_pub
fi
#################################
# 定义复制ssh公钥方法
#################################
config_copy_ssh(){
echo "复制公钥到对应的主机上"
/usr/bin/expect << eof
# 设置捕获字符串后,期待回复的超时时间
set timeout 30
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $1@$2
## 开始进连续捕获
expect {
"connecting (yes/no)?" { send "yes\n"; exp_continue }
"s password:" { send "${ssh_passwd}\n"; exp_continue }
}
eof
}
for name in ${ssh_***workname[*]};do
timeout 5 ssh root@${name} "echo ${name}: 'This is su***ess!'"
if [[ $? -ne 0 ]];then
echo "复制文件到: ${name}"
config_copy_ssh root ${name} > /dev/null
fi
done
参考链接:ansible 实现自动化部署ambari(纯离线)_ansible ambari-CSDN博客