[root@server ~]# yum -y install mariadb-serverphp
[root@server ~]# vim /etc/my.cnfnode
# 在[mysqld]部分添加mysql
[mysqld]sql
character-set-server=utf8數據庫
[root@server ~]# systemctl start mariadb bootstrap
[root@server ~]# systemctl enable mariadb vim
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'centos
[root@client ~]# mysql_secure_installation 瀏覽器
使用root用戶鏈接服務器
[root@client ~]# mysql -u root –p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.37-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 查看用戶列表
MariaDB [(none)]> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | 127.0.0.1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | ::1 | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
# 查看數據庫列表
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@server ~]# yum -y install phpMyAdmin php-mysql php-mcrypt
[root@server ~]# vi /etc/httpd/conf.d/phpMyAdmin.conf
# line 15: 你容許訪問的網段
Require ip 127.0.0.1 192.168.96.0/24
# line 32: 你容許訪問的網段
Require ip 127.0.0.1 192.168.96.0/24
[root@client ~]# systemctl restart httpd
MariaDB Replication的 主從配置的設置。
[root@client ~]# vi /etc/my.cnf
[mysqld]
# 在mysqld 部分添加如下部分,獲得二進制日誌。
log-bin=mysql-bin
# 定義server ID
server-id=101
[root@client ~]# systemctl restart mariadb
[root@client ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.41-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#建立用戶(set any password for 'password' section)
MariaDB [(none)]> grant replication slave on *.* to replica@'%' identified by 'password';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@repl01 ~]# vi /etc/my.cnf
[mysqld]
# 在mysqld 部分添加如下部分,獲得二進制日誌。
log-bin=mysql-bin
# 定義server ID,不一樣於主配置文件的id
server-id=102
# 只讀
read_only=1
# 定義本身的主機名
report-host=repl01.example.com
[root@repl01 ~]# systemctl restart mariadb
[root@client ~]# mysql -u root -p
Enter password:
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#鎖住全部的表
MariaDB [(none)]> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
# 顯示狀態 (remember File, Position value)
MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 465 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
#保留以前的窗口,打開一個新的執行轉儲
[root@client ~]# mysqldump -u root -p --all-databases --lock-all-tables --events > mysql_dump.sql
Enter password:
# 返回以前的窗口,並解鎖
MariaDB [(none)]> unlock tables;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
#將轉儲轉發至從服務器
[root@client ~]# scp mysql_dump.sql repl01.example.com:/tmp/
root@repl01.example.com's password:
mysql_dump.sql 100% 515KB 514.7KB/s 00:00
[5]在從服務器上配置replication
準備好以後,確信工做正常從而在主服務器建立數據庫
#從主服務器導入轉儲
[root@repl01 ~]# mysql -u root -p < /tmp/mysql_dump.sql
Enter password:
[root@repl01 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> change master to
-> master_host='10.0.0.31', # Master Hosts's IP
-> master_user='replica', # replication ID
-> master_password='password', # replication ID's password
-> master_log_file='mysql-bin.000001', # File value confirmed on Master
-> master_log_pos=465; # Position value confirmed on Master
Query OK, 0 rows affected (0.58 sec)
# 開始 replication
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
# 顯示狀態
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.31
Master_User: replica
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 536
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 600
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 536
Relay_Log_Space: 896
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 101
1 row in set (0.00 sec)
Configure MariaDB Galera Cluster.
All nodes in cluster become Master-Server in this configuration.
[root@client ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 10.0 CentOS repository list
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=0
[root@client ~]# yum --enablerepo=mariadb -y install MariaDB-Galera-server
[root@client ~]# vi /etc/my.cnf.d/server.cnf
# line 19: uncomment and change like follows
[galera]
# Mandatory settings
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
# specify all nodes in cluster
wsrep_cluster_address="gcomm://10.0.0.31,10.0.0.51"
# uncomment all
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# 添加下面
# 定義集羣的名字
wsrep_cluster_name="MariaDB_Cluster"
# ip地址
wsrep_node_address="10.0.0.31"
# replication提供者
wsrep_sst_method=rsync
[root@client ~]# /etc/rc.d/init.d/mysql bootstrap
Bootstrapping the cluster.. Starting MySQL.. SUCCESS!
# 加載基本的信息
[root@client ~]# mysql_secure_installation
[root@node01 ~]# vi /etc/my.cnf.d/server.cnf
# line 19: 更改下面的信息
[galera]
# 強制設置
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
# 指定集羣中的全部節點
wsrep_cluster_address="gcomm://10.0.0.31,10.0.0.51"
#取消
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# 添加信息
# 集羣名稱
wsrep_cluster_name="MariaDB_Cluster"
# IP 地址
wsrep_node_address="10.0.0.51"
# replication 提供者
wsrep_sst_method=rsync
[root@node01 ~]# systemctl start mysql
[root@node01 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.0.20-MariaDB-wsrep MariaDB Server, wsrep_25.10.r4144
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show status like 'wsrep_%';
+------------------------------+--------------------------------------+
| Variable_name | Value |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid | 20329169-3414-11e5-9285-cab5ed757f81 |
| wsrep_protocol_version | 7 |
| wsrep_last_committed | 3 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_received | 3 |
| wsrep_received_bytes | 237 |
| wsrep_local_commits | 0 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_max | 2 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_send_queue_avg | 0.333333 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_max | 1 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_cached_downto | 18446744073709551615 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_sent | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 0.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.000000 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | 0 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_incoming_addresses | 10.0.0.31:3306,10.0.0.51:3306 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | 69d7b95d-3415-11e5-9666-7be9d4b6159d |
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 20329169-3414-11e5-9285-cab5ed757f81 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 1 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 25.3.9(r3387) |
| wsrep_ready | ON |
| wsrep_thread_count | 2 |
+------------------------------+--------------------------------------+
57 ows in set (0.00 sec)