赞
踩
IP | 类型 |
---|---|
20.0.0.11 | mysql1 |
20.0.0.12 | mysql2 |
20.0.0.13 | mysql3 |
20.0.0.14 | haproxy+keepalived |
20.0.0.15 | haproxy+keepalived |
清除残留数据库
#卸载mariadb和mysql
rpm -qa | grep mariadb | xargs rpm -e --nodeps
rpm -qa | grep mysql | xargs rpm -e --nodeps
20.0.0.11 hostnamectl set-hostname mysql1
20.0.0.12 hostnamectl set-hostname mysql2
20.0.0.13 hostnamectl set-hostname mysql3
bash
vim /etc/hosts
---------------------------
20.0.0.11 mysql1
20.0.0.12 mysql2
20.0.0.13 mysql3
三台服务器互相ping命令测试配置情况
ping mysql1
ping mysql2
ping mysql3
#每台都做
ssh-keygen -t rsa
ssh-copy-id mysql1
ssh-copy-id mysql2
ssh-copy-id mysql3
## 在mysql1上确定免密是否完成
ssh mysql2
ssh mysql3
tar xf mysql-8.0.28-el7-x86_64.tar.gz
mv mysql-8.0.28-el7-x86_64 mysql
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir /data/mysql/data
mkdir /data/mysql/logs
chown -R mysql:mysql /data/mysql
因环境问题后面有的配置需要添加;
innodb_buffer_pool_size = 20G 参数需修改
32G的内存填写20G,视内存大小修改
cat << EOF > /etc/my.cnf [mysqld] basedir=/data/mysql datadir=/data/mysql/data log-error=/data/mysql/logs/mysql.log socket=/tmp/mysql.sock pid-file=/tmp/mysql.pid event_scheduler=ON #慢查询sql日志设置 slow_query_log=ON slow_query_log_file=/data/mysql/logs/mysql-slow.log long_query_time=1 #作为从库时生效,从库复制中如何有慢sql也将被记录 #log_slow_replica_statements = 1 #检索的行数必须达到此值才可被记为慢查询 min_examined_row_limit = 100 #mysql binlog日志文件保存的过期时间,过期后自动删除 binlog_expire_logs_seconds = 7 #Mysql服务的唯一编号 每个mysql服务Id需唯一 server-id = 3 log_bin = binlog # 跳过密码登录 #skip-grant-tables #只能用IP地址检查客户端的登录,不用主机名 skip-name-resolve #skip-external-locking #最大连接数 max_connections = 100000 #最大错误连接数 max_connect_errors = 50000 # MySQL能有的连接数量 back_log = 600 # MySQL打开的文件描述符限制 open_files_limit = 65535 innodb_open_files = 5000 # 限制Innodb能打开的表的数据,如果库里的表特别多的情况,请增加这个。这个值默认是300 innodb_buffer_pool_size = 20G # InnoDB使用一个缓冲池来保存索引和原始数据, 不像MyISAM. # 这里你设置越大,你在存取表里面数据时所需要的磁盘I/O越少. #开启GTID,必须开启 gtid_mode=on enforce-gtid-consistency=on binlog_format=ROW transaction_isolation = READ-COMMITTED #log-replica-updates=1 binlog_checksum=NONE master_info_repository=TABLE relay_log_info_repository=TABLE #group_replication_member_expel_timeout=10 #group_replication_autorejoin_tries=10 transaction_write_set_extraction = XXHASH64 #replica_preserve_commit_order = ON binlog_transaction_dependency_tracking = WRITESET #replica_parallel_type=LOGICAL_CLOCK #replica_parallel_workers=4 master_info_repository=TABLE relay_log_info_repository=TABLE relay_log_recovery=ON disabled_storage_engines = MyISAM,BLACKHOLE,FEDERATED,CSV,ARCHIVE character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect='SET NAMES utf8mb4' lower_case_table_names = 1 tmp_table_size = 512M read_buffer_size = 32M read_rnd_buffer_size = 64M sort_buffer_size = 32M join_buffer_size = 16M thread_cache_size = 128 table_open_cache = 256 max_allowed_packet = 512M binlog_cache_size = 1M max_heap_table_size = 512M key_buffer_size = 1024M default-storage-engine = InnoDB innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_use_native_aio = 1 innodb_flush_log_at_trx_commit = 1 sync_binlog=1 innodb_log_buffer_size = 12M innodb_log_file_size = 128M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 80 innodb_lock_wait_timeout = 120 interactive_timeout = 28800 wait_timeout = 28800 explicit_defaults_for_timestamp = true innodb_io_capacity=200 innodb_data_file_path=ibdata1:1024M:autoextend log_queries_not_using_indexes = 1 log_throttle_queries_not_using_indexes = 5 EOF ====================================================== 如创建集群有如下图报错的话,需在末尾添加配置: loose-group_replication_group_name =“a38e32fd-5fb6-11e8-ad7a-00259015d941” ###设置组名,随便起,但是不能与UUID重复 loose-group_replication_start_on_boot =OFF ###为了避免每次启动自动引导具有相同名称的第二个组,所以设置为OFF。 loose-group_replication_bootstrap_group =OFF ###同上 loose-group_replication_local_address =“20.0.0.11:33061” ###设置成员的本地地址,不同节点此处要修改为相应的IP地址 loose-group_replication_group_seeds =“20.0.0.11:33061,20.0.0.12:33061,20.0.0.13:33061” ###设置种子成员的地址 loose-group_replication_ip_whitelist = '127.0.0.1/8,20.0.0.0/24'
## 初始化并后台启动 cd mysql/bin/ ./mysqld --initialize --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data ./mysqld_safe --defaults-file=/etc/my.cnf & ## 获取密码 grep 'password' /data/mysql/logs/mysql.log | awk '{print $NF}' ## 登陆了mysql并修改命令 ./mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'kangwen@123'; update mysql.user set host='%' where user='root'; flush privileges; ## 创建集群所需授权 GRANT CLONE_ADMIN, CONNECTION_ADMIN, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, REPLICATION_APPLIER, REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'root'@'%' WITH GRANT OPTION;
rpm -ivh mysql-shell-8.0.28-1.el7.x86_64.rpm
## 从mysql1 上进入mysqlshell命令模式,
mysqlsh --uri root@mysql1:3306
## 创建集群
var cluster=dba.createCluster("MySQL_InnoDB_Cluster")
mysql
节点cluster.addInstance('root@mysql2:3306')
cluster.addInstance('root@mysql3:3306')
查看集群状态
cluster.status()
cluster.switchToMultiPrimaryMode()
if ! grep /data/mysql /etc/profile then cat >> /etc/profile << EOF export MYSQL_HOME=/data/mysql export PATH="$PATH:$MYSQL_HOME/bin" EOF fi source /etc/profile #重启mysql并设置为开机自启动 if [ ! -e /etc/init.d/mysqld ] then cp -a /data/mysql/support-files/mysql.server /etc/init.d/mysqld fi #开机自启 chkconfig --add /etc/init.d/mysqld chkconfig mysqld on ##重启命令 service mysqld stop service mysqld start
mysqlsh --uri root@mysql1:3306 #进入mysqlshell
shell.connect('root@mysql1:3306') #连接到实例
var cluster = dba.getCluster() #定义集群信息
cluster.status();
命令 | 用途 |
---|---|
dba.getCluster(); | 查看集群名 |
cluster.status(); | 查看集群状态 |
dba.checkInstanceConfiguration(‘root@mysql1:3306’) | 检查节点状态是否正常 |
dba.configureLocalInstance(); | 检查/etc/my.cnf是否正常 |
var cluster = dba.createCluster(‘myCluster’); | 创建一个名为myCluster的集群 |
dba.createCluster(‘st’); | 创建一个名字为st的集群 |
cluster.addInstance(‘root@oratest52:3306’); | 集群添加节点 |
cluster.switchToMultiPrimaryMode() | 切换多主模式 |
命令 | 别名/快捷方式 | 用法 |
---|---|---|
\help | \h or ? | 打印有关MySQL Shell的帮助,或搜索联机帮助 |
\quit | \q or \exit | 退出MySQL Shell |
\ | 在SQL模式下,开始多行模式。输入空行时缓存并执行代码 | |
\status | \s | 显示当前的MySQL Shell状态 |
\js | 将执行模式切换为JavaScript | |
\py | 将执行模式切换为Python | |
\sql | 将执行模式切换为SQL | |
\connect | \c | 连接到MySQL服务器 |
\reconnect | 重新连接到同一个MySQL服务器 | |
\use | \u | 指定要使用的架构 |
\source | . | 使用活动语言执行脚本文件 |
\warnings | \W | 显示语句生成的任何警告 |
\nowarnings | \w | 不要显示语句生成的任何警告 |
\history | 查看和编辑命令行历史记录 | |
\rehash | 手动更新自动完成名称缓存 | |
\option | 查询和更改MySQL Shell配置选项 | |
\show | 使用提供的选项和参数运行指定的报告 | |
\watch | 使用提供的选项和参数运行指定的报告,并定期刷新结果 |
当集群的所有节点都offline,直接获取集群信息失败,如何重新恢复集群
MySQL mysql1:3306 ssl JS > var cluster = dba.getCluster()
Dba.getCluster: This function is not available through a session to a standalone instance (metadata exists, instance belongs to that metadata, but GR is not active) (MYSQLSH 51314)
MySQL mysql1:3306 ssl JS > cluster.status();
TypeError: Cannot read property 'status' of undefined
执行rebootClusterFromCompleteOutage命令,可恢复集群
MySQL mysql1:3306 ssl JS > dba.rebootClusterFromCompleteOutage('MySQL_InnoDB_Cluster')
Restoring the cluster 'MySQL_InnoDB_Cluster' from complete outage...
The instance 'mysql2:3306' was part of the cluster configuration.
Would you like to rejoin it to the cluster? [y/N]: y
The instance 'mysql3:3306' was part of the cluster configuration.
Would you like to rejoin it to the cluster? [y/N]: y
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。