部署HA wordpress Cluster
WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL 数据库的服务器上架设自己的网志。也可以把 WordPress 当作一个内容管理系统(CMS)来使用。WordPress 是一个免费的开源项目,在GNU通用公共许可证下授权发布。WordPress 被认为是Michel Valdrighi所开发的网志平台b2/cafelog的正式继承者。Wordpress是一个BLOG程序,用它可以架设完全属于自己的BLOG站点。
通过LAMP组合部署wordpress基于heartbeat v2 crm实现HA;
1、环境准备
OS:CentOS6.7
软件选型:heartbeat v2 (crm)
node1: 172.16.11.10 通过NFS提供共享存储
node2:172.16.11.20 LAMP+heartbeat
node3:172.16.11.30 LAMP+heartbeat
vip:192.168.100.80
node1:
[root@node1 ~]# mkdir /data [root@node1 ~]# mkdir {web,mydata} [root@node1 ~]# cat /etc/exports /data 192.168.100.0/24(rw,no_root_squash)
node2:
[root@node2 ~]# yum install httpd httpd-devel mysql mysql-server mysql-devel php php-devel php-mysql php-gd php-xml php-mbstring php-imap php-ldap php-odbc php-pear php-mcrypt php-bcmath php-mhash freetype freetype-devel libpng libpng-devel zlib libxml2 libxml2-devel libjpeg* libgcrypt libgcrypt-devel libxslt libxslt-devel [root@node2 ~]# mkdir /data [root@node2 ~]# mount 192.168.100.10:/data /data [root@node2 ~]# ls /data mydata web
1、修改MYSQL的数据存放位置:
1) 修改第一个文件/etc/my.cnf:修改之前先备份cp /etc/my.cnf /etc/my.cnfbak
vi /etc/my.cnf
打开之后修改datadir的目录为/data/mydata
把socket改成/data/mydata/mysql.sock #为了安全起见,你可以把原来的注释掉,然后重新加入一行,改成现在的目录。
2)修改第二个文件/etc/init.d/mysqld:修改之前先备份 cp /etc/init.d/mysqld /etc/init.d/mysqldbak
vi /etc/init.d/mysqld
注意:准确的位置是/etc/rc.d/init.d/mysqld,由于这里这里有一个/etc/init.d到/etc/rc.d/init.d的映射,
所以用上面的命令即可,也简单。
把其中get_mysql_option mysqld datadir "/var/lib/mysql" 注释
添加get_mysql_option mysqld datadir "/data/mydata"一行
3)下面需要建立一个mysql.sock的链接:
ln -s /data/mydata/mysql.sock /var/lib/mysql/mysql.sock
然后启动mysql,mysql初始化
[root@node2 mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.01 sec) mysql> Ctrl-C -- exit! Aborted [root@node2 mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.01 sec) mysql> CREATE DATABASE xxj; Query OK, 1 row affected (0.01 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | xxj | +--------------------+ 4 rows in set (0.01 sec) mysql> quit Bye [root@node2 mysql]# cd /data/mydata [root@node2 mydata]# ls ibdata1 ib_logfile1 mysqld.log mysql.sock xxj ib_logfile0 mysql mysqld.pid test [root@node2 mydata]# ssh 192.168.100.10 ls /data/mydata ibdata1 ib_logfile0 ib_logfile1 mysql mysqld.log mysqld.pid mysql.sock test xxj
2、修改/etc/httpd/conf/httpd.conf设置的站点文件存放目录
DocumentRoot "/data/web"
3、测试httpd是否能解析php文件及能否连接mysql,在apache的网站目录下放个index.php文件
[root@node2 web]# cat index.php <?php phpinfo();?>
好的,LAMP已经安装完成
node3:
[root@node3 ~]# mkdir /data [root@node3 ~]# mount 192.168.100.10:/data /data [root@node3 ~]# scp 192.168.100.20:/etc/my.cnf /etc/my.cnf my.cnf 100% 248 0.2KB/s 00:00 [root@node3 ~]# scp 192.168.100.20:/etc/init.d/mysqld /etc/init.d/mysqld mysqld 100% 7074 6.9KB/s 00:00 [root@node3 ~]# ln -s /data/mydata/mysql.sock /var/lib/mysql/mysql.sock
建立数据库和建立wordpress用户
mysql> create database wordpress;
mysql> grant all on wordpress.* to wordpress@localhost identified by 'portalhuan.123';
把下载wordpress最新版本,将解压出来的wordpress目录下的文件复制到/var/www/目录下。进如wordpress目录
将wp-config-sample.php改名为wp-config.php.
用vim打开wp-config.php,输入数据库信息。
define('DB_NAME', 'wordpress');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
将解压出来的wordpress目录下的文件复制到/var/www/目录下,(不包括wordpress目录)
测试安装
用浏览器打开http://172.168.100.20
二、开始部署heartbeat
安装,配置上篇博客已经学习了,这里就直接添加资源了
关闭node2,node3上的httpd,mysqld,确定时间已同步
上篇博文学习的是heartbeat v2中兼容v1 haresource的传统RA,这篇学习v2的crm来管理资源
heartbeat v2 (v2 crm):
启用crm方法:
ha.cf配置文件,添加一行crm on,再重启heartbeat
启动mgmtd进程,监听5560/tcp
注意:此时会禁用v1 haresources资源管理器;
Refresh in 7s...
#crm_mon ============ Last updated: Sun Oct 25 13:28:35 2015 Current DC: node2 (3b3a5a4e-90c0-40df-bf59-12d9947b2c9e) 2 Nodes configured. 0 Resources configured. ============ Node: node2 (3b3a5a4e-90c0-40df-bf59-12d9947b2c9e): online Node: node3 (599c5b3a-5f9d-4410-ab3e-281f59abbddd): online
从上面的集群状态中我们可以看到,集群中有两个节点,分别为node2和node4状态是online全部在线,我们还可以看到,DC是node2。两个节点的资源是0,说明在我们这个集群中还没有资源。下面我们来详细的说明一下!
在heartbat v2中资源管理可以2种方式:
1、命令行crm_sh配置:
[root@node2 ha.d]# crm crmadmin crm_failcount crm_resource crm_uuid crm_attribute crm_master crm_sh crm_verify crm_diff crm_mon crm_standby
2、图形化配置接口:hb_gui
V2版本crm_sh不好用,这次主要使用hb_gui
安装heartbeat图形化配置接口:heartbeat-gui
安装后会自动生成hacluster用户,
要想启用GUI配置界面,必须要为hacluster用户(heartbeat默认用户)创建一个密码
打开heartbeat-gui:hb_gui 注意:要在系统图形界面下打开
登录节点,输入密码
hb_gui主界面:
添加资源ip,,shared storage,httpd,mysql:
然后在点击资源组右键启动:
此时资源都运行于node2,尝试在写一篇博文时,把资源切换到node3;在node2上写的文章和更改在node3上可以看到
但是切换到nod3时,写不了文章也不评论不了,node2设置的密码在node3也登录不了,数据库权限的问题吗?编辑文章时没保存切换节点会保留吗?
可能是我没用干净的系统做实验,下次换干净的系统再做一次试试
作业:基于heartbeat v2 crm实现HA LAMP组合;要求,部署wordpress,用于编辑的文章中的任何数据在节点切换后都能正常访问;