Centos7编译安装mysql脚本-创新互联
#!/bin/bash
# mysqld install scripts
# display Progress
Progress () {
b=''
i=0
while [ $i -le 100 ]
do
printf "$*:[ %-50s ]%d%%\r" $b $i
sleep 0.001
i=`expr 2 + $i`
b=#$b
done
echo
}
# if Centos Version
Centos_version=$(cat /etc/redhat-release|awk '{print $4}'|cut -b1)
wget -o /dev/null -O /etc/yum.repos.d/Centos-Base.repo /http://mirrors.aliyun.com/repo/Centos-${Centos_version}.repo
yum makecache
Progress Centos Download
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config;iptables -F
setenforce 0
rpm -e --nodeps mysql*
CPU_NUMBERS=`cat /proc/cpuinfo|grep processor|wc -l`
COMPUTER_MEM=`free -m|grep Mem|awk '{print $2}'`
MYSQL_MEM=`expr $COMPUTER_MEM - $COMPUTER_MEM / 4`
COLOR_GREEN="\033[32m"
COLOR_RED="\033[31m"
COLOR_BULE="\033[34m"
COLOR_YELLOW="\033[33m"
COLOR_PURPLE="\033[35m"
COLOR_END="\033[0m"
sleep 0.05;echo "==================================================";echo;echo
sleep 0.05;echo -e "Mysql 5.7.16 on $COLOR_GREEN Centos7_`uname -m` $COLOR_END"
sleep 0.05;echo -e "Your computer is $COLOR_GREEN $CPU_NUMBERS $COLOR_END processes,Mysql Memory is ${COLOR_GREEN}${MYSQL_MEM}M${COLOR_END}"
sleep 0.05;echo -e "${COLOR_RED}Your will input mysql's root password and mysql's memory${COLOR_END}";echo;echo
sleep 0.05;echo "=================================================="
# are you sure install
read -n1 -t30 -p "Are you sure setup[y/n]?: " answer
case $answer in
"y" | "Y" )
echo;echo "Start setup.....";sleep 2;;
"n" | "N" )
echo;echo -e "${COLOR_RED}Cancel setup......${COLOR_END}"
exit 0 ;;
"")
echo;echo -e "${COLOR_PURPLE}Over time!!!!!${COLOR_END}"
exit 0 ;;
*)
echo;echo -e "${COLOR_RED}Error input parameter......${COLOR_END}"
exit 1 ;;
esac
# check if user is root
if [ $(id -u) != "0" ];then
echo "$COLOR_RED Sorry:You must be root to run this script!${COLOR_END}"
exit 1
fi
# useradd mysql
GROUP_NAME=mysql
USER_NAME=mysql
if [ -z $(cat /etc/passwd|awk -F: "{print $1}"|grep -w "$USER_NAME") -a -z $(cat /etc/group|awk -F: "{print $1}"|grep -w "$GROUP_NAME") ]
then
useradd -s /sbin/nologin -M -U $USER_NAME 2> /dev/null
if (( $? == "0" ))
then
echo -e "$COLOR_GREEN group $GROUP_NAME add sucessfully!${COLOR_END}"
fi
else
echo -e "${COLOR_PURPLE}User $USER_NAME is exsits! ${COLOR_END}"
fi
for i in make gcc gcc-c++ bison-devel ncurses-devel perl perl-devel wget
do
yum -y -q install $i > /dev/null
echo -e "${COLOR_PURPLE}$i ${COLOR_GREEN}Install ok${COLOR_END}"
done
# download cmake >= 2.8
CMAKE_VERSION=cmake-3.4.3
rm -rf /tmp/cmake*
if [ -z $(which cmake) ]
then
wget -c --no-check-certificate -q https://cmake.org/files/v3.4/${CMAKE_VERSION}.tar.gz -P /tmp
if [ $? == "0" ]
then
Progress Cmake Download
echo -e "${COLOR_GREEN}Cmake Download sucessfully!${COLOR_END}"
else
echo -e "${COLOR_RED}Cmake Download failed!${COLOR_END}"
exit 0
fi
tar -zxf /tmp/${CMAKE_VERSION}.tar.gz -C /tmp/ > /dev/null
cd /tmp/${CMAKE_VERSION}
./bootstrap > /dev/null
make && make install
echo $?
else
echo -e "${COLOR_PURPLE}Cmake is exsits ${COLOR_END}"
fi
# download boost_1.61
BOOST_VERSION=1.61.0
BOOST_VER="boost_1_61_0"
for i in bzip2 gcc bzip2-devel bzip2-libs python-devel perl-Data-Dumper
do
yum install -q -y $i > /dev/null
echo -e "${COLOR_PURPLE}$i ${COLOR_GREEN}install OK${COLOR_END}"
done
wget -c --no-check-certificate -q https://nchc.dl.sourceforge.net/project/boost/boost/${BOOST_VERSION}/${BOOST_VER}.tar.bz2 -P /tmp
if [ $? == "0" ]
then
Progress Boost Download
echo -e "${COLOR_GREEN}Boost Download sucessfully!${COLOR_END}"
echo -e "${COLOR_GREEN}Decompression ${BOOST_VER}.tar.bz2${COLOR_END}"
cd /tmp;tar -jxf ${BOOST_VER}.tar.bz2
cd ${BOOST_VER}
echo `pwd`
./bootstrap.sh 2> /dev/null
./b2 install 2> /dev/null
else
echo -e "${COLOR_RED}Boost Download failed!${COLOR_END}"
exit 0
fi
# Download mysql
rm -rf /tmp/mysql-5.*
MYSQL_VERSION=5.6.35
wget -c http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-${MYSQL_VERSION}.tar.gz -P /tmp
if [ $? == "0" ]
then
echo -e "${COLOR_PURPLE}Mysql ${MYSQL_VERSION}${COLOR_GRENN}Download sucessfully!${COLOR_END}"
else
echo -e "${COLOR_PURPLE}Mysql ${MYSQL_VERSION}${COLOR_RED}Download failed!${COLOR_END}"
fi
cd /tmp/
tar -zxf /tmp/mysql-${MYSQL_VERSION}.tar.gz
cd mysql-${MYSQL_VERSION}
if [ -f /etc/my.cnf ]
then
mv /etc/my.cnf /etc/my.cnf__$(date +%Y%m%d).bak
fi
echo "======================================================"
echo -e "Please input the root password of mysql: "
read -p "(Default password:root):" MYSQL_PASSWD
if [ $mysqlrootpw == "" ];then
MYSQL_PASSWD="root"
fi
echo "Mysql root's password is ${mysqlrootpw}"
echo -e "${COLOR_PURPLE}Please input Mysql Basedir: ${COLOR_END}"
read -p "(Default Mysql Basedir:/usr/local/mysql/)" MYSQL_HOME
if [ -z $MYSQL_HOME ];then
MYSQL_HOME="/usr/local/mysql"
fi
read -p "(Default Mysql Datadir:/usr/local/mysql/data)" MYSQLDB_HOME
if [ -z $MYSQLDB_HOME ];then
MYSQLDB_HOME="/usr/local/mysql/data"
fi
echo "======================================================="
cmake \
-DCMAKE_INSTALL_PREFIX=${MYSQL_HOME}-${MYSQL_VERSION} \
-DMYSQL_DATADIR=${MYSQLDB_HOME} \
-DSYSCONFDIR=/etc \
-DWITH_BOOST=/usr/local/include/boost \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_COLLATION=utf8_general_ci
make -j${CPU_NUMBERS} && make install
ln -s ${MYSQL_HOME}-${MYSQL_VERSION} ${MYSQL_HOME}
cp ${MYSQL_HOME}/support-files/my-default.cnf /etc/my.cnf
mkdir -p ${MYSQLDB_HOME}/log
chown -R mysql:mysql ${MYSQL_HOME}
chown -R mysql:mysql ${MYSQLDB_HOME}
cd ${MYSQL_HOME};chmod +x ./scripts/mysql_install_db
${MYSQL_HOME}/scripts/mysql_install_db --user=mysql --basedir=${MYSQL_HOME} --datadir=${MYSQLDB_HOME}
cat >> /etc/profile <
创新互联公司主营饶河网站建设的网络公司,主营网站建设方案,重庆APP开发公司,饶河h5小程序定制开发搭建,饶河网站营销推广欢迎饶河等地区企业咨询另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站名称:Centos7编译安装mysql脚本-创新互联
当前路径:http://dzwzjz.com/article/cdoips.html