<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
hostname | IP地址 | 系統版本 | 角色 |
---|---|---|---|
master | 192.168.3.171 | centos 7.6 | 主節點 |
node01 | 192.168.3.172 | centos 7.6 | 從節點 |
node02 | 192.168.3.173 | centos 7.6 | 從節點 |
主從同步使得資料可以從一個資料庫伺服器複製到其他伺服器上,在複製資料時,一個伺服器充當主伺服器(master),其餘的伺服器充當從伺服器(slave)。
半同步複製是解決主庫資料掛掉,從庫資料不一致的問題。 解決方法:半同步複製,半同步複製場景中,master會監視所有的slave,確保其中至少一臺資料完全同步成功,master才會返回使用者端資訊,此資料寫成功。
3個節點都安裝Mariadb資料庫
[root@master yum.repos.d]# cat mariadb.repo # MariaDB 10.6 CentOS repository list - created 2021-12-27 11:21 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.6/centos7-amd64 gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=0
sed -i 's#//mirrors.xtom.com.hk#//mirrors.ustc.edu.cn#g' /etc/yum.repos.d/mariadb.repo
[root@master yum.repos.d]# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status mariadb MariaDB enabled: 96 repolist: 96
yum -y install mariadb-server
[root@master yum.repos.d]# systemctl start mariadb [root@master yum.repos.d]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@master yum.repos.d]#
如上步驟安裝即可。
[root@master ~]# mariadb-secure-installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n ... skipping. By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! [root@master ~]#
[root@master ~]# grep -Ev "^$|^#" /etc/my.cnf.d/server.cnf [server] [mysqld] character-set-server=utf8 collation-server=utf8_general_ci server_id = 12 # 一組主從組裡的每個id必須是唯一值。推薦用ip位數 log-bin= mysql-bin # 二進位制紀錄檔,後面指定存放位置。如果只是指定名字,預設存放在/var/lib/mysql下 lower_case_table_names=1 # 不區分大小寫 binlog-format=ROW # 二進位制紀錄檔檔案格式 log-slave-updates=True # slave更新是否記入紀錄檔 sync-master-info=1 # 值為1確保資訊不會丟失 slave-parallel-threads=3 #同時啟動多少個複製執行緒,最多與要複製的資料庫數量相等即可 binlog-checksum=CRC32 # 效驗碼 master-verify-checksum=1 # 啟動主伺服器效驗 slave-sql-verify-checksum=1 # 啟動從伺服器效驗 [galera] [embedded] [mariadb] [mariadb-10.6] [root@master ~]#
[root@master ~]# systemctl restart mariadb [root@master ~]#
[root@node01 ~]# cat /etc/my.cnf.d/server.cnf # # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon [mysqld] character-set-server=utf8 collation-server=utf8_general_ci server_id=15 #log-bin= mysql-bin #log-bin是二進位制檔案 relay_log = relay-bin # 中繼紀錄檔, 後面指定存放位置。如果只是指定名字,預設存放在/var/lib/mysql下 lower_case_table_names=1 # # * Galera-related settings # [galera] # Mandatory settings #wsrep_on=ON #wsrep_provider= #wsrep_cluster_address= #binlog_format=row #default_storage_engine=InnoDB #innodb_autoinc_lock_mode=2 # # Allow server to accept connections on all interfaces. # #bind-address=0.0.0.0 # # Optional setting #wsrep_slave_threads=1 #innodb_flush_log_at_trx_commit=0 # this is only for embedded server [embedded] # This group is only read by MariaDB servers, not by MySQL. # If you use the same .cnf file for MySQL and MariaDB, # you can put MariaDB-only options here [mariadb] # This group is only read by MariaDB-10.6 servers. # If you use the same .cnf file for MariaDB of different versions, # use this group for options that older servers don't understand [mariadb-10.6]
[root@node02 ~]# cat /etc/my.cnf.d/server.cnf # # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon [mysqld] character-set-server=utf8 collation-server=utf8_general_ci server_id=16 #log-bin= mysql-bin #log-bin是二進位制檔案 relay_log = relay-bin # 中繼紀錄檔, 後面指定存放位置。如果只是指定名字,預設存放在/var/lib/mysql下 lower_case_table_names=1 # # * Galera-related settings # [galera] # Mandatory settings #wsrep_on=ON #wsrep_provider= #wsrep_cluster_address= #binlog_format=row #default_storage_engine=InnoDB #innodb_autoinc_lock_mode=2 # # Allow server to accept connections on all interfaces. # #bind-address=0.0.0.0 # # Optional setting #wsrep_slave_threads=1 #innodb_flush_log_at_trx_commit=0 # this is only for embedded server [embedded] # This group is only read by MariaDB servers, not by MySQL. # If you use the same .cnf file for MySQL and MariaDB, # you can put MariaDB-only options here [mariadb] # This group is only read by MariaDB-10.6 servers. # If you use the same .cnf file for MariaDB of different versions, # use this group for options that older servers don't understand [mariadb-10.6]
systemctl restart mariadb
MariaDB [(none)]> grant replication slave, replication client on *.* to 'redhat'@'%' identified by 'admin'; Query OK, 0 rows affected (0.025 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> select user,password,host from mysql.user; +-------------+-------------------------------------------+-----------+ | User | Password | Host | +-------------+-------------------------------------------+-----------+ | mariadb.sys | | localhost | | root | invalid | localhost | | mysql | invalid | localhost | | redhat | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | % | +-------------+-------------------------------------------+-----------+ 4 rows in set (0.002 sec) MariaDB [(none)]>
MariaDB [(none)]> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000002 | 659 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.000 sec) MariaDB [(none)]>
[root@master ~]# ll /var/lib/mysql/mysql-bin.index -rw-rw----. 1 mysql mysql 38 Nov 23 23:31 /var/lib/mysql/mysql-bin.index [root@master ~]# cat /var/lib/mysql/mysql-bin.index ./mysql-bin.000001 ./mysql-bin.000002
MariaDB [(none)]> select binlog_gtid_pos('mysql-bin.000002',659); +-----------------------------------------+ | binlog_gtid_pos('mysql-bin.000002',659) | +-----------------------------------------+ | 0-12-2 | +-----------------------------------------+ 1 row in set (0.000 sec) MariaDB [(none)]>
MariaDB [(none)]> set global gtid_slave_pos='0-12-2'; Query OK, 0 rows affected (0.080 sec)
MariaDB [(none)]> change master to master_host='192.168.3.171',master_user='redhat',master_password='admin',master_use_gtid=slave_pos; Query OK, 0 rows affected (0.182 sec)
MariaDB [(none)]> start slave; Query OK, 0 rows affected (0.123 sec)
MariaDB [(none)]> show slave statusG *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.3.171 Master_User: redhat Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 1450 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 1461 Relay_Master_Log_File: mysql-bin.000002 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: 1450 Relay_Log_Space: 1764 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: 12 Master_SSL_Crl: Master_SSL_Crlpath: Using_Gtid: Slave_Pos Gtid_IO_Pos: 0-12-7 Replicate_Do_Domain_Ids: Replicate_Ignore_Domain_Ids: Parallel_Mode: optimistic SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Slave_DDL_Groups: 3 Slave_Non_Transactional_Groups: 2 Slave_Transactional_Groups: 0 1 row in set (0.000 sec) MariaDB [(none)]>
MariaDB [(none)]> create database school; Query OK, 1 row affected (0.001 sec) MariaDB [(none)]> use school; Database changed MariaDB [school]> CREATE TABLE IF NOT EXISTS `student`( -> `id` INT UNSIGNED AUTO_INCREMENT, -> `name` VARCHAR(100) NOT NULL, -> `gender` TINYINT NOT NULL, -> `age` INT UNSIGNED, -> `class` INT UNSIGNED, -> `course` VARCHAR(100) NOT NULL, -> `grade` INT UNSIGNED, -> PRIMARY KEY ( `id` ) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.206 sec) MariaDB [school]> insert into student ( name, gender, age, class, Course, grade ) values ( "高峰", "0", "22", "4", "英語", "100"), ( "陳林", "1", "15", "5", "化學", "99" ); Query OK, 2 rows affected (0.012 sec) Records: 2 Duplicates: 0 Warnings: 0 MariaDB [school]> insert into student ( name, gender, age, class, course, grade ) values ( "王明", "0", "16", "2", "數學", "88"), ( "萬易", "0", "17", "4", "地理", "79" ), ( "李依依", "1", "17", "3", "語文", "90" ) ; Query OK, 3 rows affected (0.017 sec) Records: 3 Duplicates: 0 Warnings: 0
MariaDB [school]> select * from school.student; +----+-----------+--------+------+-------+--------+-------+ | id | name | gender | age | class | course | grade | +----+-----------+--------+------+-------+--------+-------+ | 1 | 高峰 | 0 | 22 | 4 | 英語 | 100 | | 2 | 陳林 | 1 | 15 | 5 | 化學 | 99 | | 3 | 王明 | 0 | 16 | 2 | 數學 | 88 | | 4 | 萬易 | 0 | 17 | 4 | 地理 | 79 | | 5 | 李依依 | 1 | 17 | 3 | 語文 | 90 | +----+-----------+--------+------+-------+--------+-------+ 5 rows in set (0.000 sec) MariaDB [school]>
[root@node01 ~]# hostname node01 [root@node01 ~]# mariadb Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 12 Server version: 10.6.11-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]> select * from school.student; +----+-----------+--------+------+-------+--------+-------+ | id | name | gender | age | class | course | grade | +----+-----------+--------+------+-------+--------+-------+ | 1 | 高峰 | 0 | 22 | 4 | 英語 | 100 | | 2 | 陳林 | 1 | 15 | 5 | 化學 | 99 | | 3 | 王明 | 0 | 16 | 2 | 數學 | 88 | | 4 | 萬易 | 0 | 17 | 4 | 地理 | 79 | | 5 | 李依依 | 1 | 17 | 3 | 語文 | 90 | +----+-----------+--------+------+-------+--------+-------+ 5 rows in set (0.000 sec) MariaDB [(none)]>
以上就是Mariadb資料庫主從複製同步設定過程範例的詳細內容,更多關於Mariadb主從複製同步設定的資料請關注it145.com其它相關文章!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45