Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ Based Corosync + Pacemaker + DRBD + LNMP Web server to achieve high availability cluster     - ThinkPad X201i installation notes Debian 7.5 (Linux)

- CentOS source installation GitLab Chinese Version (Server)

- Upgrading KDE Plasma 5.3 in Ubuntu 15.04 (Linux)

- Linux system versions organize local root password cracking method (Linux)

- Graphical development environment to build Android under Ubuntu 11.04 (Linux)

- Static member variable modified (Programming)

- Availability Hadoop platform - Oozie Workflow (Server)

- Minimum period string problem (Programming)

- Fedora 20 Installation and Configuration (Linux)

- Revive Adserver ad server installation on Ubuntu 15.04 / CentOS7 (Server)

- Difference in MySQL VARCHAR and CHAR data format (Database)

- GO five stages of language learning (Programming)

- Linux kernel programming parameter passing between modules and function calls (Programming)

- Installation under Linux Mint system guidelines for Gtk (Linux)

- CentOS7 Minimal minimize installation and then install the GNOME graphical interface (Linux)

- The direct insertion sort algorithm (Programming)

- Linux Command Line Art (Linux)

- How to install Unbound and DNSCrypt in Archlinux (Server)

- Linux installation notes under GAMIT (Linux)

- Linux Defensive / mitigate DDOS attacks (Linux)

 
         
  Based Corosync + Pacemaker + DRBD + LNMP Web server to achieve high availability cluster
     
  Add Date : 2017-03-08      
         
         
         
  Experimental System: CentOS 6.6_x86_64

Experimental conditions:

1) prepared in advance compiler environment, firewall and selinux are closed;

2) This configuration has two test nodes, respectively coro1 and coro2, respectively, for the corresponding IP address 192.168.19.55 and 192.168.19.98;

3) Cluster services nginx service;

4) providing the web service address 192.168.19.150, namely VIP;
Experimental Software: corosync-0: 1.4.7-1.el6 pacemaker-0: 1.1.12-4.el6 crmsh-2.1-1.6 drbd-8.4.4 php-5.6.11 mariadb-10.0.20 tengine-2.1.0

First, the preparatory work

1. Host names of all the nodes and the corresponding IP address resolution service can work, and the host name of each node needs the results with "uname -n" command consistent. Therefore, the need to ensure that / etc on both nodes / hosts file are added the following content

192.168.19.55 coro1
192.168.19.98 coro2

2. In order to make still maintain as host name after reboot the system, are also required to perform similar to the following command on each node:

coro1 on:

1 sed -i 's @ \ (HOSTNAME = \). * @ \ 1coro1 @ g' / etc / sysconfig / network
2 hostname coro1
coro2 on:

1 sed -i 's @ \ (HOSTNAME = \). * @ \ 1coro2 @ g' / etc / sysconfig / network
2 hostname coro2
3. Set the two nodes can communicate ssh key-based and test:

coro1 on:

1 ssh-keygen -t rsa
2 ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ coro2
coro2 on:

ssh-keygen -t rsa
ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ coro1

4. The two nodes must be synchronized time: Usually use ntpdate to operate, this is no longer the demo.

Second, install and configure the pacemaker and corosync

1. Install epel Source:

1 yum -y install epel *
2. Install corosync and pacemaker:

1 yum -y install corosync pacemaker
3. On the Edit /etc/corosync.conf coro1

 
 1 cd / etc / corosync /
 2 cp corosync.conf.example corosync.conf
 3 vim corosync.conf
 4 ------------------------------------
 5 bindnetaddr: 192.168.19.0 // where the network card for your network address
 6 mcastaddr: 239.255.19.1 // multicast address
 7 service {// add this section
 8 ver: 0
 9 name: pacemaker
10 # use_mgmtd: yes
11}
4. Build communication between nodes when used authentication key file on coro1:

1 corosync-keygen
5. corosync.conf and authkey copy onto coro2:

1 scp -p corosync.conf authkey coro2: / etc / corosync /

Third, the installation and start corosync crmsh

1. Install crmsh, required under good rpm package in advance:

1 yum -y install crmsh-2.1-1.6.x86_64.rpm
2. Start corosync (executed on coro1):

1 service corosync start
3. Check corosync engine is started normally:

1 grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log

4. Check if the initialization member nodes send out acknowledgments:

1 grep TOTEM /var/log/cluster/corosync.log

5. Check during startup if an error occurred. The following error message indicates packmaker soon will no longer run as a plug-corosync, therefore, recommend the use of cluster cman as infrastructure services, may be safely ignored here:

1 grep ERROR: /var/log/cluster/corosync.log

6. Check the pacemaker starts correctly:

1 grep pcmk_startup /var/log/cluster/corosync.log

7. If the above command are no problems, then you can execute the following command to start corosync coro2 on the coro1:

1 ssh coro2 'service corosync start'
8. If you installed crmsh, use the following command to view the startup state of cluster nodes. The following information can be seen from the two nodes have started normally, and the cluster has been in normal operation:

1 crm status

Fourth, compile and install and configure drbd

drbd total of two parts: the kernel module and user-space management tools. Wherein drbd kernel module code has been integrated into the Linux kernel 2.6.33 future releases, so if your kernel version higher than this version, you only need to install the management tools can; otherwise, you will need to install a kernel module and management tools package two, and both, the version number must maintain correspondence.

1. Install the userspace tools:

 
1 tar xf drbd-8.4.4.tar.gz
2 cd drbd-8.4.4
3 ./configure --prefix = / usr / local / drbd --with-km
4 make KDIR = / usr / src / kernels / 2.6.32-504.30.3.el6.x86_64 // replace your kernel version
5 make install
6 mkdir -pv / usr / local / drbd / var / run / drbd
7 cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d
8 chkconfig --add drbd
9 chkconfig drbd off // a while as corosync resources, so do not start automatically at boot

2. Install the drbd module:

1 cd drbd
2 make clean
3 make KDIR = / usr / src / kernels / 2.6.32-504.30.3.el6.x86_64 // replace your kernel version
4 cp drbd.ko / lib / modules / `uname -r` / kernel / lib
5 depmod

3. Give the host partition, the size of 5G. It will not give a specific step, the two hosts / dev / sda7 a partition will be used

4. Configure drbd (in coro1 operation):

drbd main configuration file /etc/drbd.conf; for administrative convenience, will usually present some configuration files into multiple parts, and are saved to /etc/drbd.d/ directory, only the main configuration file use "include" command to move these profiles to integrate pieces. Typically /etc/drbd.d directory profiles for global_common.conf and all files that end with .res. Wherein global_common.conf major global segment and common definitions section, and each .res file is used to define a resource.

In the configuration file, only once global segment, and if all of the configuration information is saved to the same profile without separated into multiple files, global segment must be located at the very beginning of the configuration file. The current global segment parameters that can be defined only minor-count, dialog-refresh, disable-ip-verification and usage-count. common segment is used to define each resource is inherited default parameter, the parameter that can be used in the resource definition can be defined in common section. Practice, common segment is not necessary, but recommended that more resources be shared parameter is defined as common segment parameters to reduce the complexity of the configuration file. resource section is used to define the drbd resources, each typically defined in a separate directory located /etc/drbd.d to .res file ending. When defining resources must give it a name, the name may be made of a non-blank ASCII characters. Define each resource segment must contain at least two host sub-segments, to define the resource related to the node, the other parameters can be inherited from a common segment or drbd in default without definition.
NOTE: Because this test drbd is compiled and installed, the default configuration file path is: / usr / local / drbd / etc
 
 1 cd /usr/local/drbd/etc/drbd.d/
 2 vim global_common.conf
 3 --------------------------------------
 4 global {
 5 usage-count no;
 6 # minor-count dialog-refresh disable-ip-verification
 7}
 8
 9 common {
10 protocol C;
11
12 handlers {
13 # These are EXAMPLE handlers only.
14 # They may have severe implications,
15 # like hard resetting the node under certain circumstances.
16 # Be careful when chosing your poison.
17
18 # pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b> / p
19 roc / sysrq-trigger; reboot -f ";
20 # pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b> / p
21 roc / sysrq-trigger; reboot -f ";
22 # local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o> / proc / sysrq-
23 trigger; halt -f ";
24 # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
25 # split-brain "/usr/lib/drbd/notify-split-brain.sh root";
26 # out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
27 # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 - -c 16k";
28 # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
29}
30
31 startup {
32 # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
33}
34
35 options {
36 # cpu-mask on-no-data-accessible
37}
38
39 disk {
40 # on-io-error detach;
41 # size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes
42 # disk-drain md-flushes resync-rate resync-after al-extents
43 # c-plan-ahead c-delay-target c-fill-target c-max-rate
44 # c-min-rate disk-timeout
45}
46 net {
47 # cram-hmac-alg "sha1";
48 # shared-secret "mydrbd";
49 # protocol timeout max-epoch-size max-buffers unplug-watermark
50 # connect-int ping-int sndbuf-size rcvbuf-size ko-count
51 # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
52 # after-sb-1pri after-sb-2pri always-asbp rr-conflict
53 # ping-timeout data-integrity-alg tcp-cork on-congestion
54 # congestion-fill congestion-extents csums-alg verify-alg
55 # use-rle
56}
57}
5. Define a resource, web resource name, you can change yourself:

 
 1 vim /usr/local/drbd/etc/drbd.d/web.res
 2 --------------------------------------
 3 resource web {
 4 on coro1 {
 5 device / dev / drbd0;
 6 disk / dev / sda7;
 7 address 192.168.19.55:7789;
 8 meta-disk internal;
 9 }
10 on coro2 {
11 device / dev / drbd0;
12 disk / dev / sda7;
13 address 192.168.19.98:7789;
14 meta-disk internal;
15}
16}
6. The above documents must be the same on both nodes, therefore, it may be based on just the ssh configuration file to coro2 sync all nodes:

1 scp /usr/local/drbd/etc/drbd.d/* coro2: /usr/local/drbd/etc/drbd.d/
7. On both nodes initialization defined resources and start the service:

1 drbdadm create-md web
2 service drbd start
8. Check the startup state, the following information can be seen at this time two nodes are in Secondary status:

1 cat / proc / drbd

9. We need to be one of the next node is set to Primary, execute the following command on the node to be set to Primary, where operations on coro1:

1 drbdadm primary --force web
2 cat / proc / drbd

And then view the status again, you can find the data synchronization process has begun. After synchronization is complete view data such as the status again, you can find the location of the primary and secondary display is not the same. Slash in front of the representatives of the current host, the latter on behalf of the other host.

10. Create and mount the file system:

Mount the file system only Primary node, therefore, only in order to set up a post-master node drbd device formatted here operate on coro1.

1 mke2fs -t ext4 -L DRBD / dev / drbd0
2 mkdir / mydata // create the mount point
3 mount / dev / drbd0 / mydata /
4 mkdir / mydata / www // Create Web Directory
5 mkdir / mydata / data // create the database directory
11. Switch Primary and Secondary nodes:

Drbd service to primary Primary / Secondary model terms, at a time only one node as Primary, so to switch the roles of the two nodes, only the first node is set to the original Primary Secondary only after the original the Secondary node is set to Primary.

On coro1:

1 umount / mydata /
2 drbdadm secondary web // becomes secondary node
On coro2:

1 drbdadm primary web // becomes primary node
2 cat / proc / drbd
3 mkdir / mydata // create the mount point
4 mount / dev / drbd0 / mydata /
5 ls / mydata /
We can see, coro2 has become the Primary, create a directory before the coro1 can also be accessed. After the test is completed, again coro1 into Primary and mount.

Fifth, prepare LNMP environment

 1. compile and install tengine:

 
1 yum -y install pcre-devel
2 useradd -r nginx // to ensure that the same two hosts nginx user id and group id
3 tar xf tengine-2.1.0.tar.gz
4 cd tengine-2.1.0
5 ./configure --prefix = / usr / local / nginx --sbin-path = / usr / local / nginx / sbin / nginx --conf-path = / etc / nginx / nginx.conf --error-log- path = / var / log / nginx / error.log --http-log-path = / var / log / nginx / access.log --pid-path = / var / run / nginx / nginx.pid --lock- path = / var / lock / nginx.lock --user = nginx --group = nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp- path = / var / tmp / nginx / client / --http-proxy-temp-path = / var / tmp / nginx / proxy / --http-fastcgi-temp-path = / var / tmp / nginx / fcgi / - -http-uwsgi-temp-path = / var / tmp / nginx / uwsgi --http-scgi-temp-path = / var / tmp / nginx / scgi --with-pcre
6 make && make install
2. tengine provide script:

 
  1 vim /etc/init.d/nginx
  2 ------------------------------------
  3 #! / Bin / sh
  4 #
  5 # nginx - this script starts and stops the nginx daemon
  6 #
  7 # chkconfig: - 85 15
  8 # description: Nginx is an HTTP (S) server, HTTP (S) reverse 9 # proxy and IMAP / POP3 proxy server
 10 # processname: nginx
 11 # config: /etc/nginx/nginx.conf
 12 # config: / etc / sysconfig / nginx
 13 # pidfile: /var/run/nginx.pid
 14
 15 # Source function library.
 16. /etc/rc.d/init.d/functions
 17
 18 # Source networking configuration.
 19. / Etc / sysconfig / network
 20
 21 # Check that networking is up.
 22 [ "$ NETWORKING" = "no"] && exit 0
 twenty three
 24 nginx = "/ usr / local / nginx / sbin / nginx"
 25 prog = $ (basename $ nginx)
 26
 27 NGINX_CONF_FILE = "/ etc / nginx / nginx.conf"
 28
 29 [-f / etc / sysconfig / nginx] &&. / Etc / sysconfig / nginx
 30
 31 lockfile = / var / lock / subsys / nginx
 32
 33 make_dirs () {
 34 # make required directories
 35 user = `nginx -V 2> & 1 | grep" configure arguments: "| sed 's / [^ *] * - user = \ ([^] * \) * / \ 1 / g.' -`
 36 options = `$ nginx -V 2> & 1 | grep 'configure arguments:'`
 37 for opt in $ options; do
 38 if [ `echo $ opt | grep '* - temp-path'`.]; Then
 39 value = `echo $ opt | cut -d" = "-f 2`
 40 if [! -d "$ Value"]; then
 41 # echo "creating" $ value
 42 mkdir -p $ value && chown -R $ user $ value
 43 fi
 44 fi
 45 done
 46}
 47
 48 start () {
 49 [-x $ nginx] || exit 5
 50 [-f $ NGINX_CONF_FILE] || exit 6
 51 make_dirs
 52 echo -n $ "Starting $ prog:"
 53 daemon $ nginx -c $ NGINX_CONF_FILE
 54 retval = $?
 55 echo
 56 [$ retval -eq 0] && touch $ lockfile
 57 return $ retval
 58}
 59
 60 stop () {
 61 echo -n $ "Stopping $ prog:"
 62 killproc $ prog -QUIT
 63 retval = $?
 64 echo
 65 [$ retval -eq 0] && rm -f $ lockfile
 66 return $ retval
 67}
 68
 69 restart () {
 70 configtest || return $?
 71 stop
 72 sleep 1
 73 start
 74}
 75
 76 reload () {
 77 configtest || return $?
 78 echo -n $ "Reloading $ prog:"
 79 killproc $ nginx -HUP
 80 RETVAL = $?
 81 echo
 82}
 83
 84 force_reload () {
 85 restart
 86}
 87
 88 configtest () {
 $ 89 nginx -t -c $ NGINX_CONF_FILE
 90}
 91
 92 rh_status () {
 93 status $ prog
 94}
 95
 96 rh_status_q () {
 97 rh_status> / dev / null 2> & 1
 98}
 99
100 case "$ 1" in
101 start)
102 rh_status_q && exit 0
103 $ 1
104 ;;
105 stop)
106 rh_status_q || exit 0
107 $ 1
108 ;;
109 restart | configtest)
110 $ 1
111 ;;
112 reload)
113 rh_status_q || exit 7
114 $ 1
115 ;;
116 force-reload)
117 force_reload
118 ;;
119 status)
120 rh_status
121 ;;
122 condrestart | try-restart)
123 rh_status_q || exit 0
124 ;;
125 *)
126 echo $ "Usage: $ 0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}"
127 exit 2
128 esac
129 ------------------------------------
130 chmod + x /etc/init.d/nginx
131 chkconfig --add nginx
132 chkconfig nginx off // a while as corosync resources, so do not start automatically at boot
3. Install mysql, man is no longer here and the path output path Demo:

 
1 useradd -r mysql // ensure that the same two hosts mysql user id and group id
2 tar xf mariadb-10.0.20-linux-x86_64.tar.gz -C / usr / local /
3 cd / usr / local /
4 ln -sv mariadb-10.0.20-linux-x86_64 mysql
5 cd mysql /
6 chown -R root: mysql.
7 ln -sv / usr / local / mysql / include / usr / include / mysql // output mysql header files to the system header file path
8 echo '/ usr / local / mysql / lib'> /etc/ld.so.conf.d/mysql.conf // output mysql library file to the system library search path
9 ldconfig
This test is drbd coro1 of Primary, so the following operations on coro1 carried out in advance of / dev / brbd0 mount to / mydata:

 
 1 chown -R mysql: mysql / mydata / data /
 2 / usr / local / mysql / scripts / mysql_install_db --user = mysql --datadir = / mydata / data / // initialization mysql
 3 cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf // provide profiles
 4 vim /etc/my.cnf
 5 ------------------------------------
 6 datadir = / mydata / data // Add this
 7 ------------------------------------
 8 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld // script to provide services
 9 scp -p /etc/init.d/mysqld coro2: /etc/init.d/
10 scp -p /etc/my.cnf coro2: / etc /
11 chkconfig --add mysqld
12 chkconfig mysqld off // a while as corosync resources, so do not start automatically at boot
13 service mysqld start
14 / usr / local / mysql / bin / mysql // mysql connection
15 ------------------------------------
16 CREATE DATABASE abcd; // create database abcd
17 SHOW DATABASES; // display a list of databases

Mysql stopped, let drbd master switch to coro2 and mount, connect mysql on coro2, please refer to the previous step to switch primary and secondary:

1 chkconfig --add mysqld
2 chkconfig mysqld off
3 service mysqld start
4 / usr / local / mysql / bin / mysql
5 -----------------------------------
6 SHOW DATABASES;

mysql test is successful, the data can also be seen on coro2 coro1 created. Stopped mysql, let the master switch back to the coro1 and mount / dev / drbd0.

4. compile and install php:

 
1 yum -y install libxml2-devel bzip2-devel libcurl-devel libmcrypt-devel
2 tar xf php-5.6.11.tar.bz2
3 cd php-5.6.11
4 ./configure --prefix = / usr / local / php --with-mysql = / usr / local / mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with- mysqli = / usr / local / mysql / bin / mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml -dir = / usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path = / etc --with-config-file-scan-dir = / etc / php.d --with-bz2 --with-curl --with-pdo-mysql = / usr / local / mysql
5 make && make install
5. Provide profile for php and php-fpm:

 
 1 cp php.ini-production /etc/php.ini // provide php configuration file
 2 cp sapi / fpm / init.d.php-fpm /etc/init.d/php-fpm // provided script
 3 chmod + x /etc/init.d/php-fpm
 4 chkconfig --add php-fpm
 5 chkconfig php-fpm off // a while as corosync resources, so do not start automatically at boot
 6 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf // provide php-fpm profile
 7 vim /usr/local/php/etc/php-fpm.conf
 8 ------------------------------------------------- -
 9 pm.max_children = 150
10 pm.start_servers = 8
11 pm.min_spare_servers = 5
12 pm.max_spare_servers = 10
13 pid = /usr/local/php/var/run/php-fpm.pid
14 user = nginx
15 group = nginx
16 listen = 192.168.19.150:9000
// Listen port in the VIP 9000

Sixth, LNMP combination with DRBD

1. Now is the test coro1 drbd of Primary node, the following actions on coro1 below:

 
 1 chown -R nginx: nginx / mydata / www /
 2 vim /etc/nginx/nginx.conf
 3 ----------------------------------------
 4 location / {
 5 root / mydata / www;
 6 index index.php index.html index.htm;
 7}
 8 location ~ \ .php $ {
 9 root / mydata / www;
10 fastcgi_pass 192.168.19.150:9000;
11 fastcgi_index index.php;
12 fastcgi_param SCRIPT_FILENAME / scripts $ fastcgi_script_name;
13 include fastcgi_params;
14}
15 ----------------------------------------
16 vim / etc / nginx / fastcgi_params // read the contents of this file the following lines
17 ----------------------------------------
18 fastcgi_param GATEWAY_INTERFACE CGI / 1.1;
19 fastcgi_param SERVER_SOFTWARE nginx;
20 fastcgi_param QUERY_STRING $ query_string;
21 fastcgi_param REQUEST_METHOD $ request_method;
22 fastcgi_param CONTENT_TYPE $ content_type;
23 fastcgi_param CONTENT_LENGTH $ content_length;
24 fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
25 fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
26 fastcgi_param REQUEST_URI $ request_uri;
27 fastcgi_param DOCUMENT_URI $ document_uri;
28 fastcgi_param DOCUMENT_ROOT $ document_root;
29 fastcgi_param SERVER_PROTOCOL $ server_protocol;
30 fastcgi_param REMOTE_ADDR $ remote_addr;
31 fastcgi_param REMOTE_PORT $ remote_port;
32 fastcgi_param SERVER_ADDR $ server_addr;
33 fastcgi_param SERVER_PORT $ server_port;
34 fastcgi_param SERVER_NAME $ server_name;
35 ----------------------------------------
36 scp /etc/nginx/nginx.conf coro2: / etc / nginx /
37 scp / etc / nginx / fastcgi_params coro2: / etc / nginx /
38 ifconfig eth0: 0 192.168.19.150/24 up // manually start the VIP
39 service nginx start
40 service mysqld start
41 service php-fpm start
Add page file in / mydata / www, here to wordpress example. Open the browser http://192.168.19.150, if no problem, the installation page appears, follow the prompts to install. I am here to manually create a wordpress database and to add the root user password, the direct use of root installation.

1 / usr / local / mysql / bin / mysql
2 -----------------------------------------
3 CREATE DATABASE wordpress;
4 UPDATE mysql.user SET Password = PASSWORD (123456) WHERE User = 'root';
5 FLUSH PRIVILEGES;

2. Change the Primary drbd nodes coro2, and test:

On coro1 actions:

1 service nginx stop
2 service mysqld stop
3 service php-fpm stop
4 umount / mydata /
5 drbdadm secondary web
6 ifconfig eth0: 0 down
On coro2 actions:

1 drbdadm primary web
2 mount / dev / drbd0 / mydata /
3 ifconfig eth0: 0 192.168.19.150/24 up
4 service nginx start
5 service mysqld start
6 service php-fpm start
After the completion of the manual switching, the same open http://192.168.19.150, any operations are no problem. So far, drbd + LNMP set up is completed. Next, it is necessary to corosync and pacemaker integration came. Now check the two hosts VIP, nginx, php-fpm, mysql, drbd are turned off, and can not be switched automatically.

Seventh, use crmsh add resources to corosync

1. Create a soft link drbd configuration file (both machines are operating):

1 ln -sv /usr/local/drbd/etc/drbd.conf /etc/drbd.conf
2 ln -sv /usr/local/drbd/etc/drbd.d /etc/drbd.d
2. Modify the startup script to php-fpm following, if not modified, then corosync not recognize (the two machines are operating):

 
  1 #! / Bin / sh
  2 # ================================================ =======================================
  3 # php-fpm - this script start and stop the php-fpm daemon
  4 #
  5 # chkconfig 35 on
  6 # description: php-fpm is a FastCGI web server.
  7 # processname: php-fpm
  8 # config: /usr/local/php/etc/php-fpm.conf
  9 # pidfile: /var/run/php-fpm.pid
 10 # ================================================ =======================================
 11 PATH = / usr / local / sbin: / usr / local / bin: / sbin: / bin: / usr / sbin: / usr / bin
 12
 13 BINFILE = "/ usr / local / php / sbin / php-fpm"
 14 CFGFILE = "/ usr / local / php / etc / php-fpm.conf"
 15 PIDFILE = "/ var / run / php-fpm.pid"
 16 LOCKFILE = "/ var / lock / php-fpm.lock"
 17
 18 RETVAL = 0
 19
 20 start () {
 21 [[-x $ BINFILE]] || exit 5
 22 [[-f $ CFGFILE]] || exit 6
 twenty three
 24 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -gt 0]]; then
 25 echo "The php-fpm is already running."
 26 return 1
 27 fi
 28
 $ 29 BINFILE -t> / dev / null 2> & 1
 30
 31 if [[$ -ne 0]?]; Then
 32 echo "The php-fpm configure has error."
 33 return 1
 34 fi
 35
 36 echo -n "Starting php-fpm ......"
 37 $ BINFILE -y $ CFGFILE -g $ {PIDFILE}
 38 RETVAL = $?
 39 echo
 40 [[$ RETVAL -eq 0]] && touch $ LOCKFILE
 41
 42 return $ RETVAL
 43}
 44
 45 stop () {
 46 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0]]; then
 47 echo "The php-fpm is not running."
 48 return 1
 49 fi
 50
 51 echo -n "Shutting down php-fpm ......"
 52
 53 if [[-f $ PIDFILE]]; then
 54 kill -QUIT `cat $ {PIDFILE}`
 55 else
 56 kill -QUIT `ps aux | grep php-fpm | awk '/ master / {print $ 2}'`
 57 fi
 58
 59 RETVAL = $?
 60 echo
 61 [[$ RETVAL -eq 0]] && rm -f $ LOCKFILE $ PIDFILE
 62
 63 return $ RETVAL
 64}
 65
 66 restart () {
 67 stop
 68 sleep 1
 69
 70 while true
 71 do
 72 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0]]; then
 73 start
 74 break
 75 fi
 76 sleep 1
 77 done
 78
 79 RETVAL = $?
 80 echo
 81
 82 return $ RETVAL
 83}
 84
 85 reload () {
 86 if [[ `ps aux | grep php-fpm: | grep -v grep | wc -l` -eq 0]]; then
 87 echo "The php-fpm is not running."
 88 return 1
 89 fi
 90
 91 echo -n $ "Reloading php-fpm ......"
 92
 93 if [[-f $ PIDFILE]]; then
 94 kill -USR2 `cat $ {PIDFILE}`
 95 else
 96 kill -USR2 `ps aux | grep php-fpm | awk '/ master / {print $ 2}'`
 97 fi
 98
 99 RETVAL = $?
100 echo
101
102 return $ RETVAL
103}
104
105 case "$ 1" in
106 start)
107 start
108 ;;
109
110 stop)
111 stop
112 ;;
113
114 restart)
115 restart
116 ;;
117
118 reload)
119 reload
120 ;;
121
122 *)
123 echo "Usage: service php-fpm {start | stop | restart | reload}"
124 RETVAL = 1
125 esac
126
127 exit $ RETVAL
Run the following command crm, crm enter the command line mode, non-special circumstances indicate operations were carried out in this mode, you can operate on a single machine.

3. Close corosync of stonith detection and arbitration:

1 configure // enter the configuration menu
2 property stonith-enabled = false // Close stonith equipment
3 property no-quorum-policy = ignore // Close arbitration device
4 verify // Syntax Check
5 commit // Submit
 4. Add the resource (configure menu):

 
1 primitive mydrbd ocf: drbd params drbd_resource = web op monitor role = Master interval = 20s timeout = 30s op monitor role = Slave interval = 30s timeout = 20s op start timeout = 240s op stop timeout = 240s // define drbd resources
2 primitive myfile Filesystem params device = "/ dev / drbd0" directory = "/ mydata" fstype = "ext4" op monitor interval = 30s timeout = 60s op start timeout = 60s op stop timeout = 60s // define the file system resources
3 primitive myip IPaddr params ip = 192.168.19.150 op monitor interval = 30s timeout = 60s // define VIP Resources
4 primitive mynginx lsb: nginx op monitor interval = 30s timeout = 20s // define nginx resources
5 primitive mysql lsb: mysqld op monitor interval = 30s timeout = 60s // define mysqld resources
6 primitive myphp lsb: php-fpm // define php-fpm resources
7 group myserver myfile myip mynginx myphp mysql // define a resource group
8 verify // syntax testing, such as no problem, the first not to submit
5. Add a variety of constraints:

 
1 ms ms_mydrbd mydrbd meta master-max = 1 master-node-max = 1 clone-max = 2 clone-node-max = 1 notify = True // drbd from the main Resource Allocation
2 colocation myfile_with_mydrbd_master inf: myfile ms_mydrbd: Master // define constraints arrangement, myfile to the Master node and drbd together
3 colocation mysql_with_myfile inf: mysql myfile // mysql going myfile together
4 order myfile_after_ms_mydrbd_master Mandatory: ms_mydrbd: promote myfile: start // define a sequence constraint, drbd master node is lifted, myfile to start
5 order myip_after_myfile Mandatory: myfile myip
6 order mynginx_after_myip Mandatory: myip mynginx
7 verify
8 commit
6. After submission, you can see that all resources have run coro2, open http://192.168.19.150 operation would have no problem

7. The following operation allows coro2 become the standby node. You can see all the resources transferred to the coro1 the open http://192.168.19.150 various operations are still OK:

1 cd ..
2 node standby coro2 // coro2 become alternate
----------------------------- Wait 5 seconds
3 node online coro2 // back online
4 status // Viewing Status
     
         
         
         
  More:      
 
- Linux dynamic libraries and Guide (Programming)
- Linux command to view the system status (Linux)
- Protobuf compiled and used on the Ubuntu 14.04 (Programming)
- MySQL how to export files with the date format (Database)
- Python virtual environment: Virtualenv (Linux)
- Django 1.8 TEMPLATE_DIRS configuration and STATICFILES_DIRS (Server)
- Linux System Tutorial: Fix ImportError: No module named wxversion error (Linux)
- Repair Chrome for Linux is (Linux)
- Linux Command-line MySQL summary (Database)
- Introduction to Linux Shell (Programming)
- Java reflection by calling the class method (Programming)
- Linux, how to filter, split, and merge pcap file (Linux)
- GRUB how to load Linux kernel (Linux)
- CentOS 6.6 running level (Linux)
- Linux 4.0+ kernel support for hardware switching module (HW Switch Offload) (Linux)
- 11.2.04 Oracle RAC directory crfclust.bdb file is too large, Bug 20186278 (Database)
- Java Performance Tuning the proxy mode (Programming)
- Use Vagrant build cross-platform development environment for Python (Server)
- AngularJS notes --- Scope and controller (Programming)
- CentOS / RedHat system partition essential requirements and partition scheme (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.