點(diǎn)擊上方“IT那活兒”公眾號(hào),關(guān)注后了解更多內(nèi)容,不管IT什么活兒,干就完了?。?!
部署安裝
1.1 獲取安裝介質(zhì)
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
1.2 創(chuàng)建用戶
groupaddmysql
useradd-r -g mysql -s /bin/false mysql
1.3 解壓安裝包
cd/usr/local
chown-R mysql:mysql mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
tar-xvf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
chown-R mysql:mysql mysql-8.0.23-linux-glibc2.12-x86_64
ln-s mysql-8.0.23-linux-glibc2.12-x86_64 mysql
chown-R mysql:mysql mysql
1.4 創(chuàng)建數(shù)據(jù)文件目錄
mkdir-p /mysqldata/data
mkdir-p /mysqldata/log
mkdir-p /mysqldata/sys
chown-R mysql:mysql /mysqldata/
chmod-R 750 /mysqldata/
1.5 配置環(huán)境變量(寫(xiě)到/etc/profile)
exportPATH=/usr/local/mysql/bin:$PATH
source/etc/profile
1.6 編輯參數(shù)文件
主庫(kù)
vi/etc/my.cnf
[mysql]
prompt=[u@h][d]>\_
socket=/mysqldata/sys/mysql.sock
[mysqld]
user=mysql
datadir=/mysqldata/data/
socket=/mysqldata/sys/mysql.sock
character_set_server=utf8mb4
transaction_isolation=read-committed
explicit_defaults_for_timestamp=1
max_allowed_packet=16777216
event_scheduler=1
server_id=212211
lower_case_table_names=1
interactive_timeout=1800
wait_timeout=1800
skip_name_resolve=1
max_connections=2000
max_connect_errors=100000
table_open_cache=4096
table_definition_cache=4096
table_open_cache_instances=64
read_buffer_size=6M
read_rnd_buffer_size=16M
sort_buffer_size=16M
tmp_table_size=64M
join_buffer_size=64M
thread_cache_size=64
log_error=/mysqldata/log/alert.log
log_bin=/mysqldata/log/binlog
master_info_repository=table
relay_log_info_repository=table
sync_binlog=1
gtid_mode=on
enforce_gtid_consistency=1
log_slave_updates=1
binlog_format=row
binlog_rows_query_log_events=1
relay_log=/mysqldata/log/relay.log
relay_log_recovery=1
#slave_rows_search_algorithms=index_scan,hash_scan
innodb_buffer_pool_size=16G
innodb_buffer_pool_instances=4
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_lru_scan_depth=2048
innodb_flush_method=o_direct
innodb_open_files=4096
innodb_log_file_size=1024000000
從庫(kù)的參數(shù)基本上跟主庫(kù)的參數(shù)一致,只需要改變一個(gè)server_id,這個(gè)配置雙主的時(shí)候不能一樣。
1.7 初始化數(shù)據(jù)庫(kù)
cd/usr/local/mysql
bin/mysqld--initialize --lower-case-table-names=1 -user=mysql
1.8 啟動(dòng)數(shù)據(jù)庫(kù)
cd/usr/local/mysql
bin/mysqld_safe--user=mysql &
1.9 進(jìn)入mysql修改密碼
mysql-uroot -p(初始密碼在error.log里)
VKgfkfqUA0,7
alteruser root@localhost identified by My1qaz@WSX;
flushprivileges;
1.10 添加服務(wù)到系統(tǒng)
cd/usr/local/mysql
cpsupport-files/mysql.server /etc/init.d/mysql
chmod+x /etc/init.d/mysql
chkconfig--add mysql
chkconfig--list mysql
1.11 測(cè)試
servicemysql start
雙主配置
2.1 192.168.245.138->192.168.245.139方向
1)創(chuàng)建復(fù)制用戶(主庫(kù):192.168.245.138)
createuser repl@% identified with mysql_native_password by "2w3e@W#E";
grantfile on *.* to repl@%;
grantreplication slave on *.* to repl@%;
flushprivileges;
2)開(kāi)啟復(fù)制進(jìn)程(從庫(kù):192.168.245.139)
changemaster
tomaster_host=192.168.245.138,master_port=3306,master_user
=repl,master_password=2w3e@W#E,master_auto_position=1;
startslave;
3)檢查slave狀態(tài)
showslave statusG
2.2 192.168.245.139->192.168.245.138方向
1)創(chuàng)建復(fù)制用戶(主庫(kù):192.168.245.139)
createuser sysadmin@% identified with mysql_native_password by"1q2w!Q@W";
grantall on *.* to sysadmin@%;
flushprivileges;
2)開(kāi)啟復(fù)制進(jìn)程(從庫(kù):192.168.245.138)
changemaster tomaster_host=192.168.245.139,master_port=3306,master_user=repl,master_password=2w3e@W#E,master_auto_position=1;
startslave;
3)檢查slave狀態(tài)
showslave statusG
測(cè)試
3.1 192.168.245.138->192.168.245.139方向
192.168.245.138:
CREATEDATABASE `gohealth-plat` CHARACTER SET utf8mb4 COLLATEutf8mb4_general_ci;
usegohealth-plat;
createtable product(
product_idint(10) not NULL,
product_namevarchar(100) not NULL,
product_tyepvarchar(32) not NULL,
sale_priceint(10) default 0,
input_priceint(10) default 0,
regist_timedate,
primarykey (product_id));
192.168.245.139:
showdatabases;
usegohealth-plat;
showtables;
3.2 192.168.245.139->192.168.245.138方向
192.168.245.139:
usegohealth-plat;
insertinto product values(555,sdfsd,sdfd,54,215,null);
select* from product;
192.168.245.138:
select* from product;
MySQL軟件安裝以及雙主配置還是非常簡(jiǎn)單的,如果在啟動(dòng)復(fù)制過(guò)程中報(bào)錯(cuò),可以使用showslave status進(jìn)行查看是什么原因?qū)е碌?,好了,今天的分享就到此結(jié)束了!!
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/129271.html
摘要:雙主是一個(gè)比較簡(jiǎn)單的高可用架構(gòu),適用于中小集群,今天就說(shuō)說(shuō)怎么用做的高可用。缺點(diǎn)也比較明顯,就是增加從節(jié)點(diǎn)的情況下,從節(jié)點(diǎn)不會(huì)主動(dòng)切換同步對(duì)象,而且腳本需要自己實(shí)現(xiàn),有一定風(fēng)險(xiǎn)。 雙主 + keepalived 是一個(gè)比較簡(jiǎn)單的 MySQL 高可用架構(gòu),適用于中小 MySQL 集群,今天就說(shuō)說(shuō)怎么用 keepalived 做 MySQL 的高可用。 1 概述 1.1 keepalive...
摘要:雙主是一個(gè)比較簡(jiǎn)單的高可用架構(gòu),適用于中小集群,今天就說(shuō)說(shuō)怎么用做的高可用。缺點(diǎn)也比較明顯,就是增加從節(jié)點(diǎn)的情況下,從節(jié)點(diǎn)不會(huì)主動(dòng)切換同步對(duì)象,而且腳本需要自己實(shí)現(xiàn),有一定風(fēng)險(xiǎn)。 雙主 + keepalived 是一個(gè)比較簡(jiǎn)單的 MySQL 高可用架構(gòu),適用于中小 MySQL 集群,今天就說(shuō)說(shuō)怎么用 keepalived 做 MySQL 的高可用。 1 概述 1.1 keepalive...
閱讀 1357·2023-01-11 13:20
閱讀 1707·2023-01-11 13:20
閱讀 1215·2023-01-11 13:20
閱讀 1907·2023-01-11 13:20
閱讀 4165·2023-01-11 13:20
閱讀 2758·2023-01-11 13:20
閱讀 1402·2023-01-11 13:20
閱讀 3673·2023-01-11 13:20