MySQL 5.6.26源码安装

MySQL 5.6.26 源码安装包 与 cmake安装包链接:

操作系统版本:CentOS release 6.3 (Final)

安装过程:(记得挂载镜像,并且配置yum,方便yum安装各种依赖的包

CentOS配置yum:
1、cd  /etc/yum.repos.d
2、创建个任意目录,将所有文件移动到创建的目录中,除了CentOS-Media.repo
3、编辑CentOS-Media.repo
    vi  CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


4、创建/media/CentOS/目录
5、挂载
    mount /dev/cdrom  /media/CentOS/


[root@hank-yoon ~]# mkdir -p /export/servers

[root@hank-yoon servers]# 上传安装脚本、MySQL源码安装包,Cmake安装包

[root@hank-yoon servers]#ls
cmake-2.8.3.tar.gz   mysql-5.6.26.tar.gz  install.sh

[root@hank-yoon servers]#sh install.sh

[root@hank-yoon servers]#cat  install.sh   脚本内容
#!/bin/bash


# check
echo -e "\033[;37;34mCheck Memory Size...\033[0m"
if [ `free -g|grep ^Mem|awk '{print $2}'` != 125 ]
then
read -p "Memory size is `free -g|grep ^Mem|awk '{print $2}'`G , enter innodb_buffer_pool_size(default 20G) : " pool
else
echo -e "\033[;37;32mMemory Size is 125G , innodb_buffer_pool_size set 100G\033[0m"
fi
echo -e "\033[;37;34mCheck Network...\033[0m"
#if ! ping -c 1 -w 1 > /dev/null;then echo -e "\033[;37;31mPlease Check Network Before Setup\033[0m";exit 1;else echo -e "\033[;37;32mOK\033[0m";fi
echo -e "\033[;37;34mCheck Packet...\033[0m"
if ! ls mysql-5.6.26.tar.gz cmake-2.8.3.tar.gz > /dev/null;then echo -e "\033[;37;31mNo Packets\033[0m";exit 1;else echo -e "\033[;37;32mOK\033[0m";fi
# replace  yum.repos.d
#rm -f /etc/yum.repos.d/*
#wget -P /etc/yum.repos.d/
#sed -i 's/6.3/6.5/' /etc/yum.repos.d/CentOS-Media.repo
#echo -e "\033[;37;34mreplace  yum.repos.d...\033[0m"


#wget mysql cmake


#change IO scheduler
echo deadline > /sys/block/sda/queue/scheduler
echo -e "\033[;37;34mchange IO scheduler to deadline...\033[0m"


# init enviroment
echo -e "\033[;37;34mStarting Yum Install...\033[0m"
yum install -y ncurses-devel glibc gcc gcc-c++ libstdc++*  libtool cmake lrzsz libaio-devel 
echo -e "\033[;37;32mYum Install Done\033[0m"
echo -e "\033[;37;34mAdd MySQL OS User...\033[0m"
useradd mysql
echo -e "\033[;37;32mAdd User Done\033[0m"


setuplog=/home/mysql/logs/install-log
setupdir=$(pwd)
mysqldir=(/export/data/mysql/tmp /export/data/mysql/undo /export/data/mysql/data /export/servers/mysql/etc /export/data/mysql/dumps /export/data/mysql/log /home/mysql/scripts /home/mysql/logs)
mkdir -p ${mysqldir[*]}
chown mysql:mysql -R /export/data/mysql /home/mysql/


echo -e "\033[;37;34mExtracting package to /usr/local/src/\033[0m"
tar xzf cmake-2.8.3.tar.gz -C /usr/local/src
tar xzf mysql-5.6.26.tar.gz -C /usr/local/src
mv *.tar.gz /usr/local/src
echo -e "\033[;37;32mExtracting Done\033[0m"


# install
echo -e "\033[;37;34mInstall Cmake...\033[0m"
cd /usr/local/src/cmake-2.8.3 ; ./bootstrap && gmake && make install
if [ $? = 0 ];then echo -e "\033[;37;32mCmake Install Done\033[0m";else echo -e "\033[;37;31mCmake Install Faild\033[0m";fi


echo -e "\033[;37;34mInstall MySQL...\033[0m"
echo "Configure Error" > $setuplog
cd /usr/local/src/mysql-5.6.26 ; cmake . -DCMAKE_INSTALL_PREFIX=/export/servers/mysql/ -DMYSQL_DATADIR=/export/data/mysql/data -DSYSCONFDIR=/export/servers/mysql/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/export/data/mysql/tmp/mysql.sock -DENABLED_LOCAL_INFILE=ON -DENABLED_PROFILING=ON -DWITH_DEBUG=0 -DENABLE_DTRACE=OFF -DMYSQL_TCP_PORT=3358 2>> $setuplog
make && make install
if [ $? = 0 ];then echo -e "\033[;37;32mMySQL Install Done\033[0m";else echo -e "\033[;37;31mMySQL Install Faild\033[0m";exit 1;fi
/sbin/ldconfig /export/servers/mysql/lib/


echo -e "\033[;37;34mModify /home/mysql/.bash_profile...\033[0m"
echo "export LANG=en_US.UTF-8" >> /home/mysql/.bash_profile
sed -i 's!PATH=$PATH:$HOME/bin!PATH=$PATH:$HOME/bin:/export/servers/mysql/bin!' /home/mysql/.bash_profile
source /home/mysql/.bash_profile
echo -e "\033[;37;32mDONE\033[0m"


# my.cnf
echo -e "\033[;37;34mCreate /export/servers/mysql/etc/my.cnf...\033[0m"
cat >> /export/servers/mysql/etc/my.cnf << EOF
[client]
port            = 3358
socket          = /export/data/mysql/tmp/mysql.sock


[mysqld]
port            = 3358
socket          = /export/data/mysql/tmp/mysql.sock
datadir         = /export/data/mysql/data/




#--- GLOBAL ---#
character-set-server    = utf8
lower_case_table_names  = 1
log-output              = FILE
log-error               = /export/data/mysql/log/error.log


general_log = 0


general_log_file        = /export/data/mysql/log/mysql.log
pid-file                = /export/data/mysql/mysql.pid
slow-query-log
slow_query_log_file     = /export/data/mysql/log/slow.log
tmpdir                  = /export/data/mysql/tmp
long_query_time         = 1


#--------------#


#thread_concurrency      = 16
thread_cache_size       = 512
table_open_cache        = 16384
table_definition_cache  = 16384
sort_buffer_size        = 2M
join_buffer_size        = 2M
read_buffer_size        = 4M
read_rnd_buffer_size    = 4M
key_buffer_size         = 8M
myisam_sort_buffer_size = 8M
tmp_table_size          = 64M
max_heap_table_size     = 64M
open_files_limit        = 65535
query_cache_size       = 0


#add z #################
innodb_undo_directory = /export/data/mysql/undo
innodb_undo_tablespaces = 4
explicit_defaults_for_timestamp = 1


#--- NETWORK ---#
back_log                = 1024
max_allowed_packet      = 16M
interactive_timeout     = 28800
wait_timeout            = 28800
skip-external-locking
max-connections         = 1000
skip-name-resolve
#read_only               = 1
#--- REPL ---#
server-id               = 360360
log-bin                 = mysql-bin
binlog_format           = mixed
expire_logs_days        = 7
relay-log               = relay-log




replicate-ignore-db     = mysql.slave_master_info
replicate-ignore-db     = mysql.slave_relay_log_info
replicate-ignore-db     = mysql.slave_worker_info
replicate-ignore-db     = test
replicate-ignore-db     = information_schema
replicate-ignore-db     = performance_schema




log_slave_updates
skip-slave-start
slave-parallel-workers= 4
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
relay_log_info_repository = TABLE
master_info_repository = TABLE
#rpl_semi_sync_master_enabled = 1
#rpl_semi_sync_slave_enabled = 1
#rpl_semi_sync_master_timeout = 1000


#--- INNODB ---#
default-storage-engine          = INNODB
innodb_data_home_dir            = /export/data/mysql/data
innodb_file_per_table
innodb_log_group_home_dir       = /export/data/mysql/data
innodb_log_files_in_group       = 3
innodb_log_file_size            = 512M
innodb_log_buffer_size          = 16M
innodb_flush_log_at_trx_commit  = 1
innodb_lock_wait_timeout        = 120
innodb_flush_method             = O_DIRECT
innodb_max_dirty_pages_pct      = 75


#change z #####
sync_binlog = 1
innodb_buffer_pool_size         = 100G
innodb_data_file_path           = ibdata1:2G;ibdata2:2G:autoextend
innodb_autoextend_increment     = 500
innodb_thread_concurrency       = 32
innodb_open_files               = 65535
innodb_write_io_threads = 20
innodb_read_io_threads = 20
innodb_spin_wait_delay = 10
innodb_flush_neighbors = 1
innodb_use_native_aio = 1
innodb_io_capacity              = 2000
innodb_io_capacity_max          = 6000
relay_log_recovery = 1
#innodb_additional_mem_pool_size = 128M


#change h #####


#innodb_numa_interleave=ON
innodb_lru_scan_depth=512
innodb_checksum_algorithm=crc32
innodb_purge_threads=4




[mysqldump]
quick
max_allowed_packet = 16M


[mysql]
# auto-rehash
# Remove the next comment character if you are not familiar with SQL
# safe-updates
default-character-set=utf8


[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M


[mysqlhotcopy]
interactive-timeout


EOF
serverid=$(ifconfig |grep Bcast|grep 'inet addr:' | awk '{print $2}' |awk -F. '{print $3$4}')
#serverid=$(ifconfig eth0|grep Bcast|grep 'inet addr:' | awk '{print $2}' |awk -F. '{print $3$4}')
sed -i 's/360360/'$serverid'/' /export/servers/mysql/etc/my.cnf
if [ ! -z $pool ];then sed -i 's/innodb_buffer_pool_size         = 100G/innodb_buffer_pool_size         = '$pool'/' /export/servers/mysql/etc/my.cnf;echo -e "\033[;37;34m`cat /export/servers/mysql/etc/my.cnf|grep innodb_buffer_pool_size`\033[0m";fi
echo -e "\033[;37;32mDONE\033[0m"


# start
/export/servers/mysql/scripts/mysql_install_db --user=mysql --basedir=/export/servers/mysql/ --datadir=/export/data/mysql/data/
/export/servers/mysql/bin/mysqld_safe --defaults-file=/export/servers/mysql/etc/my.cnf &
echo -e "\033[;37;34mStart MySQL\033[0m"
for i in {1..500};do [ -S /export/data/mysql/tmp/mysql.sock ] && echo -e "\033[;37;32m[OK]\033[0m" && break || echo -n ". ";sleep 2;done
if [ ! -S /export/data/mysql/tmp/mysql.sock ];then echo -e "\033[;37;31m[Start Faild,See /export/data/mysql/log/error.log]\033[0m";exit 1;fi




# cutting
echo -e "\033[;37;34mCreate Cutting.sh to Crontab\033[0m"
cat >> /home/mysql/scripts/cutting.sh << EOF
#!/bin/bash
mysql=/export/servers/mysql/bin/mysql
user=backup
password='7FH3iwIX90VdUInu'


generallog=/export/data/mysql/log/mysql.log
if [ -f \$generallog ]
then
        mv \$generallog \${generallog}.\`date  "+%Y%m%d%H"\`
        \$mysql -u\$user -p\$password -e "flush no_write_to_binlog general logs;"
fi


slowlog=/export/data/mysql/log/slow.log
if [ \`date "+%w"\` = 6 -a -f \$slowlog ]
then
        mv \$slowlog \${slowlog}.\`date  "+%Y%m%d%H"\`
        \$mysql -u\$user -p\$password -e "flush no_write_to_binlog slow logs;"
fi


find /export/data/mysql/log/ -type f -name "*.log.*" -mtime +7 |xargs rm -f
EOF
chown mysql.mysql /home/mysql/scripts/cutting.sh
chmod +x /home/mysql/scripts/cutting.sh
echo "1 0 * * * /home/mysql/scripts/cutting.sh" >> /var/spool/cron/mysql
echo "1 0 * * * /usr/sbin/ntpdate 172.17.1.134 | hwclock -w" >> /var/spool/cron/root
chown mysql.root /var/spool/cron/mysql
chmod 600 /var/spool/cron/mysql
/etc/init.d/crond restart
echo -e "\033[;37;32mDONE\033[0m"
mkdir /var/lib/mysql
ln -s /export/data/mysql/tmp/mysql.sock /var/lib/mysql/mysql.sock
chown -R mysql.mysql  /var/lib/mysql


echo -e "\033[;37;34mClean...\033[0m"
> /export/data/mysql/log/mysql.log
rm -f ${setupdir}/`basename $0`
echo -e "\033[;37;32mDONE\033[0m"


# add service 
cp /export/servers/mysql/support-files/mysql.server /etc/init.d/mysql


# rpl semi sync ON
/export/servers/mysql/bin/mysql -uroot -e "install plugin rpl_semi_sync_master soname 'semisync_master.so'"
/export/servers/mysql/bin/mysql -uroot -e "install plugin rpl_semi_sync_slave soname 'semisync_slave.so'";
sed -i 's/#rpl_semi_sync_master_enabled/rpl_semi_sync_master_enabled/' /export/servers/mysql/etc/my.cnf
sed -i 's/#rpl_semi_sync_slave_enabled/rpl_semi_sync_slave_enabled/' /export/servers/mysql/etc/my.cnf
sed -i 's/#rpl_semi_sync_master_timeout/rpl_semi_sync_master_timeout/' /export/servers/mysql/etc/my.cnf


# mysql restart
service mysql restart

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/2fc3c7667125383e77bc109bfbac0762.html