mariadb-galera-10.0.19oncentos6.5
******************************************************************************
0.使用場景
******************************************************************************
數據庫軟件:mariadb-galera-10.0.19-linux-x86_64.tar.gz
集群管理:galera-25.3.5-1.rhel6.x86_64.rpm
節點同步方式(xtrabackup,rsync):percona-xtrabackup-2.2.8-5059.el6.x86_64.rpm
節點同步使用sockt:socat-2.0.0-b7.tar.gz
安裝galera是為了獲得/usr/lib64/galera/libgalera_smm.so;
安裝xtrabackup是為了配置同步方式xtrabackup,節點數據同步的時候用到;
安裝socat是因為同步數據使用socket方式進行端到端的數據交換;
數據庫節點:
192.168.50.10 db01 db01.mysql.com
192.168.50.20 db02 db02.mysql.com
192.168.50.30 db03 db03.mysql.com
******************************************************************************
1.系統安裝
******************************************************************************
--------1.desktop安裝即可,選擇自定義
選擇下面兩個包,其它根據自己需求選擇
base system
legacy unix compatibility(rsh telnet ksh tftp )
Desktops
legacy x window system compatibility (xorg-x11-xdm)
-------2 配置yum源
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.old
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum makecache
檢查可更新的rpm包
#yum check-update
更新所有的rpm包
#yum update
---3.關閉防火牆和selinux
chkconfig --level 123456 iptables off
service iptables stop
/usr/sbin/sestatus -v | grep "SELinux status"
vi /etc/selinux/config
SELINUX=disabled
---4.修改各個節點hosts
#vi /etc/hosts
192.168.50.10 db01 db01.mysql.com
192.168.50.20 db02 db02.mysql.com
192.168.50.30 db03 db03.mysql.com
---4.rz
yum install lrzsz -y
******************************************************************************
2.mysql安裝部分
******************************************************************************
一:卸載舊版本
使用下面的命令檢查是否安裝有MySQL Server
rpm -qa | grep mysql
有的話通過下面的命令來卸載掉
rpm -e mysql //普通刪除模式
rpm -e --nodeps mysql
rpm -e --nodeps mysql-devel
rpm -e --nodeps mysql-libs
// 強力刪除模式,如果使用上面命令刪除時,提示有依賴的其它文件,
則用該命令可以對其進行強力刪除
yum remove mysql-libs
二:安裝MySQL
1.安裝編譯代碼需要的包
yum -y install cmake gcc gcc-c++ autoconf automake zlib* libxml* \
ncurses ncurses-devel libtool-ltdl-devel* make bison bison-devel libaio \
openssl-devel libevent-devel \
libaio-devel pam-devel boost-devel valgrind-devel \
libnl-devel popt-devel popt-static
2.為mysql新建組和用戶
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
passwd mysql
mysql01!
id mysql
3.設置用戶的系統資源限制
#vi /etc/security/limits.conf
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
4.編譯安裝
tar xf mariadb-galera-10.0.19.tar.gz
cd cd mariadb-10.0.19
編譯安裝
/***
cmake . -LH --查看cmake支持的mysql相關參數
shell> cmake . -L # overview
shell> cmake . -LH # overview with help text
shell> cmake . -LAH # all params with help text
shell> ccmake . # interactive display
重新編譯時,需要清除舊的對象文件和緩存信息
# make clean
# rm -f CMakeCache.txt
****/
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_DATADIR=/data/mysql/data \
-DMYSQL_TCP_PORT=33306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_WSREP=1 \
-DWITH_INNODB_DISALLOW_WRITES=1
make -j4
make install
三:配置MySQL
1.新建數據文件、臨時文件,修改/usr/local/mysql權限
mkdir -p /data/mysql
mkdir /data/mysql/{innodb_data,data,tmp} -p
mkdir /data/mysql/mysql_logs/{binary_log,innodb_log,query_log,slow_query_log,error_log} -p
2.修改權限
chown -R mysql /data/mysql
chgrp -R mysql /data/mysql
3.修改參數
#rm -rf /etc/my.cnf
#vi /data/mysql/my.cnf
##鏈接文件
#ln -fs /data/mysql/my.cnf /etc/my.cnf
ll /etc/my.cnf
lrwxrwxrwx. 1 root root 23 Nov 18 17:30 /etc/my.cnf -> /data/mysql/my.cnf
chown -R mysql /data/mysql
chgrp -R mysql /data/mysql
5.初始化數據庫
cd /data/mysql/scripts
# ./mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/data/mysql \
--datadir=/data/mysql/data
6.啟動MySQL
chown -R mysql /data/mysql
chgrp -R mysql /data/mysql
--6.1建議安全啟動
/data/mysql/bin/mysqld_safe &
/data/mysql/bin/mysqld_safe --datadir='/data/mysql/data' &
--6.2添加服務,拷貝服務腳本到init.d目錄,並設置開機啟動
cd /data/mysql/
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
7.配置mysql用戶
MySQL啟動成功後,root默認沒有密碼,我們需要設置root密碼。
7.1修改/etc/profile文件,在文件末尾添加
#vi /etc/profile
PATH=/data/mysql/bin:$PATH
export PATH
#source /etc/profile
現在,我們可以在終端內直接輸入mysql進入,mysql的環境了
執行下面的命令修改root密碼
--7.2修改mysql管理員密碼
1.修改當前用戶密碼
mysql -uroot -p
SET PASSWORD = PASSWORD('pass01');
flush privileges;
2.給所有的root用戶設定密碼:
第一種方式(推薦)
# mysql -uroot -p
MariaDB [(none)]>
MariaDB [(none)]> select host,user,password from mysql.user;
+-------------+------+----------+
| host | user | password |
+-------------+------+----------+
| localhost | root | |
| db02.zp.com | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| db02.zp.com | | |
+-------------+------+----------+
6 rows in set (0.00 sec)
update mysql.user set password = password('pass01') where user = 'root' limit 100;flush privileges;
flush privileges;
3.刪除所有匿名用戶(不要刪除root@localhost)
DROP USER ''@'localhost';delete from mysql.user where user='' limit 10;commit;flush privileges;
delete from mysql.user where host='db01.mysql.com';flush privileges;
--7.3設置root用戶可以遠程訪問
--方法1:授權法
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pass01' \
WITH GRANT OPTION;flush privileges;
select host,user,password from mysql.user;
--7.4 登錄mysql
#mysql -hlocalhost -uroot -ppass01
----7.5設置linux腳本
vi ~/.bash_profile
#ocpyang set(綁定mysql到內網IP只能寫內網IP)
alias mysql="mysql -U -hlocalhost -uroot -ppass01 --auto-rehash"
alias errorlog="cat /data/mysql/mysql_logs/error_log/error.log"
alias mycnf="cd /data/mysql"
export PATH=/data/mysql/scripts:$PATH
source ~/.bash_profile
----7.7修改權限
chown -R mysql /data/mysql
chgrp -R mysql /data/mysql
----7.8 常見啟動錯誤或警告
cat /data/mysql/mysql_logs/error_log/error.log
Warning] 'proxies_priv' entry '@% [email protected]' ignored in --skip-name-resolve mode.
解決辦法:
delete from mysql.proxies_priv where host='db01.mysql.com';commit;flush privileges;
******************************************************************************
3.galera相關配置
******************************************************************************
---3.1 新建wsrep用戶
GRANT ALL PRIVILEGES ON *.* TO 'wsrep'@'%' IDENTIFIED BY 'wsrep' ;flush privileges;
---3.2 安裝galera
--3.2.1 安裝galera所依賴的軟件
yum install boost-devel
yum install check-devel
wget http://cznic.dl.sourceforge.net/project/scons/scons/2.3.4/scons-2.3.4.tar.gz
tar zxvf scons-2.3.4.tar.gz
cd scons-2.3.4
python setup.py install
--3.2.2 安裝galera
#rpm -ql | grep galera
#cd /soft
#rpm -ivh galera-25.3.5-1.rhel6.x86_64.rpm
# ls /usr/lib64/galera
libgalera_smm.so
---3.2.3
#tar xf socat-2.0.0-b7.tar.gz
#cd socat
#./configure
#make & make install
---3.2.4 修改mysql的配置文件
mkdir /etc/my.cnf.d
cd /soft/mariadb-10.0.19/support-files
cp wsrep.cnf /etc/my.cnf.d/
#vi /etc/my.cnf.d/wsrep.cnf
#notde01
[mysqld]
wsrep_on=ON
binlog_format=ROW
default-storage-engine=innodb
#為了降低沖突
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
innodb_flush_log_at_trx_commit = 2 #可以提高性能,galera保證不丟數據
query_cache_size=0
query_cache_type=0
wsrep_provider=/usr/lib64/galera/libgalera_smm.so #修改
wsrep_cluster_name="galera_cluster" #修改
wsrep_cluster_address="gcomm://" #修改
wsrep_node_address='192.168.50.10,192.168.50.20,192.168.50.30' #修改
wsrep_node_name='db01' #修改
wsrep_slave_threads=4
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=mysqldump #可以修改#rsync,xtrabackup,mysqldump
wsrep_sst_auth=root:pass01 #修改
#notde02
[mysqld]
wsrep_on=ON
binlog_format=ROW
default-storage-engine=innodb
#為了降低沖突
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit = 2 #可以提高性能,galera保證不丟數據
query_cache_size=0
query_cache_type=0
wsrep_provider=/usr/lib64/galera/libgalera_smm.so #修改
wsrep_cluster_name="galera_cluster" #修改
wsrep_cluster_address="gcomm://192.168.50.10,192.168.50.20,192.168.50.30" #修改
wsrep_node_address='192.168.50.20' #修改
wsrep_node_name='db02' #修改
wsrep_slave_threads=4
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=mysqldump #可以修改#rsync,xtrabackup,mysqldump,xtrabackup-v2
wsrep_sst_auth=root:pass01 #修改
#notde03
[mysqld]
wsrep_on=ON
binlog_format=ROW
default-storage-engine=innodb
#為了降低沖突
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
innodb_flush_log_at_trx_commit = 2 #可以提高性能,galera保證不丟數據
query_cache_size=0
query_cache_type=0
wsrep_provider=/usr/lib64/galera/libgalera_smm.so #修改
wsrep_cluster_name="galera_cluster" #修改
wsrep_cluster_address="gcomm://192.168.50.10,192.168.50.20,192.168.50.30" #修改
wsrep_node_address='192.168.50.30' #修改
wsrep_node_name='db03' #修改
wsrep_slave_threads=4
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=mysqldump #可以修改#rsync,xtrabackup,mysqldump,xtrabackup-v2
wsrep_sst_auth=root:pass01 #修改
echo '!includedir /etc/my.cnf.d/' >>/etc/my.cnf
---4.使用rsync、xtrabackup、mydupm
--4.1 使用rsync
yum -y install rsync
#tar xvzf socat-2.0.0-b8.tar.gz
#cd socat-2.0.0-b8
#./configure
#make & make install
--強烈建議將xtrabackup和socat加入path
#vi /etc/profile
PATH=/data/mysql/bin:/usr/local/bin/socat:/usr/local/xtrabackup/bin:$PATH
export PATH
ln -s /usr/local/bin/socat /usr/sbin/
ln -s /usr/local/xtrabackup/bin/* /usr/sbin/
--4.2 使用xtrabackup
---5.初始化啟動
--方法1:
修改 my.cnf 並設置 wsrep_cluster_address=gcomm:// ,啟動後再來修改配置.
--方法2:
使用下面這個命令來啟動 mysql (支持 RedHat 和 CentOS 系統)
/data/mysql/bin/mysqld_safe --datadir='/data/mysql/data' --wsrep-cluster-address="gcomm://" &
/data/mysql/bin/mysqld_safe --datadir='/data/mysql/data' &
----6.各節點啟動相關
# netstat -lntp | grep 33306
tcp 0 0 :::33306 :::* LISTEN 3072/mysqld
# pkill mysqld
NODE1先啟動,其它節點無順序.
----7.查看群集連接情況
SHOW STATUS LIKE 'wsrep_cluster_size';
SHOW STATUS LIKE 'wsrep%';