MySQL源码安装脚本(初版)

前端之家收集整理的这篇文章主要介绍了MySQL源码安装脚本(初版)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear;
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		= MysqL
server-id	= 1
pid-file	= /var/run/MysqLd.pid
socket		= /var/run/MysqLd.sock
port		= 3306
basedir		= $MysqLPath
datadir		= $MysqLDataPath
bind-address	= 0.0.0.0
skip-name-resolve
skip-external-locking
thread_concurrency	= `expr $cpuNum \* 2`
max_connections	= `expr $FileMax \* $cpuNum \* 2 / $RamTotal`
max_connect_errors	= 30
table_open_cache	= `expr $RamTotal + $RamSwap`
max_allowed_packet	= `expr $RamTotal \* 2 / 1000`M
binlog_cache_size	= 4M
max_heap_table_size	= `expr $RamTotal / 100`M
sort_buffer_size	= `expr $RamTotal \* 2 / 1000`M
join_buffer_size	= `expr $RamTotal \* 2 / 1000`M
query_cache_size	= `expr $RamTotal / 100`M
thread_cache_size	= 30
thread_concurrency	= `expr $cpuNum \* 4`
connect_timeout		= 1200
wait_timeout		= 1200
general_log	= 1
general_log_file	= $MysqLLogPath/MysqL.log
log_error	= $MysqLLogPath/MysqL-err.log
slow_query_log	= 1
slow_query_log_file	= $MysqLLogPath/MysqL-slow.log
long_query_time	= 3
log_bin	= $MysqLLogPath/MysqL-bin
log_bin_index	= $MysqLLogPath/MysqL-bin.index
expire_logs_days	= 7
max_binlog_size	= `expr $(df -m $MysqLLogPath |awk 'NR==2{printf "%s\n",$4}') / 10000`M
default_storage_engine	= InnoDB
innodb_buffer_pool_size	= `expr $RamTotal / 100`M
innodb_log_buffer_size	= 8M
innodb_file_per_table	= 1
innodb_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]
quick
quote-names
max_allowed_packet	= 16M
EOF
# **************************************
	$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/lib
EOF
# **************************************
	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 <<EOF
USE 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

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章