MariaDB之cluster集群

环境 centos8

1.安装最新mariadb 源

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
yum clean all

2.安装mariadb 

yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common  lrzsz -y

3.修改系统参数配置

sudo tee /etc/systemd/system/mariadb.service.d/limitnofile.conf <<EOF
[Service]
LimitNOFILE=1048576
EOF
sudo tee /etc/systemd/system/mariadb.service.d/limitcore.conf <<EOF
[Service]
LimitCORE=infinity
EOF
sudo systemctl daemon-reload
mkdir -pv /data/{mysql,logs/mysql} 
chown mysql.mysql  /data/{mysql,logs/mysql}

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]
binlog_cache_size = 192K
thread_stack = 384K
join_buffer_size = 4096K
query_cache_type = 1
max_heap_table_size = 1024M

port		= 3306
socket		= /var/lib/mysql/mysql.sock
datadir = /data/mysql

default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 512M
max_allowed_packet = 100G
table_open_cache = 1024
sort_buffer_size = 2048K
net_buffer_length = 4K
read_buffer_size = 2048K
read_rnd_buffer_size = 1024K
myisam_sort_buffer_size = 16M
thread_cache_size = 192
query_cache_size = 256M
tmp_table_size = 1024M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


max_connections = 800
max_connect_errors = 100
open_files_limit = 65535

expire_logs_days = 10
#log_queries_not_using_indexes=on


character-set-server=utf8
skip-name-resolve
event_scheduler=1
#skip-grant-tables


innodb_data_home_dir = /data/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql/
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 4
innodb_write_io_threads = 4



#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so

wsrep_cluster_address="gcomm://192.168.17.137,192.168.17.138,192.168.17.129"
wsrep_node_name=m137
wsrep_node_address=192.168.17.137

binlog_format=row
wsrep_auto_increment_control=ON
default_storage_engine=InnoDB
wsrep_cluster_name='cluster'
innodb_autoinc_lock_mode=2
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=120M


#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.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]
autoset_open_files_limit
#enable_slow_query_log

#audit
plugin_load_add=server_audit
server_audit_logging=on
server_audit_events=connect,query
server_audit=force_plus_permanent
server_audit_events=QUERY_DDL,QUERY_DML,CONNECT
server_audit_output_type=file
server_audit_file_rotate_now=on
server_audit_file_rotations=9
server_audit_file_rotate_size=1G
server_audit_file_path=/data/logs/mysql


log_error=/data/logs/mysql/mariadb.err

log_output=FILE
slow_query_log
long_query_time=3
slow_query_log_file=/data/logs/mysql/mariadb-slow.log
log_queries_not_using_indexes=ON  #Logging Queries That Don't Use Indexes



#server_id=2
#log-bin=mysql-bin

# This group is only read by MariaDB-10.5 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.5]

将 server.cnf 复制到 /etc/my.cnf.d/ 目录下

根据实际情况修改参数

vim /etc/my.cnf.d/server.cnf


wsrep_node_name
wsrep_node_address
wsrep_cluster_address
server_id
sed -i 's@^wsrep_cluster_address.*@wsrep_cluster_address="gcomm://10.66.6.201,10.66.6.202,10.66.6.203"@'   /etc/my.cnf.d/server.cnf

初始化新的数据库目录 执行命令 

mysql_install_db --user=mysql

然后随便找一个节点,执行命令   

mysqld_safe --wsrep_cluster_address=gcomm://10.66.6.201,10.66.6.202,10.66.6.203

然后在该节点启动集群,执行命令   

galera_new_cluster

并且在其他节点启动,执行命令 

systemctl start mariadb

进入mysql,查看集群状态

show status like 'wsrep%';

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值