您好,登錄后才能下訂單哦!
這篇文章主要講解了“mysql源碼安裝的腳本分享”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“mysql源碼安裝的腳本分享”吧!
代碼如下:
#!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHclear;SysName=""SysBit=""CpuNum=""RamTotal=""RamSwap=""FileMax=""MysqlVersion="Percona-Server-5.6.15-rel63.0"MysqlLine="http://www.percona.com/downloads/Percona-Server-5.6/LATEST/source"MysqlPath="/usr/local/mysql"MysqlDataPath="$MysqlPath/data"MysqlLogPath="/var/log/mysql"MysqlConfigPath="$MysqlPath/conf"MysqlPass="test123"SYSTEM_CHECK(){ [[ $(id -u) != '0' ]] && echo '[Error] Please use root to install PUPPET.' && exit; egrep -i "centos" /etc/issue && SysName='centos'; egrep -i "ubuntu" /etc/issue && SysName='ubuntu'; [[ "$SysName" == '' ]] && echo '[Error] Your system is not supported this script' && exit; SysBit='32' && [ `getconf WORD_BIT` == '32' ] && [ `getconf LONG_BIT` == '64' ] && SysBit='64'; CpuNum=`cat /proc/cpuinfo |grep 'processor'|wc -l`; RamTotal=`free -m | grep 'Mem' | awk '{print $2}'`; RamSwap=`free -m | grep 'Swap' | awk '{print $2}'`; FileMax=`cat /proc/sys/fs/file-max`}INSTALL_BASE_PACKAGES(){ SYSTEM_CHECK if [ "$SysName" == 'centos' ]; then echo '[yum-fastestmirror Installing] ************************************************** >>'; yum -y install yum-fastestmirror; cp /etc/yum.conf /etc/yum.conf.lnmp sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf for packages in gcc gcc-c++ openssl-devel ncurses-devel wget crontabs iptables bison cmake automake make readline-devel logrotate openssl; do echo "[${packages} Installing] ************************************************** >>"; yum -y install $packages; done; mv -f /etc/yum.conf.lnmp /etc/yum.conf; else apt-get remove -y mysql-client mysql-server mysql-common; apt-get update; for packages in gcc g++ cmake make ntp logrotate cron bison libncurses5-dev libncurses5 libssl-dev openssl curl openssl; do echo "[${packages} Installing] ************************************************** >>"; apt-get install -y $packages --force-yes;apt-get -fy install;apt-get -y autoremove; done; fi;}INSTALL_MYSQL(){ INSTALL_BASE_PACKAGES cd /tmp/ echo "[${MysqlVersion} Installing] ************************************************** >>"; [ ! -f ${MysqlVersion}.tar.gz ] && wget -c ${MysqlLine}/${MysqlVersion}.tar.gz tar -zxf /tmp/$MysqlVersion.tar.gz; cd /tmp/$MysqlVersion; groupadd mysql; useradd -s /sbin/nologin -g mysql mysql; cmake -DCMAKE_INSTALL_PREFIX=$MysqlPath -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=complex -DWITH_READLINE=ON -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_UNIT_TESTS=OFF; make -j $Cpunum; make install; for path in $MysqlLogPath $MysqlPath $MysqlConfigPath/conf.d $MysqlDataPath;do [ ! -d $path ] && mkdir -p $path chmod 740 $path; chown -R mysql:mysql $path; done# EOF **********************************cat > $MysqlConfigPath/my.cnf<<EOF;[mysqld]user = mysqlserver-id = 1pid-file = /var/run/mysqld.pidsocket = /var/run/mysqld.sockport = 3306basedir = $MysqlPathdatadir = $MysqlDataPathbind-address = 0.0.0.0skip-name-resolveskip-external-lockingthread_concurrency = `expr $CpuNum \* 2`max_connections = `expr $FileMax \* $CpuNum \* 2 / $RamTotal`max_connect_errors = 30table_open_cache = `expr $RamTotal + $RamSwap`max_allowed_packet = `expr $RamTotal \* 2 / 1000`Mbinlog_cache_size = 4Mmax_heap_table_size = `expr $RamTotal / 100`Msort_buffer_size = `expr $RamTotal \* 2 / 1000`Mjoin_buffer_size = `expr $RamTotal \* 2 / 1000`Mquery_cache_size = `expr $RamTotal / 100`Mthread_cache_size = 30thread_concurrency = `expr $CpuNum \* 4`connect_timeout = 1200wait_timeout = 1200general_log = 1general_log_file = $MysqlLogPath/mysql.loglog_error = $MysqlLogPath/mysql-err.logslow_query_log = 1slow_query_log_file = $MysqlLogPath/mysql-slow.loglong_query_time = 3log_bin = $MysqlLogPath/mysql-binlog_bin_index = $MysqlLogPath/mysql-bin.indexexpire_logs_days = 7max_binlog_size = `expr $(df -m $MysqlLogPath |awk 'NR==2{printf "%s\n",$4}') / 10000`Mdefault_storage_engine = InnoDBinnodb_buffer_pool_size = `expr $RamTotal / 100`Minnodb_log_buffer_size = 8Minnodb_file_per_table = 1innodb_open_files = `expr $FileMax \* $CpuNum / $RamTotal`innodb_io_capacity = `expr $FileMax \* $CpuNum / $RamTotal`innodb_flush_method = O_DIRECT !includedir $$MysqlConfigPath/conf.d[mysqld_safe]open_files_limit = `expr $FileMax / $CpuNum / 100`[isamchk]key_buffer = 16M[mysqldump]quickquote-namesmax_allowed_packet = 16MEOF# ************************************** $MysqlPath/scripts/mysql_install_db --user=mysql --defaults-file=$MysqlConfigPath/my.cnf --basedir=$MysqlPath --datadir=$MysqlDataPath;# EOF **********************************cat > /etc/ld.so.conf.d/mysql.conf<<EOF/usr/local/mysql/lib/mysql/usr/local/libEOF# ************************************** ldconfig; if [ "$SysBit" == '64' ] ; then ln -s $MysqlPath/lib/mysql /usr/lib64/mysql; else ln -s $MysqlPath/lib/mysql /usr/lib/mysql; fi; cp $MysqlPath/support-files/mysql.server /etc/init.d/mysqld; chmod 775 /etc/init.d/mysqld; /etc/init.d/mysqld start; ln -s $MysqlPath/bin/mysql /usr/bin/mysql; ln -s $MysqlPath/bin/mysqladmin /usr/bin/mysqladmin; $MysqlPath/bin/mysqladmin password $MysqlPass; rm -rf $MysqlDataPath/test;# EOF **********************************mysql -hlocalhost -uroot -p$MysqlPass <<EOFUSE mysql;DELETE FROM user WHERE user='';UPDATE user set password=password('$MysqlPass') WHERE user='root';DELETE FROM user WHERE not (user='root');DROP USER ''@'%';FLUSH PRIVILEGES;EOF# ************************************** echo "[OK] ${MysqlVersion} install completed.";}INSTALL_MYSQL
感謝各位的閱讀,以上就是“mysql源碼安裝的腳本分享”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)mysql源碼安裝的腳本分享這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。