安装docker
#!/usr/bin/bash
set -e
unset c
color(){
declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34)
#echo -e "\033[${c[$1]}m[`date +%T`]($1) $2\033[0m"
printf "\033[${c[$1]}m%-10s%-10s %-30s\033[0m\n" "[`date +%T`]" "($1)" "$2"
sleep 0.5
}
install(){
color Info "开始安装docker服务"
yum install -y yum-utils device-mapper-persistent-data lvm2 git && \
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && \
yum install -y docker-ce
mkdir -p /etc/docker
color Success "安装完成"
color Info "开始配置镜像加速器"
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://pilvpemn.mirror.aliyuncs.com"]
}
EOF
cat >> /etc/sysctl.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
EOF
systemctl daemon-reload && \
systemctl enable docker --now
}
install
color Success "配置完成"
安装mysql
#!/bin/bash
# by newrain
# time 2019-11-28
# lv 2.0
level=5.7
password="QianFeng@123"
remote_user="remote"
remote_passwd="QianFeng@123"
unset c
color(){
declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34)
#echo -e "\033[${c[$1]}m[`date +%T`]($1) $2\033[0m"
printf "\033[${c[$1]}m%-10s%-10s %-30s\033[0m\n" "[`date +%T`]" "($1)" "$2"
sleep 0.5
}
color Info "此脚本用于yum 安装mysql"
color Warning "此脚本将删除所有mysql数据,如需备份请ctrl+c终止脚本,程序将在3秒后执行"
sleep 3
if [[ $UID -ne 0 ]];then
color Warning "使用root 执行此脚本"
exit 1
fi
color Warning "清理环境"
systemctl stop mysqld mariadb &>/dev/null
yum erase -y `rpm -qa |grep mariadb` 2>/dev/null
yum erase -y `rpm -qa |grep mysql` 2>/dev/null
rm -rvf /etc/my.cnf /var/lib/mysql /var/log/mysql*
userdel -rf mysql &>/dev/null
ping -c1 -w1 www.baidu.com &>/dev/null
if [[ $? -eq 0 ]];then
if [ ! -f /tmp/.init ];then
yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
fi
else
color Error "网络错误"
exit 22
fi
yum -y install mysql-community-server mysql-community-devel --disablerepo mysql80-community --enablerepo mysql57-community --nogpgcheck
systemctl start mysqld
color Warning "启动成功,初始密码如下(mysql5.7前版本没有初始密码)"
passwd=$(grep -o 'root@localhost.*' /var/log/mysqld.log | awk 'END{print $NF}')
mysqladmin -uroot -p$passwd password $password && \
mysql -uroot -p$password -e "grant all on *.* to \"$remote_user\"@'%' identified by \"$remote_passwd\"; flush privileges;"
color Success "安装完成 初始密码为$password"
安装python3.10
#!/usr/bin/bash
path=/opt/py3104
unset c
color(){
declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34)
#echo -e "\033[${c[$1]}m[`date +%T`]($1) $2\033[0m"
printf "\033[${c[$1]}m%-10s%-10s %-30s\033[0m\n" "[`date +%T`]" "($1)" "$2"
sleep 0.5
}
mkdir -pv $path
cd $path && \
yum -y install gcc gcc-c++ zlib-devel bzip2-devel sqlite-devel readline-devel libffi-devel && \
color Info "openssl 包下载,请稍等..." && \
wget http://download.beyourself.org.cn/package/openssl-1.1.1n.tar.gz && \
tar xf openssl-1.1.1n.tar.gz && \
cd openssl-1.1.1n && \
./config --prefix=/usr/local/openssl && \
make -j $(cat /proc/cpuinfo | grep processor |wc -l) && make install && cd .. && \
wget http://download.beyourself.org.cn/package/Python-3.10.4.tar.xz && \
tar xf Python-3.10.4.tar.xz && \
cd Python-3.10.4 && \
./configure --enable-shared --prefix=/usr/local/python3.10.4 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto && \
make -j $(cat /proc/cpuinfo | grep processor |wc -l) && \
make install && \
echo "/usr/local/python3.10.4/lib" >> /etc/ld.so.conf && \
ldconfig && \
echo "export PATH=/usr/local/python3.10.4/bin:\$PATH" >> /etc/profile && \
color Success "python安装完成"
color Info "配置pip加速"
mkdir ~/.pip &>/dev/null
tee ~/.pip/pip.conf <<EOF
[global]
index_url=https://mirrors.aliyun.com/pypi/simple
timeout=6000
EOF
color Success "配置完成"
安装mysql[编译]
#!/usr/bin/bash
source ./color.sh
source ./checkos.sh
source ./init.sh
# 数据库安装目录
install_dir=/usr/local/mysql
# 数据存放目录
data_dir=${install_dir}/data
# 配置文件存放目录
config_dir=/etc
# 解压目录名称
source_dir=mysql-5.7.27
# 默认端口
port=3306
# 源码包名称
packagename="mysql-boost-5.7.27.tar.gz"
# 编译线程数
cpus=`grep "processor" /proc/cpuinfo | wc -l`
checkEnv(){
[ -d /var/lib/mysql ] && color yellow "检测到本机可能使用yum安装了mysql,可能会造成冲突,请问是否继续安装[Y|N]"
read result
if [ "$result" = 'Y' ];then
color green "安装继续"
else
color green "退出脚本"
exit 1
fi
[ -d /usr/local/mysql ] && color red "检测到${install_dir}已存在,请手动处理" && exit 1 || \
color green "环境检测完成"
}
installPackage(){
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make glibc automake autoconf cmake && \
color green "依赖包安装完成" || \
color red "依赖包安装异常,请修复yum源[需要官方yum以及epelyum]"
color green "开始准备源码包"
sed -n -e '1,/^exit 0$/!p' $0 > ./$packagename
tar xvf $packagename && \
color green "源码包准备完成" && \
cd $source_dir/
cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=$install_dir \
-DSYSCONFDIR=$config_dir \
-DMYSQL_DATADIR=$data_dir \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=$port \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 && \
make -j $cpus && make install && \
color green "编译安装完成"
}
down(){
cat >> /etc/profile.d/source_mysql.sh <<\EOF
PATH=/usr/local/mysql/bin:$PATH
export PATH
EOF
password=$(${install_dir}/bin/mysqld --initialize --user=mysql --basedir=$install_dir --datadir=$data_dir 2>&1 | grep "A temporary password" | awk '{print $NF}')
if [ -n "$password" ];then
color green "初始化完成,初始密码为$password"
color green "通过mysqladmin -p$password password '新密码'进行修改密码"
color green "启动数据库 mysqld_safe &\nmysql 安装完成"
else
color red "初始化异常,请手动检查"
fi
read -p '是否需要清理安装环境[Y|N]: ' ask
if [ "$ask" = 'Y' ];then
rm -rvf $source_dir
rm -rvf $packagename
color green "清理完成"
else
color green "脚本退出"
fi
}
main(){
checkEnv
installPackage
down
}
main
exit 0