麒麟v10 上部署 TiDB v5.1.2 生产环境优化实践
1000
2023-04-07
构建 MariaDB Galera Cluster 分布式数据库集群(二)
MariaDB的安装
构建 MariaDB Galera Cluster之前,首先安装MariaDB,本文使用的版本是10.1
1.环境准备
主机:
MariaDB01(192.168.56.102)MariaDB02(192.168.56.103)MariaDB03(192.168.56.104)
OS: centos6.5MariaDB版本:10.1
yum源设置Here is your custom MariaDB YUM repository entry for CentOS. Copy and paste it into a file under /etc/yum.repos.d/ (we suggest naming the file MariaDB.repo or something similar). See "Installing MariaDB with yum" for detailed information.#翻译:这是您CentOS的自定义MariaDB YUM存储库条目。 将它复制并粘贴到/etc/yum.repos.d/下的文件(我们建议命名文件MariaDB.repo或类似的东西)。 有关详细信息,请参阅“使用yum安装MariaDB”。
然后执行下列命令导入证书并更新repo
如果你对网络质量充满信心,你现在就可以进入第二步的安装maridb了,但是我强烈建议你用下面的这个方法,因为你可能要反复测试重装个几次,毕竟每次都从官网下载不是一件高效的事儿。
2.安装maridb
yum install MariaDB-server MariaDB-client
官网还提供了MariaDB Enterprise Cluster 5.5的安装方法,不是本文的重点,直接跳过。值得注意的是,如果你要安装5.5版本,则后面的cluster集群的安装配置和10.1版本下是完全不一样的,需要高度注意,避免发生混淆和错误。
3.创建执行用户
# groupadd mariadb# useradd -g mariadb mariadb# passwd mariadb# echo 'mariadb ALL=(ALL) ALL' >> /etc/sudoers# cd /var/lib# chown -R mariadb:mariadb mysql
4.启动maridb服务
请根据自身系统版本,选择适合的启动方法启动即可。本文安装环境是在centos6.5下,按照4.3进行启动
4.1:On RHEL and CentOS starting with version 7 using systemd, start MariaDB like this: (通过systemd启动mariadb)# systemctl start mariadb.service
4.2:or on RHEL and CentOS starting with version 7 using systemd, bootstrap the first node of a MariaDB Enterprise Cluster like this:# galera_new_cluster
4.3:or on RHEL and CentOS before version 7, such as centos6.5, start MariaDB like this:(在centos6.5上仍然按照启动mysql的方法启动mariadb)
# service mysql start
启动时可能会遇到下列错误:Starting MySQL.161222 11:28:27 mysqld_safe Logging to '/var/lib/mysql/MariaDB03.err'. ERROR! #检查是由于/var/lib/mysql/MariaDB03.err权限的问题,需要执行 su mariadb,在mariadb用户下启动服务
[root@MariaDB03 ~]# cat /var/lib/mysql/MariaDB03.err161222 11:28:27 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql2016-12-22 11:28:27 140570816137248 [Note] /usr/sbin/mysqld (mysqld 10.1.18-MariaDB) starting as process 3650 ...2016-12-22 11:28:27 140570816137248 [ERROR] mysqld: File '/var/lib/mysql/aria_log_control' not found (Errcode: 13 "Permission denied")2016-12-22 11:28:27 140570816137248 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/var/lib/mysql/aria_log_control'2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'Aria' init function returned error.2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using mutexes to ref count buffer pool pages2016-12-22 11:28:27 140570816137248 [Note] InnoDB: The InnoDB memory heap is disabled2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2016-12-22 11:28:27 140570816137248 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Compressed tables use zlib 1.2.32016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using Linux native AIO2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using SSE crc32 instructions2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Initializing buffer pool, size = 128.0M2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Completed initialization of buffer pool2016-12-22 11:28:27 140570816137248 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode2016-12-22 11:28:27 140570816137248 [ERROR] InnoDB: The system tablespace must be writable!2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'InnoDB' init function returned error.2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.2016-12-22 11:28:27 140570816137248 [Note] Plugin 'FEEDBACK' is disabled.2016-12-22 11:28:27 140570816137248 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded2016-12-22 11:28:27 140570816137248 [ERROR] Unknown/unsupported storage engine: Inno***016-12-22 11:28:27 140570816137248 [ERROR] Aborting161222 11:28:27 mysqld_safe mysqld from pid file /var/lib/mysql/MariaDB03.pid en# su mariadb$ service mysql start
4.4:or on RHEL and CentOS before version 7, bootstrap the first node of a MariaDB Enterprise Cluster like this:service mysql bootstrap
5.初始化maridb数据库
在mariadb@MariaDB01 至 mariadb@MariaDB03上分别初始化msyql
[mariadb@MariaDB01 root]# su mariadb$ sudo mysql_secure_installation
>根据提示进行操作>由于是测试,密码推荐设置为空,便于后面的操作,正式用的时候再修改密码>一定要设置不允许root远程访问,这是起码的操守,不要再问为什么了,因为以后也不会再去改它了吧
5.防火墙设置
centos6,root下执行
# iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT# iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT
如果在centos7下,诸如这样执行:
# firewall-cmd --add-port=3306/tcp #暂时生效,重启后失效# firewall-cmd --permanent --add-port=3306/tcp #永久生效
正式环境务必要配置防火墙的,尤其对于研发的人来说,一定要重视这个问题如测试用,可关闭防火墙,忽略此配置即可
6.mysql管理和监控工具
MySQL免费性能监控工具-MONyog 分linux和windows版SQLyog数据库管理 只有windows版上面的工具说实话我没用过,我更习惯用nginx/zabbix进行监控,用navicat进行管理
7.使用
安装完了,简单测试下吧
[mariadb@MariaDB01 my.cnf.d]$ mysql -uroot -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 9Server version: 10.1.18-MariaDB MariaDB ServerCopyright (c) 2000, 2016, ***, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#看看集群的状态如何
MariaDB [(none)]> show status like 'wsrep%';+--------------------------+----------------------+| Variable_name | Value |+--------------------------+----------------------+| wsrep_cluster_conf_id | 18446744073709551615 || wsrep_cluster_size | 0 || wsrep_cluster_state_uuid | || wsrep_cluster_status | Disconnected || wsrep_connected | OFF || wsrep_local_bf_aborts | 0 || wsrep_local_index | 18446744073709551615 || wsrep_provider_name | || wsrep_provider_vendor | || wsrep_provider_version | || wsrep_ready | OFF || wsrep_thread_count | 0 |+----------------------MariaDB [(none)]> show variables like 'wsrep_cluster_address';+-----------------------+------------------------------------------------------+| Variable_name | Value |+-----------------------+------------------------------------------------------+| wsrep_cluster_address | gcomm://192.168.56.102,192.168.56.103,192.168.56.104 | #这个展示是已经配置过集群的,初始安装的这里显示的应该是空,不要被误导啊!+-----------------------+------------------------------------------------------+1 row in set (0.00 sec)
现在还只是个MariaDB10.1的环境,要完成MariaDB Galera Cluster请继续看下一章内容
-本章完-
2017-02-24
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。