Home >Database >Mysql Tutorial >HGDB HA with ISCSI

HGDB HA with ISCSI

WBOY
WBOYOriginal
2016-06-07 14:49:511430browse

1、基础环境 vip(虚拟IP):192.168.100.222 iscsi(存储):192.168.100.200 node1(节点一):192.168.100.192 node2(节点二):192.168.100.195 新建highgo操作系统用户,要求三台机器highgo用户的uid、gid相同 2、三台机器均关闭防火墙和SELINUX (以n

1、基础环境

<code>  vip(虚拟IP):192.168.100.222
  iscsi(存储):192.168.100.200
  node1(节点一):192.168.100.192
  node2(节点二):192.168.100.195     
  新建highgo操作系统用户,要求三台机器highgo用户的uid、gid相同
</code>

2、三台机器均关闭防火墙和SELINUX (以node1为例)

这里写图片描述

3、三台机器均SSH互信 (以iscsi为例)

(1)修改/etc/hosts
这里写图片描述

(2)root用户执行
这里写图片描述

(3)highgo用户执行
这里写图片描述

4、ISCSI配置

(1)服务器端(iscsi)

<code class=" hljs lasso"><span class="hljs-subst">>>></span>首先安装scsi<span class="hljs-attribute">-target</span><span class="hljs-attribute">-utils</span>:
yum <span class="hljs-attribute">-y</span> install scsi<span class="hljs-attribute">-target</span><span class="hljs-attribute">-utils</span>

<span class="hljs-subst">>>></span>编辑/etc/tgt/targets<span class="hljs-built_in">.</span>conf,添加:(/dev/sda是新添加的用来共享的磁盘,为原生的未经过格式化的盘)
<span class="hljs-subst"><</span>target iqn<span class="hljs-number">.201605</span><span class="hljs-built_in">.</span>dev:server<span class="hljs-built_in">.</span>target1<span class="hljs-subst">></span>
    backing<span class="hljs-attribute">-store</span> /dev/sda
<span class="hljs-subst"><</span>/target<span class="hljs-subst">></span>

<span class="hljs-subst">>>></span>启动服务,并配置开机自启动:
service tgtd start
chkconfig tgtd <span class="hljs-keyword">on</span></code>

(2)客户端(node1、node2)

<code class=" hljs lasso"><span class="hljs-subst">>>></span>首先安装iscsi<span class="hljs-attribute">-initiator</span><span class="hljs-attribute">-utils</span>
yum <span class="hljs-attribute">-y</span> install iscsi<span class="hljs-attribute">-initiator</span><span class="hljs-attribute">-utils</span>

<span class="hljs-subst">>>></span>编辑/etc/iscsi/initiatorname<span class="hljs-built_in">.</span>iscsi,添加:
InitiatorName<span class="hljs-subst">=</span>iqn<span class="hljs-number">.201605</span><span class="hljs-built_in">.</span>dev:server<span class="hljs-built_in">.</span>target1

<span class="hljs-subst">>>></span>配置服务:
chkconfig iscsi <span class="hljs-keyword">on</span>
chkconfig iscsid <span class="hljs-keyword">on</span>

service iscsi restart
service iscsid restart</code>

启动服务时出现失败的情况,正常
这里写图片描述

5、安装数据库(node1、node2)

node1安装过程:

(1)创建目录(挂载点)

<code class=" hljs perl"><span class="hljs-keyword">mkdir</span> /install/hgdb -p</code>

(2)发现服务器端有磁盘共享,并登录

这里写图片描述

这里写图片描述

(3)查询本地多一块磁盘

这里写图片描述

(4)格式化磁盘并挂载

这里写图片描述

注意:若挂载时出现以下错误,即为没有格式化磁盘所致
这里写图片描述

(5)切换到highgo登录系统,执行安装

<code class=" hljs bash">>>>编辑.bash_profile,添加:
<span class="hljs-keyword">export</span> HG_HOME=/home/highgo/hgdb</code>

注意:数据目录的选择,即将data目录置于共享磁盘中
这里写图片描述

(6)安装完成后,注销highgo,切换回root,执行关闭数据库服务、设置开机不自动启动数据库服务、卸载挂载的目录

<code class=" hljs vbnet">service hgdb-se2<span class="hljs-number">.0</span><span class="hljs-number">.4</span> <span class="hljs-keyword">stop</span>
chkconfig hgdb-se2<span class="hljs-number">.0</span><span class="hljs-number">.4</span> <span class="hljs-keyword">off</span>
umount /install/hgdb</code>

node2安装过程:

(1)创建目录(挂载点)

<code class=" hljs perl"><span class="hljs-keyword">mkdir</span> /install/hgdb -p</code>

(2)发现服务器端有磁盘共享,并登录

这里写图片描述

这里写图片描述

(3)挂载磁盘
这里写图片描述

注意:/dev/sdb为共享磁盘,在node1安装数据库时已经格式化并将data目录置于其下,此时只需要挂载即可看到data目录

(4)切换到highgo登录系统,执行安装

注意:不作为系统服务安装(这样安装时不会有data目录选项出现)
这里写图片描述

(5)注销highgo,切换回root,执行卸载挂载的目录

<code class=" hljs cmake">umount /<span class="hljs-keyword">install</span>/hgdb</code>

6、HA配置

(1)node1、node2安装

<code class=" hljs cmake">yum -y <span class="hljs-keyword">install</span> pacemaker corosync pcs</code>

(2)在一个节点配置文件,并将文件拷贝到另一节点(以node1为例)

<code class=" hljs ruby">密钥文件:

corosync-keygen
scp /etc/corosync/authkey root<span class="hljs-variable">@node1</span><span class="hljs-symbol">:/etc/corosync</span></code>
<code class=" hljs avrasm">corosync<span class="hljs-preprocessor">.conf</span>文件:

cd /etc/corosync
<span class="hljs-keyword">cp</span> corosync<span class="hljs-preprocessor">.conf</span><span class="hljs-preprocessor">.example</span> corosync<span class="hljs-preprocessor">.conf</span>
vi corosync<span class="hljs-preprocessor">.conf</span></code>

这里写图片描述

<code class=" hljs bash">pacemaker服务启动脚本:

<span class="hljs-built_in">cd</span> service.d
vi pcmd</code>

这里写图片描述

<code class=" hljs vbnet">corosync、pacemaker服务启停:

chkconfig corosync <span class="hljs-keyword">on</span>
service corosync start

chkcofig pacemaker <span class="hljs-keyword">off</span>
servicepacemaker <span class="hljs-keyword">stop</span></code>

7、集群资源配置

<code class=" hljs sql">首先启动服务:service corosync <span class="hljs-operator"><span class="hljs-keyword">start</span> (node1、node2)</span></code>

查看集群状态:
这里写图片描述

在一个节点上完成资源的配置即可

<code class=" hljs lasso">任何情况集群资源继续运行
pcs property <span class="hljs-built_in">set</span> no<span class="hljs-attribute">-quorum</span><span class="hljs-attribute">-policy</span><span class="hljs-subst">=</span>ignore
禁用stonith
pcs property <span class="hljs-built_in">set</span> stonith<span class="hljs-attribute">-enabled</span><span class="hljs-subst">=</span><span class="hljs-literal">false</span></code>
<code class=" hljs sql">配置vip
pcs resource <span class="hljs-operator"><span class="hljs-keyword">create</span> vip ocf:heartbeat:IPaddr params ip=<span class="hljs-string">"192.168.100.222"</span> nic=<span class="hljs-string">"eth0"</span> cidr_netmask=<span class="hljs-string">"24"</span> op monitor <span class="hljs-keyword">interval</span>=<span class="hljs-number">20</span>s timeout=<span class="hljs-number">30</span>s</span></code>

查看集群状态
这里写图片描述

<code class=" hljs sql">配置sdisk(共享存储)
pcs resource <span class="hljs-operator"><span class="hljs-keyword">create</span> sdisk ocf:heartbeat:Filesystem params device=<span class="hljs-string">"/dev/sdb"</span> directory=<span class="hljs-string">"/install/hgdb "</span> fstype=<span class="hljs-string">"ext4"</span> op <span class="hljs-keyword">start</span> timeout=<span class="hljs-number">60</span>s op stop timeout=<span class="hljs-number">60</span>s op monitor <span class="hljs-keyword">interval</span>=<span class="hljs-number">20</span>s timeout=<span class="hljs-number">60</span>s</span></code>

查看集群状态
这里写图片描述

<code class=" hljs sql">配置数据库服务
pcs resource <span class="hljs-operator"><span class="hljs-keyword">create</span> dbserver ocf:heartbeat:pgsql params pghost=<span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.222</span> pgport=<span class="hljs-number">5866</span> pgdba=highgo pgctl=/home/highgo/hgdb/bin/pg_ctl start_opt=<span class="hljs-string">"-D /install/hgdb/data"</span> psql=/home/highgo/hgdb/bin/psql pgdata=/install/hgdb/data monitor_user=highgo monitor_password=highgo123 op <span class="hljs-keyword">start</span> timeout=<span class="hljs-number">120</span>s <span class="hljs-keyword">interval</span>=<span class="hljs-number">120</span>s op stop timeout=<span class="hljs-number">120</span>s <span class="hljs-keyword">interval</span>=<span class="hljs-number">120</span>s op status timeout=<span class="hljs-number">60</span>s <span class="hljs-keyword">interval</span>=<span class="hljs-number">60</span>s</span></code>

这里写图片描述

<code class=" hljs oxygene">配置三个资源在一个组
pcs resource <span class="hljs-keyword">group</span> <span class="hljs-keyword">add</span> hgdb_group sdisk
pcs resource <span class="hljs-keyword">group</span> <span class="hljs-keyword">add</span> hgdb_group vip
pcs resource <span class="hljs-keyword">group</span> <span class="hljs-keyword">add</span> hgdb_group dbserver
</code>
<code class=" hljs ocaml">配置资源在两节点中的优先级
pcs <span class="hljs-keyword">constraint</span> location sdisk prefers node1=<span class="hljs-number">50</span>
pcs <span class="hljs-keyword">constraint</span> location sdisk prefers node2=<span class="hljs-number">40</span>
pcs <span class="hljs-keyword">constraint</span> location vip prefers node1=<span class="hljs-number">50</span>
pcs <span class="hljs-keyword">constraint</span> location vip prefers node2=<span class="hljs-number">40</span>
pcs <span class="hljs-keyword">constraint</span> location dbserver prefers node1=<span class="hljs-number">50</span>
pcs <span class="hljs-keyword">constraint</span> location dbserver prefers node2=<span class="hljs-number">40</span></code>
<code class=" hljs sql">配置资源在节点中的启动顺序
pcs constraint order <span class="hljs-operator"><span class="hljs-keyword">start</span> vip <span class="hljs-keyword">then</span> <span class="hljs-keyword">start</span> sdisk <span class="hljs-keyword">then</span> <span class="hljs-keyword">start</span> dbserver</span></code>
<code class=" hljs vbnet">配置psql文件(node1、node2)
vi /usr/<span class="hljs-keyword">lib</span>/ocf/resource.d/heartbeat/pgsql</code>

这里写图片描述
这里写图片描述

需要确认的错误情况及解决方法:
node1重启corosync服务时,出现下面的状况,而node2可以重启
这里写图片描述
查看日志文件
这里写图片描述
切换到highgo用户重新启动停止了服务(之前安装完数据库停掉服务后有新修改postgresql.conf和pg_hba.conf文件,设置了远程访问),再重启corosync服务成功

查看集群状态
这里写图片描述

8、验证

(1)正常状态下

在node1用虚拟ip可访问数据库
这里写图片描述

查看共享盘挂载情况
这里写图片描述

(2)模拟node1崩溃

此时在node2能用虚拟ip访问数据库
这里写图片描述

集群状态
这里写图片描述

共享盘挂载
这里写图片描述

注意:
在配置前最好设置NetworkManager服务stop,更改system eth0为eth0因为配置vip时为eth0,怕会找不到设备,然后重启network服务

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn