重起两节点或heartbeat服务,通过crm_mon –i2 命令查看资源状态..
          
此时,两个节点都充当主节点,占用共享IP和磁盘资源,同时做为对方的备用节点.这是为以下在每个节点同时安装两个MySQL做准备.其目的是同一时刻每个节点都运行一个MySQL数据库,如果其中一个节点出现问题,另一个节点则会接管对方的MySQL服务,即此时,正常的这个节点会同时运行两个MySQL服务.提高了服务器的使用效率.
 
           @测试内容2配置,在每个节点上做以下修改.
             
 分别关闭两个节点,然后增加一网卡eth1,用于心跳监测.
            具体实现:
            修改/etc/ha.d/ha.cf,原来是eth0,然后重新生成cib.xml(先把原来的删除)
bcast   eth1
   
        
# /usr/lib/heartbeat/haresources2cib.py --stout -c /etc/ha.d/ha.cf /etc/ha.d/haresources.bak
 
 
           验证是否生效,重起heartbeat,如图,bcast使用eth1通信.
          
@FAQ
         1. WARN: log_data_element: default_cib_update_callback: update:failed
              问题:来源于/var/log/message,同时,机器不断重启.
              原因: /etc/ha.cf/haresources.bak配置有问题,我当时没有在haresources里定义虚拟IP      
db_cluster1 IPaddr:: Filesystem::192.168.0.34:/mnt/da0/db1::/var/mysql/db1::nfs
db_cluster1 IPaddr:: Filesystem::192.168.0.34:/mnt/da0/db2::/var/mysql/db2::nfs
 
             
              改为以下即可.
db_cluster1IPaddr::192.168.0.32 Filesystem::192.168.0.34:/mnt/da0/db1::/var/mysql/db1::nfs
db_cluster1IPaddr::192.168.0.33 Filesystem::192.168.0.34:/mnt/da0/db2::/var/mysql/db2::nfs
 
 
 
              2. Resource IPaddr_192_168_0_32 cannot run anywhere
WARN: native_color: Resource Filesystem_2 cannot run anywhere
WARN: native_color: Resource IPaddr_192_168_0_33 cannot run anywhere
WARN: native_color: Resource Filesystem_12 cannot run anywhere
以下是原配置
db_cluster1IPaddr::192.168.0.32/24/eth0 Filesystem::192.168.0.34:/mnt/da0/db1::/var/mysql/db1::nfs
db_cluster1IPaddr::192.168.0.33/24/eth0 Filesystem::192.168.0.34:/mnt/da0/db1::/var/mysql/db1::nfs
 
 
 
 
 
 
解决:
       @资源手工管理
              1.查看所有资源(在任何一个节点执行都可以)
                     # crm_resource –L 
                    
              2. 资源切换
                     # crm_resource -M -r group_11 -H db_cluster1
                      -M
表示迁移 –r 资源名,这里是指资源组名 –H 节点名
                    
                     以上是切换前资源状态
                    
                     以上是切换后资源状态
 
四.MySQL多实例在两个节点上的安装
       安装前资源状态:#crm_mon –i2
      
       具体安装位置说明:
 
db_cluster1(节点1)
db_cluster2(节点2)
mysqld_1
basedir: /usr/local/mysql
datadir: /var/mysql/db1
basedir: /usr/local/mysql
datadir: /var/mysql/db1
Mysqld_2
basedir: /usr/local/mysql
datadir: /var/mysql/db2
basedir: /usr/local/mysql
datadir: /var/mysql/db2
      
1Db_cluster1上安装MySQL
             
       @版本:mysql-5.1.35.tar.gz(官网下载)
刚开始采用的版本是5.0.41,但其有一个bug,没有mysqld_multi.server.sh文件,不易在HA上管理mysql多个实例。故选择了5.1以上版本。
              @安装
                # tar zxvf mysql-5.1.35.tar.gz
                # cd mysql-5.1.35
#./configure --prefix=/usr/local/mysql
 --with-extra-charsets=gb2312,gbk --with-unix-socket-path=/tmp/mysql.sock
 --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static
                    --sysconfdir=/etc --enable-assembler        
# ./ scripts/mysql_install_db --user=mysql  #安装数据库,安装位置为/usr/local/mysql/var
 
              基本配置:
# cp –r –p  /usr/local/mysql/var /var/mysql/db1/
# cd /usr/local/mysql
# cp share/mysql/my-medium.cnf  /etc/my.cnf
# more /etc/my.cnf
-----------------------------my.cnf开始----------------------------------------------
[client]
port            = 3306
socket          = /tmp/mysql.sock
 
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root
 
[mysqld1]
port            = 3306
socket          = /tmp/mysql.sock
pid-file = /var/mysql/db1/var/db_cluster1.pid
datadir = /var/mysql/db1/var
 
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
#log-bin=mysql-bin
server-id       = 1
 
[mysqld2]
port            = 3307
socket          = /tmp/mysql2.sock
pid-file = /var/mysql/db2/var/db_cluster1.pid
datadir = /var/mysql/db2/var
 
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
#log-bin=mysql-bin
server-id       = 1
 
[mysqldump]
quick
max_allowed_packet = 16M
 
[mysql]
no-auto-rehash
 
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
-------------------------------------my.cnf结束------------------------------------------------------------
#  export PATH=$PATH:/usr/local/mysql/bin:. (可以将其放置于/etc/profile文件)
             
 
      
 
 
 
      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
动测试: # mysqld_multi start 1-2 #两个实例同时起动
                        # mysqld_multi start 1    # 起动实例1
                      
                     从上图可以看出,两个MySQL实例都正常起动了。
                     停止服务:# mysqld_multi stop 1-2  # 两个实例同时停止
                                     # mysqld_multi stop 1   # 停止实例1
     以服务方式管理:
                    # cp 源代码/support-files/mysqld_multi.server /etc/rc.d/init.d/mysqld_m
                    export PATH=$PATH:/usr/local/mysql/bin添加到/etc/rc.d/init.d/mysqld_m文件中
                    # chmod +x /etc/rc.d/init.d/mysqld_m
              操作命令:# service mysqld_m start|stop|report|restart
                    
 
@整合mysqld_m系统服务到heartbeat资源管理中.
         修改以下内容:
# more /etc/ha.d/haresources.bak
db_cluster1 IPaddr::192.168.0.32 Filesystem::192.168.0.34:/mnt/da0/db1::/var/mysql/db1::nfs mysqld_m::1
db_cluster2 IPaddr::192.168.0.33 Filesystem::192.168.0.34:/mnt/da0/db2::/var/mysql/db2::nfs mysqld_m::2
# /usr/lib/heartbeat/haresources2cib.py --stout -c /etc/ha.d/ha.cf /etc/ha.d/haresources.bak
  重新生成cib.xml
             
 
2Db_cluster2上安装MySQL(实例:mysqld1mysqld2)
              @安装
                # tar zxvf mysql-5.0.41.tar.gz
                # cd mysql-5.0.41
#./configure --prefix=/usr/local/mysql
 --with-extra-charsets=gb2312,gbk --with-unix-socket-path=/tmp/mysql.sock
 --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static
 --sysconfdir=/etc --enable-assembler    
               # make && make install
         # ./ scripts/mysql_install_db --user=mysql  #安装数据库,安装位置为/usr/local/mysql/var
              基本配置:
# cp –r –p  /usr/local/mysql/var /var/mysql/db2/
# cd /usr/local/mysql
# cp share/mysql/my-medium.cnf  /etc/my.cnf
# more /etc/my.cnf
-----------------------------my.cnf开始----------------------------------------------
#
db_cluster1机器上的配置是一样的,从上边拷贝一下即可
#
可以这样: # scp 192.168.0.30:/etc/my.cnf  /etc/
-------------------------------------my.cnf结束---------------------------------------
#  export PATH=$PATH:/usr/local/mysql/bin:. (可以将其放置于/etc/profile文件)
 
 
 
 
 
 
 
以服务方式管理:
     # cp 源代码/support-files/mysqld_multi.server /etc/rc.d/init.d/mysqld_m
     # chmod +x /etc/rc.d/init.d/mysqld_m
     操作命令:# service mysqld_m start|stop|report|restart
 
@整合mysqld_m系统服务到heartbeat资源管理中.
         修改以下内容:
# more /etc/ha.d/haresources.bak
db_cluster1 IPaddr::192.168.0.32 Filesystem::192.168.0.34:/mnt/da0/db1::/var/mysql/db1::nfs mysqld_m::1
db_cluster2 IPaddr::192.168.0.33 Filesystem::192.168.0.34:/mnt/da0/db2::/var/mysql/db2::nfs mysqld_m::2
# /usr/lib/heartbeat/haresources2cib.py --stout -c /etc/ha.d/ha.cf /etc/ha.d/haresources.bak
  重新生成cib.xml,建议先把原来的删除(/var/lib/heartbeat/crm/)
 
 
 
 
 
 
3.FAQ
          @WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.
ABORT: Can't find command 'my_print_defaults'.
This command is available from the latest MySQL
distribution. Please make sure you have the command
in your PATH.
问题出现:/usr/local/mysql/bin/mysqld_multi start 1-2
解决:export PATH=$PATH:/usr/local/mysql/bin:.
如果添加到/etc/profile文件中不能解决,可以将其加入到/etc/rc.d/init.d/mysqld_m文件中
五.配置到此完毕,做最后测试
       @测试一:起动两个节点,同时或不同时都可。
        
              资源均起动正常。(包括VIPNFS挂载和数据库服务)
       @测试二,停止其中一个节点,稍等片刻再看资源状态,这里关闭第一个节点(db_cluster1)
             
Db_cluster1显示已OFFLINE,其资源均由db_cluster2接管。
@测试三,起动关闭的节点1,待节点1起动以后,稍等片刻再看资源状态,已恢复到了测试一状态。