程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> Galera10.0.20onCentOS6.6

Galera10.0.20onCentOS6.6

編輯:MySQL綜合教程

Galera10.0.20onCentOS6.6


Galera 10.0.20 on CentOS 6.6


0.使用場景


數據庫軟件:mariadb-galera-10.0.20-linux-x86_64.tar.gz
集群管理:galera-3-25.3.10
節點同步方式(xtrabackup,rsync):percona-xtrabackup-2.2.8-5059.el6.x86_64.rpm
節點同步使用sockt:socat-2.0.0-b7.tar.gz

安裝galera是為了獲得libgalera_smm.so;
安裝xtrabackup是為了配置同步方式xtrabackup,節點數據同步的時候用到;
安裝socat是因為同步數據使用socket方式進行端到端的數據交換;

數據庫節點:
127.0.0.1 localhost localhost
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.系統安裝


——–0.刪除postfix

yum remove postfix

——–1.系統安裝

參見:Linux for Mysql 系統安裝規范

——-2 配置yum源

cd /etc/yum.repos.d

mv CentOS-Base.repo CentOS-Base.repo.old

阿裡鏡像

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

163鏡像

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 libtool-ltdl-devel* make bison bison-devel \
openssl-devel libevent-devel \
libaio libaio-devel pam-devel boost boost-devel valgrind-devel \
libnl-devel popt-devel popt-static bzr

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.20.tar.gz

cd mariadb-10.0.20

編譯安裝

/*
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;
delete from mysql.user where host=’db02.mysql.com’;flush privileges;
delete from mysql.user where host=’db03.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;
delete from mysql.proxies_priv where host=’db02.mysql.com’;commit;flush privileges;
delete from mysql.proxies_priv where host=’db03.mysql.com’;commit;flush privileges;

—–7.9 軟連接mysql的bin目錄

ln -sf /data/mysql/bin/* /usr/bin/


3.galera相關配置


—–3.1 galera安裝(參見galera安裝配置)

—3.2 新建wsrep用戶

GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON . TO ‘wsrep’@’%’ IDENTIFIED BY ‘wsrep’ ;flush privileges;

CREATE USER ‘wsrep’@’localhost’ IDENTIFIED BY ‘wsrep’;
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON . TO ‘wsrep’@’localhost’;
FLUSH PRIVILEGES;

—3.2.3 安裝socat

http://www.dest-unreach.org/socat/

http://www.dest-unreach.org/socat/download/

tar xf socat-1.7.3.0.tar.gz
cd socat-1.7.3.0
./configure
make -j4
make install

—3.2.4 修改mysql的配置文件

mkdir /etc/my.cnf.d

cd /soft/mariadb-10.0.20/support-files

cp wsrep.cnf /etc/my.cnf.d/

vi /etc/my.cnf.d/wsrep.cnf

node01

[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=/data/mysql/lib/plugin/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.10 #修改
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=xtrabackup-v2 #可以修改#rsync,xtrabackup,mysqldump
wsrep_sst_auth=root:pass01 #修改

node02

[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=/data/mysql/lib/plugin/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=xtrabackup-v2 #可以修改#rsync,xtrabackup,mysqldump,xtrabackup-v2
wsrep_sst_auth=root:pass01 #修改

node03

[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=/data/mysql/lib/plugin/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=xtrabackup-v2 #可以修改#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:$PATH
export PATH

ln -sf /usr/local/bin/socat /usr/sbin/

—–4.2 使用xtrabackup(推薦)

tar xf Percona-XtraBackup-2.2.11-r7956d1d-el6-x86_64-bundle.tar

yum localinstall -y percona-*

—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’ &

–node1查看日志

cat /data/mysql/data/innobackup.backup.log

—-6.各節點啟動相關

netstat -lntp | grep 33306

tcp 0 0 :::33306 :::* LISTEN 3072/mysqld

pkill mysqld

NODE1先啟動,其它節點無順序.

—-7.查看群集連接情況

SELECT VARIABLE_VALUE as “cluster size” FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME=”wsrep_cluster_size”;

SHOW STATUS LIKE ‘wsrep_cluster_size’;

SHOW STATUS LIKE ‘wsrep%’;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved