High availability LAMP via HeartBeat 2.x

One, test environment

< td width="159" valign="top">192.168.86.185

Host name IP address Characters < span style="line-height:0px;">
node1.example.com node1 span>
node2.example.com 192.168.86.186 node2< /td>
fs.example.com 192.168.86.111 fileserver

Two, configure the time synchronization of the three servers and modify the crontab to automatically synchronize with the ntp server

crontab -e

*/2 * * * * /usr/sbin/ntpdate cn.pool.ntp.org

Three, edit the /etc/hosts file to configure ssh mutual trust

1.vim /etc/hosts

192.168.86.185 node1.example.com node1192.168.86.186 node2.example.com node2192.168.86.111 fs. example.com fs
scp/etc/host s 192.168.86.186:/etc/scp /etc/hosts 192.168.86.111:/etc/

2. Configure ssh certificate

Run ssh-keygen on each server –> ssh-copyid node2

Four, prepare NFS Server

1. Add a new disk partition and mount it

fdisk /dev/sdbmkfs.ext4 /dev/sdb1mkdir /mydata; mount /dev/sdb1/mydata

2. Edit the /etc/exports file

vim /etc/ exports

/mydata 192.168.86.0/24(rw,no_root_squash)

Start nfs service

service nfs start

Create the /mydata directory on node1 and node2, and mount it as a test

mkdir /mydata; mount-t nfs fs:/mydata/mydata; mkdir/mydata/{db,webdoc}

Five, install heartbeat+crm+httpd+mariadb on node1 and node2< /p>

Heartbeat-gui-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-2.1.4-12.el6. x86_64.rpm Heartbeat-stonith-2.1.4-12.el6.x86_64.rpm to install

It is recommended to use yum localinstall to solve the dependencies, or you can use yum install heartbeat to install and then yum remove After heartbeat resolves the dependencies, install rpm -ivh

httpd uses yum Installation

yum install httpd php php-mysql -y

mariadb is installed using a compiled tarball

tar xvf mariadb-5.5.46-linux-x86_64.tar.gz -C/usr/local; ln-s/usr/local/mariadb-5.5.46/mysql

1.mysql configuration

groupadd -r -g mysqluseradd -r -g mysql mysqlchown -R root.mysql /usr/local/mysql< /pre> 

copy mysql configuration file

cp /usr/local/mysql/support-fils/my-medium.cnf /etc/my. cnf

Edit configuration file

vim /etc/my.cnf

datadir = /mydata/db Specify database location

innodb_file_per_table = on Specify the storage method of innodb table space

skip_name_resolve = on Skip domain name resolution

copy startup script

cp /usr/local/mysql/mysql.server /etc/init.d/mysqld; chmod +x /etc/init.d/mysqld

Initialize the database

< pre class="brush:bash;toolbar:false">/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql--user=mysql

Test start mysql

service mysqld start

Create wordpress library and authorize wordpress users

MariaDB [(none)]> create database wordpress;Query OK, 1 row affected (0.01 sec) MariaDB [(none)]> grant all privileges on wordpress.* to'wordpress'@'192.168.86.%' identified by'wordpress ';Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.01 sec)

Close mysql after normal startup

service mysqld stop

2.httpd configuration

Edit httpd configuration file

vim /etc/httpd/conf/httpd.conf

DocumentRoot"/mydata/webdoc"

Six, configure heartbeat

cp/ usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf} /etc/ha.d/

1. Edit authkeys

First you need to generate a random number Make the most matching pair

openssl rand-base64 10ABB7qPDGZVXdRAvim/etc/ha.d/authkeysauth 2#1crc2sha1ABB7qPDGZVXdRA

Modify to Random number generated

#3 md5 Hello!

Copy authkeys to node 2

scp /etc/ha.d/authkeys node2:/etc/ha.d

2. Edit ha.cf< /p>

vim /etc/ha.d/ha.cf

logfile /var/log/ha-log Enable log function

logfacility local0

udpport 694 monitor udp 694 port

mcast eth0 225.0. 0.1 694 1 0 Configure the multicast address, the ttl value

auto_failback on After the repair, the automatic switchback function is turned on

node node1.example.com Define two nodes separately

< p>node node2.example.com

ping 192.168.86.2 pingnode device

crm on open heartbeat 2.x crm

copy ha.cf to node2

scp /etc/ha.d/ha.cf node2:/etc/ha.d/

Modify hacluster password

echo linuxha|passwdhacluster--stdin

Seven, configure cluster resources

Start hb_gui and add one Group resources650) this.width=650;” src=”/wp-content/uploadshttp: /img.voidcn.com/vcimg/static/loading.png” title=”QQ screenshot20151023113539.png” alt=”wKiom1YprczS66uWAAB3095mfvk025.jpg” d=”4632401″ s=”158_fc0″ t=”jpg”>

Add VIP

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png “title=”QQ screenshot20151023113630.png” alt=”wKiom1Yprf3BoYmwAAKMOulW0cM176.jpg” d=”4632403″ s=”c2e_f01″ t=”jpg”>

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” style=”float:none ;” title=”QQ screenshot20151023113829.png” alt=”wKiom1YpriuzYSA8AAKQ3aOY4C4674.jpg” d=”4632405″ s=”cd2_b78″ t=”jpg”>

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” style=”float:none;” title=”QQ Screenshot 20151023113919.png” alt=”wKiom1YpriujXDLVAAKJpNCwcWs258.jpg” d=”4632407″ s=”06a_51d” t=”jpg”>

650) this.width=650;” src=”/wp-content/uploadshttp :/img.voidcn.com/vcimg/static/loading.png” style=”float:none;” title=”QQ screenshot20151023120207.png” alt=”wKiom1Ypvn2z3ChpAAMpxrOBvXg817.jpg” d=”4632409″ s=”44f_9a4″ t=”jpg”>

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” style=”float:none;” title=”QQ screenshot20151023125644.png” alt=”wKioL1YpvqrTv-MiAADCvgjd O8E654.jpg” d=”4632411″ s=”da1_79a” t=”jpg”>

Test resource migration

Stop heartbeat on node2

service heartbeat stop

Visit the page again to test whether it is normal

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2600 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.