上一篇讲的安装配置iscsi,本章介绍mariadb安装以及高可用的mysql具体实现
一、安装配置mariadb
[root@SQL1 ~]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local \\解压软件包 [root@SQL1 ~]# groupadd -g 200 mysql \\创建mysql组指定其GID [root@SQL1 ~]# useradd -u 200 -g 200 mysql \\ 创建mysql用户指定其UID [root@SQL1 ~]# mkdir -pv /mydata/data \\创建mysql数据存放位置 [root@SQL1 ~]# chown -R mysql.mysql /mydata/data/ \\更能属主属组 [root@SQL1 ~]# mount /dev/sdb1 /mydata/data \\挂载iscsi设备 [root@SQL1 ~]# ln -sv /usr/local/mariadb-5.5.36-linux-x86_64/ /usr/local/mysql \\创建链接 [root@SQL1 ~]# cd /usr/local/mysql \\切换目录 [root@SQL1 mysql]# chown -R root.mysql ./ \\更改当前目录的属主属组 [root@SQL1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ \\初始化数据库 [root@SQL1 mysql]# mkdir /etc/mysql \\创建mysql配置文件存放目录 [root@SQL1 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf \\复制mysql配置文件 [root@SQL1 mysql]# vim /etc/mysql/my.cnf \\编辑mysql配置文件 datadir = /mydata/data \\定义数据存放位置 innodb_file_per_table = on \\定义每表各有表结构 skip_name_resolve = on \\关闭msyql的主机名解析 [root@SQL1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld \\配置mysql启动脚本 [root@SQL1 mysql]# chkconfig --add /etc/init.d/mysqld \\添加mysql启动脚本为lsb风格 [root@SQL1 mysql]# service mysqld start \\启动mysql Starting MySQL.... [ OK ] [root@SQL1 mysql]# mysql \\进入msyql mysql> CREATE DATABASE iscsi; \\创建测试库 mysql> USE iscsi; \\切换默认库 mysql> CREATE TABLE ha_mysql(ID INT); \\创建测试表 mysql> GRANT ALL ON iscsi.* TO "hasql"@"172.16.2.%" IDENTIFIED BY "hasql"; \\用户授权 mysql> FLUSH PRIVILEGES; \\刷新权限 [root@SQL1 mysql]# mysql -h 172.16.2.13 -uhasql -p \\测试授权用户权限 Enter password: mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | iscsi | | test | +--------------------+ [root@SQL1 mysql]# service mysqld stop \\停止数据库 Shutting down MySQL. [ OK ] [root@SQL1 mysql]# umount /mydata/data/ \\卸载iscsi设备
[root@SQL2 ~]# iscsiadm -m node -T iqn.2015-07.com.mylinux:t1 -p 172.16.2.12 -l \\登录iscsi设备 Logging in to [iface: default, target: iqn.2015-07.com.mylinux:t1, portal: 172.16.2.12,3260] (multiple) Login to [iface: default, target: iqn.2015-07.com.mylinux:t1, portal: 172.16.2.12,3260] successful. [root@sql2 ~]# fdisk -l | grep "/dev/sd[a-z][0-9]" \\查看磁盘信息 /dev/sda1 * 1 64 512000 83 Linux /dev/sda2 64 5222 41430016 8e Linux LVM /dev/sdb1 1 10244 10489840 83 Linux \\此设备时sql1分区格式化的;可以直接使用 [root@sql2 ~]# groupadd -g 200 mysql [root@sql2 ~]# useradd -u 200 -g 200 mysql [root@sql2 ~]# mkdir -pv /mydata/data [root@sql2 ~]# chown -R mysql.mysql /mydata/data [root@sql2 ~]# mkdir /etc/mysql/ [root@sql2 ~]# mount /dev/sdb1 /mydata/data [root@sql2 ~]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local/ [root@sql2 ~]# ln -sv /usr/local/mariadb-5.5.36-linux-x86_64/ /usr/local/mysql [root@sql2 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@sql2 ~]# chkconfig --add /etc/init.d/mysqld [root@sql2 ~]# chown -R root.mysql /usr/local/mysql/ [root@SQL1 ~]# scp /etc/mysql/my.cnf SQL2:/etc/mysql/ \\复制sql1的mysql配置文件到sql2 [root@sql2 ~]# service mysqld start Starting MySQL.. SUCCESS! [root@sql2 ~]# mysql -h 172.16.2.14 -uhasql -p Enter password: mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | iscsi | | test | +--------------------+ [root@sql2 ~]# service mysqld stop Shutting down MySQL. SUCCESS! [root@sql2 ~]# umount /mydata/data/
二、配置HA
设置HA的默认属性:
[root@SQL1 ~]# crm crm(live)# configure crm(live)configure# property stonith-enabled=false crm(live)configure# verify crm(live)configure# commit crm(live)configure# property no-quorum-policy=ignore crm(live)configure# verify crm(live)configure# commit crm(live)configure# property default-resource-stickiness=200 crm(live)configure# verify crm(live)configure# commit
配置vip资源:
crm(live)configure# primitive hasql_vip ocf:heartbeat:IPaddr params ip="172.16.2.10" nic="eth0" cidr_netmask="24" broadcast="172.16.2.10" op monitor timeout=20s interval=10s crm(live)configure# verify crm(live)configure# commit
配置iscsi资源
crm(live)configure# primitive hasql_iscsi ocf:heartbeat:Filesystem params device="/dev/sdb1" directory="/mydata/data" fstype="ext4" op monitor timeout=40s interval=20s op start timeout=60s op stop timeout=60s crm(live)configure# verify crm(live)configure# commit
配置msyql资源
crm(live)configure# primitive hasql_mysql lsb:mysqld op monitor timeout=15s interval=15s crm(live)configure# verify crm(live)configure# commit
配置资源约束:order
crm(live)configure# order hasql_iscsi_after_hasql_vip inf: hasql_vip hasql_iscsi crm(live)configure# verify crm(live)configure# commit crm(live)configure# order hasql_mysql_after_hasql_hasql_iscsi inf: hasql_iscsi hasql_mysql crm(live)configure# verify crm(live)configure# commit
配置组资源约束:group
crm(live)configure# group hamysql_iscsi hasql_vip hasql_iscsi hasql_mysql INFO: resource references in order:hasql_iscsi_after_hasql_vip updated INFO: resource references in order:hasql_iscsi_after_hasql_vip updated INFO: resource references in order:hasql_mysql_after_hasql_hasql_iscsi updated INFO: resource references in order:hasql_mysql_after_hasql_hasql_iscsi updated crm(live)configure# verify crm(live)configure# commit
查看配置结果:
[root@SQL1 ~]# crm status Last updated: Wed Jul 1 14:00:03 2015 Last change: Wed Jul 1 13:59:45 2015 Stack: classic openais (with plugin) Current DC: SQL2.linux.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 3 Resources configured Online: [ SQL1.linux.com SQL2.linux.com ] Resource Group: hamysql_iscsi hasql_vip (ocf::heartbeat:IPaddr): Started SQL1.linux.com hasql_iscsi (ocf::heartbeat:Filesystem): Started SQL1.linux.com hasql_mysql (lsb:mysqld): Started SQL1.linux.com
测试访问mariadb
[root@SQL2 ~]# mysql -h 172.16.2.10 -uhasql -p Enter password: mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | iscsi | | test | +--------------------+ mysql> USE iscsi; mysql> SHOW TABLES; +-----------------+ | Tables_in_iscsi| +-----------------+ | ha_mysql | +-----------------+
切换mysql服务器:
[root@SQL1 ~]# crm crm(live)# crm(live)# node standby crm(live)# status Last updated: Wed Jul 1 14:02:51 2015 Last change: Wed Jul 1 14:02:44 2015 Stack: classic openais (with plugin) Current DC: SQL2.linux.com - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 3 Resources configured Node SQL1.linux.com: standby Online: [ SQL2.linux.com ] Resource Group: hamysql_iscsi hasql_vip (ocf::heartbeat:IPaddr): Started SQL2.linux.com hasql_iscsi (ocf::heartbeat:Filesystem): Started SQL2.linux.com hasql_mysql (lsb:mysqld): Started SQL2.linux.com
访问测试:
[root@SQL1 ~]# mysql -h 172.16.2.10 -uhasql -p Enter password: mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | iscsi | | test | +--------------------+ mysql> USE iscsi; mysql> SHOW TABLES; +-----------------+ | Tables_in_iscsi| +-----------------+ | ha_mysql | +-----------------+
原创文章,作者:马行空,如若转载,请注明出处:http://www.178linux.com/5922