久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

怎么安裝Mysql雙機熱備

149次閱讀
沒有評論

共計 6780 個字符,預計需要花費 17 分鐘才能閱讀完成。

這篇文章主要介紹“怎么安裝 Mysql 雙機熱備”,在日常操作中,相信很多人在怎么安裝 Mysql 雙機熱備問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么安裝 Mysql 雙機熱備”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學習吧!

一、安裝 mysql

#tar -xf mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar 
#yum localinstall *.rpm

1.1 修改 mysql 配置

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
explicit_defaults_for_timestamp=true
tmpdir=/tmp
[client]
default-character-set=utf8mb4
[mysqld]
character_set_server=utf8mb4

1.2 權限修改

[root@172 ~]# chown -R mysql:mysql /data
[root@172 ~]# chmod 777 -R /data/
[root@172 ~]# chmod -R 777 /tmp

1.3 啟動 mysql 服務

[root@172 ~]# service mysqld restart
Stopping mysqld: [FAILED]
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]

1.4 查看 temp 密碼

more /var/log/mysqld.log |grep temporary

1.5 修改 root 密碼 db1

ALTER USER  root @ localhost  IDENTIFIED BY  ***** 
flush privileges;
exit;

db2

ALTER USER  root @ localhost  IDENTIFIED BY  ***** 
flush privileges;
exit;

二、配置主從同步 master1172.28.8.187master2172.28.8.1882.1 配置 master1 給 master2 登錄的密碼

Master1

create user  repl  identified by  ***** 
GRANT REPLICATION SLAVE ON *.* TO  repl @ 172.28.8.188  IDENTIFIED BY  ***** 
FLUSH PRIVILEGES;
mysql  create database mydb default charset utf8;

在 172.28.8.188 測試 repuser 是否能登錄 172.28.8.187 上的數據庫

mysql -urepl -p -h272.28.8.187

2.1.1 Master1 配置 my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
explicit_defaults_for_timestamp=true
tmpdir=/tmp
character_set_server=utf8mb4
server-id=177
log-bin=/var/log/mysql/mysql-bin.log
read-only=0
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
expire_logs_days= 365
auto-increment-increment = 2
auto-increment-offset = 1
[client]
default-character-set=utf8mb4

2.2 Master2 配置 my.cnf

# 除 server-id 外,其他與 master1 保持一致 

2.2.1 Master2 給 Master1 創建賬號密碼并授權

create user  repl  identified by  ***** 
GRANT REPLICATION SLAVE ON *.* TO  repl @ 172.28.8.187  IDENTIFIED BY  ***** 
FLUSH PRIVILEGES;

2.3 查看 Master 同步狀態

master1

mysql  show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000001 | 154 | mydb | mysql,information_schema | |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

master2

mysql  show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000001 | 154 | mydb | mysql,information_schema | |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

設置 master1 從 master2 同步

mysql CHANGE MASTER TO MASTER_HOST= 172.28.8.188 ,MASTER_PORT=3306,MASTER_USER= repl ,MASTER_PASSWORD= b4l:GGtG3s0* ,MASTER_LOG_FILE= mysql-bin.000002 ,MASTER_LOG_POS=860;
mysql  SHOW SLAVE STATUS\G
mysql  START SLAVE;
mysql  SHOW SLAVE STATUS\G

設置 master2 從 master1 同步

mysql CHANGE MASTER TO MASTER_HOST= 172.28.8.187 ,MASTER_PORT=3306,MASTER_USER= repl ,MASTER_PASSWORD= 2S1*8pr+BzqH^8T` ,MASTER_LOG_FILE= mysql-bin.000003 ,MASTER_LOG_POS=1497;
mysql  SHOW SLAVE STATUS\G
mysql  START SLAVE;
mysql  SHOW SLAVE STATUS\G

如出現以下兩項,則說明配置成功!

 Slave_IO_Running: Yes
 Slave_SQL_Running: Yes

3. 雙主同步測試

進入 master1 mysql 數據庫

mysql  create database crm;
Query OK, 1 row affected (0.00 sec)
mysql  use crm;
Database changed
mysql  create table employee(id int auto_increment,name varchar(10),primary key(id));
Query OK, 0 rows affected (0.00 sec)
mysql  insert into employee(name) values( a 
Query OK, 1 row affected (0.00 sec)
mysql  insert into employee(name) values( b 
Query OK, 1 row affected (0.00 sec)
mysql  insert into employee(name) values( c 
Query OK, 1 row affected (0.06 sec)
mysql  select * from employee;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 3 | b |
| 5 | c |
+----+------+
3 rows in set (0.00 sec)

進入 master2,查看是否有 crm 這個數據庫和 employee 表。

mysql  show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crm |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
mysql  use crm;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql  show tables;
+---------------+
| Tables_in_crm |
+---------------+
| employee |
+---------------+
1 row in set (0.00 sec)
mysql  select * from employee;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 3 | b |
| 5 | c |
+----+------+
3 rows in set (0.00 sec)
mysql  insert into employee(name) values( d 
Query OK, 1 row affected (0.00 sec)
mysql  select * from employee;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 3 | b |
| 5 | c |
| 7 | d |
+----+------+
4 rows in set (0.00 sec)

在 master1 的中查看是否有剛剛在 master2 中插入的數據。

mysql  select * from employee;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 3 | b |
| 5 | c |
| 7 | d |
+----+------+
4 rows in set (0.00 sec)

到此,關于“怎么安裝 Mysql 雙機熱備”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注丸趣 TV 網站,丸趣 TV 小編會繼續努力為大家帶來更多實用的文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-19發表,共計6780字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 平远县| 安仁县| 行唐县| 曲水县| 洞口县| 澄迈县| 大埔县| 山西省| 南投市| 博白县| 铜陵市| 伽师县| 望江县| 云南省| 和顺县| 饶平县| 西盟| 湘乡市| 桃园市| 尚志市| 平邑县| 高清| 安泽县| 彭山县| 基隆市| 民丰县| 徐州市| 永泰县| 蒙山县| 靖安县| 光泽县| 肇庆市| 蕲春县| 宁乡县| 桂阳县| 扎鲁特旗| 剑阁县| 平果县| 交口县| 项城市| 海安县|