Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx/PHP + HeartBeat + DRBD + MySql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Nginx/PHP + HeartBeat + DRBD + MySql

I. Project introduction

A) download and configure the Nginx/PHP service on the host server, use Nginx as the proxy, and let the Discuz community software run in the Nginx/html/ directory

B) download DRBD on the database server, load the MySql database data on the DRBD service, and do dual-computer hot backup in HeartBeat to ensure the safe and stable operation of the database.

Download and configure Nginx/PHP

1. Download configuration Nginx

(1) download the stable version of nginx on the official website. Nginx-1.10.3 is currently used.

(2) configure the source code and link the location

. / configure-- prefix=/usr/local/nginx-- with-http_ssl_module-- with-http_stub_status_module

Make & & make

Ln-s / usr/local/nginx/sbin/nginx / usr/local/bin/

(3) Common commands

Nginx [on]

Nginx-s reload [overload]

Nginx-s stop [shutdown]

(4) hide (delete version number) nginx version number

two。 Configure the nginx.conf file

[in the case of a single core, the number of working connections is 1024 * number of cores = 1024!]

[enable the function of loading PHP pages ~]

two。 Add the PHP test page (/ user/lcoal/nginx/html/index.php) to the installation

two。 Download configuration PHP

Download php-5.6.20.tar.bz2

(1) resolve dependencies (for specific installation tips, please see the error message, but I suggest you install the following first. Sometimes the wrong message will confuse you (I won't tell you that the bit has been confused and wasted the whole day. ))

Yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel-y

(2) configure source code

/ configure-- prefix=/usr/local/lnmp/php-- with-config-file-path=/usr/local/lnmp/php/etc-- with-openssl-- with-snmp-- with-gd-- with-zlib-- with-curl-- with-libxml-dir-- with-png-dir-- with-jpeg-dir-- with-freetype-dir-- with-out-pear-- with-gettext-- with-gmp-- enable-inline-optimization-- enable-soap-- enable-ftp -- enable-sockets-- enable-mbstring-- enable-fpm-- with-fpm-user=nginx-- with-fpm-group=nginx-- with-mcrypt-- with-mysql-- with-pdo-mysql-- enable-mysqlnd

Cp php.ini-production / usr/local/lnmp/php/etc/php.ini

Cd / usr/local/lnmp/php/etc/

Cp php-fpm.conf.default php-fpm.conf

Cp/php-5.6.20/sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm [configure Startup Project]

Chmod + x / etc/init.d/php-fpm

(3) modify configuration information (vim / usr/local/lnmp/php/etc/php.ini)

1.date.timezone = 'Asia/shanghai'

2.pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock [there are three places, and this address is the mysql.sock address compiled by the source code, depending on the circumstances]

Add drbd (distributed replication block device storage)

1 download the software used

Drbd-8.4.2.tar.gz (tar-zxf decompression)

Yum install-y gcc

two。 Execute. / configure-- enable-spec and. / configure-- enbale-spec-- with-km

(a) download the software according to the prompts (required) (flex,rpm-build, etc.)

Generate files such as drbd.spec,drbd-km.spec,drbd-kernel.spec, which are used to make rpm packages

Download 3.rpmbuild-bb drbd.spec and rpmbuild-bb drbd-km.spec before installation

Cp drbd-8.4.2.tar.gz ~ / rpmbuild/SOURCES/

After performing the above operations, eight drbd-* packages will be generated under ~ / rpmbuild/RPMS/x86_64, installed (rpm-ivh *), and sent to other node machines and installed.

4. Edit the customization file in / etc/drdb.d/, which is very important, that is, the server loaded by the drbd service and its related information.

(a) add two 4G virtual network cards to each virtual machine before the configuration file

(B) vim / etc/drdb.d/example.res

Resource example {

Meta-disk internal

Device / dev/drbd1

Syncer {

Verify-alg sha1

}

On server3.example.com {

Disk / dev/vdb

Address 172.25.254.163:7789

}

On server4.example.com {

Disk / dev/vdb

Address 172.25.254.164:7789

}

}

(C) scp example.com-> 172.25.254.164

(d) each node machine needs to add drbd services, drbdadm create-md example, and enable drbd services.

(e) set up the master / standby machine and forcibly synchronize the storage content

Drbdadm primary/secondary example-- force [which machine operates this command which is primary / secondary, and forcibly synchronizes information, auxiliary does not need-- force]

Watch cat / proc/drbd [processes that can view synchronized content]

(F) after synchronization, make the file system and mount it (mkfs.ext4) so that the contents of the / dev/drbd device can be synchronized.

When mounting a device, you should first set the current machine as the master, and then perform mount operation.

Drbdadm primary/secondary example

Fourth, add the mysql database and automatically transfer the service to another node when the node service is abnormal.

1. Improve the mount mysql point

(1) download mysql-server from the main node

a. Mount mount / dev/drbd1 / var/lib/mysql/, into / var/lib/mysql, and make its primary group mysql (chown mysql.mysql ~-R)

b. At this point, switch between primary and secondary mount / dev/drbd1/ to / var/lib/mysql to enable mysqld, and you can achieve mysql database data sharing.

two。 Set the policy for service auto-mount and heartbeat-based service transfer

Configuration / etc/ha.d/haresources

[line mark]

150 server3.example.com IPaddr::172.25.254.168/24/eth0 drbddisk::example Filesystem::/dev/drbd1::/var/lib/mysql::ext4 mysqld

[hostname, VIP, load drbd example file, mount file system / dev/drbd1 to / var/lib/mysql ext4 local file system, mysql service]

3. Secure initialization of MySql

4. Add a remote access permission to the MySql database

This allows Discuz to connect remotely when installing the database)

5. Discuz Community version

1. Download Discuz_X3.2_SC_UTF8.zip

Decompress under / usr/local/nginx/html

Unzip Discuz_x3.2_SC_UTF8.zip

two。 Change the name of upload to hxl, then open a browser and http://172.25.254.161/hxl/install/ to install

[modify directory permissions according to the prompts during installation]

This is relatively simple!

3. Install remote database

4. Successful interface

VI. [core] highly available storage test

1. Database information that the service is running normally on server3.example.com

[drbd storage is also mounted normally]

two。 Turn off the heartbeat service of server3.example.com, and switch the database information to the standby machine of server4.example.com database service normally.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report