Record Server Load balancer web Service requests based on DNS

Source: Internet
Author: User
Tags mysql host wordpress database wordpress blog

Record Server Load balancer web Service requests based on DNS

As a forum site: There are two types of data to be processed:

1. structured data, such as user names and user comments, can be stored in relational databases. 2. unstructured data, such as attachments uploaded by users. Stored in the file system.

Forum architecture:

Use two httpd servers to serve users' access requests. Use the record of DNS for customer access to the two servers. Php serves as the httpd module.

Shows the Forum architecture:


1. Set up an NFS file sharing server.

Key Point: ensure that the processes of the two httpd servers 192.168.60.99 and 192.168.60.40 can write data to the Shared File System (directory.

1. Create a shared directory.

[Root @ nfs ~] # Vim/etc/exports [root @ nfs ~] # Cat/etc/exports/web192.168.60.0/24 (rw, no_root_squash)

Note: users in the 192.168.60.0 network segment can mount directories shared by NFS.

2. Two httpd servers try to mount the NFS shared directory.

(1) httpd A (192.168.60.99): Server Mount/web

View the directory shared by the NFS server (File System)

[Root @ stu13 ~] # Showmount-e192.168.60.88Exportlistfor192.168.60.88:/web192.168.60.0/24

Mount shared directory

[Root @ stu13 ~] # Mount-tnfs192.168.60.88: // web/mnt/nfs/

Check whether the disk is mounted.

[Root @ stu13 ~] # Mount | grep "nfs [[: space:]" 192.168.60.88:/webon/mnt/nfstypenfs (rw, addr = 192.168.60.88)

(2) httpd B (192.168.60.40): the server is also mounted:/web

View the directory shared by the NFS server (File System)

[Root @ localhost ~] # Showmount-e192.168.60.88Exportlistfor192.168.60.88:/web192.168.60.0/24

Mount shared directory

[Root @ localhost ~] # Mount-tnfs192.168.60.88: // web/mnt/nfs/

Check whether the mounting is successful

[Root @ localhost ~] # Mount | grep "nfs [[: space:]" 192.168.60.88:/webon/mnt/nfstypenfs (rw, addr = 192.168.60.88)

3. Create a user who uses the NFS server Shared File System (directory;

For both httpd A (192.168.60.99) and httpd B (192.168.60.40) servers: User and Group: usenfs

That is, the owner and group of the processes or threads requested by the service user are usenfs. If the user uploads attachments, data should be written to the shared file system. Therefore, we must ensure that this user can write data to the NFS shared file directory of the Shared Server.

(1) set usenfs users on httpd A and httpd B servers respectively. The user ID is 400.

[Root @ stu13 ~] # Idusenfsuid = 400 (usenfs) gid = 400 (usenfs) groups = 400 (usenfs)[Root @ localhost ~] # Useradd-u400-rusenfs [root @ localhost ~] # Idusenfsuid = 400 (usenfs) gid = 400 (usenfs) groups = 400 (usenfs)

(2) create a user with the same ID on the NFS server and require the user to have a file system (/web) shared by NFS) you have read and write permissions.

[Root @ nfs ~] # Useradd-u400-rusenfs [root @ nfs ~] # Idusenfsuid = 400 (usenfs) gid = 400 (usenfs) groups = 400 (usenfs)

Use the file authorization in the Control List

Before setting:

[Root @ nfs ~] # Getfacl/webgetfacl: Removingleading '/'fromabsolutepathnames # file: web # owner: root # group: rootuser: rwxgroup: r-xother: r-x

Note:

According to the above information, usenfs users cannot create files in this directory.

Grant permissions to a user by using the File Permission list method.

[Root @ nfs ~] # Setfacl-mu: usenfs: rwx/web [root @ nfs ~] # Getfacl/webgetfacl: Removingleading '/'authorization # file: web # owner: root # group: rootuser: rwxuser: usenfs: rwxgroup: r-xmask: rwxother :: r-x

Note:

Because the usenfs user has the rwx permission, you can create a file in this directory when you initiate a file creation process as this user.

2. Create a LAMP Platform

Note: php is used as a module to interact with httpd. The database mariadb and NFS server work on the same host 192.168.60.88.

1. Compile the httpd server software:

Both httpd servers use the same settings for source code compilation and installation.

The method is as follows:

Required software package:

Httpd-2.4.9.tar.bz2apr-util-1.4.1.tar.bz2apr-1.4.6.tar.bz2

(Httpd-2.4 version requirements: apr version must be above 1.4.

View the apr database version of the system,

[Root @ stu13admin] # ldconfig-v | grepaprlibaprutil-1.so.0-> libaprutil-1.so.0.3.9libgstdataprotocol-0.10.so.0-> libgstdataprotocol-0.10.so.0.25.0libapr-1.so.0-> libapr-1.so.0.3.9

(Because apr version is not suitable for httpd-2.4, so to upgrade apr library. Upgrade Method: rpm package and source code package. Select the source code package.

Installation: apr-1.4.6.tar.bz2 and apr-util-1.4.1.tar.bz2

Export root@stu13admin1_tar-xfapr-1.4.6.tar.bz2 [root @ stu13admin] # cdapr-1.4.6 [root@stu13apr-1.4.6] #./configure -- prefix =/usr/local/apr-1.4 [root@stu13apr-1.4.6] # make & makeinstallExport root@stu13admin1_tar-xfapr-util-1.4.1.tar.bz2 [root @ stu13admin] # cdapr-util-1.4.1 [root@stu13apr-util-1.4.1] #. /configure -- prefix =/usr/local/apr-util-1.4 -- with-apr =/usr/local/apr-1.4 [root@stu13apr-util-1.4.1] # make & makeinstall

Compile and install the httpd server

Export root@stu13admin1_tar-xfhttpd-2.4.9.tar.bz2 [root@stu13httpd-2.4.9] #. /configure \ -- prefix =/usr/local/httpd-2.4.9 \ location where the installer is stored -- sysconfdir =/etc/httpd-2.4.9 \ location where the configuration file is stored -- enable-so \ with shared Module to compile and install httpd. You can flexibly load and uninstall modules. -- Enable-ssl \ enable ssl Secure Transmission feature -- enable-cgi \ enable cgi feature -- enable-rewrite \ enable redirect feature -- with-zlib \ supports compression. Enabling this feature saves bandwidth when transferring data -- with-pcre \ encrypted -- with-apr =/usr/local/apr-1.4 \ uses the newly installed apr because the library is not exported. So specify the directory in which -- with-apr-util =/usr/local/apr-util-1.4 \ -- enable-modules = all \ install all modules -- enable-mpms-shared = all \ prefork, worker, and event are all compiled. The httpd-2.4 supports dynamic mpm switching. -- With-mpm = the default mpm used by event is: event

[Root@stu13httpd-2.4.9] # make & makeinstall

Install the encryption tool:

Install libmcrypt

Export root@stu13lamp;{tar-xflibmcrypt-2.5.8.tar.bz2 [root @ stu13lamp] # cdlibmcrypt-2.5.8 [root@stu13libmcrypt-2.5.8] #./configure -- prefix =/usr/local/libmcrypt [root@stu13libmcrypt-2.5.8] # make & makeinstall

2. Compile php

(1) Compile php

Export root@stu13admin1_tar-xfphp-5.4.26.tar.bz2 [root @ stu13admin] # cdphp-5.4.26 [root@stu13php-5.4.26] #. /configure \ -- prefix =/usr/local/php-5.4 \ php installation directory -- with-mysql = mysqlnd \ Use php built-in connection to the database driver -- with-pdo-mysql = mysqlnd \ use php built-in database connection driver -- with-mysqli = mysqlnd \ Use php built-in database connection driver -- with-openssl \ enable support for ssl -- enable-mbstring \ support for more word sets -- -freetype-dir \ -- with-jpeg-dir \ supports jpeg images -- with-png-dir \ supports images in png format -- with-libxml-dir \ supports Extended Markup Language x Ml -- enable-xml \ -- with-apxs2 =/usr/local/httpd-2.4.9/bin/apxs \ edit php to the httpd module -- with-mcrypt =/usr/local/libmcrypt \ Use encryption -- with-config-file-path =/etc/storage location of the configuration file -- with-config-file-scan-dir =/etc/php. d \ -- with-bz2 \ supports bz2 Data Compression -- enable-maintainer-zts secure thread, use httpd: event, wordker to enable this option. [Root@stu13php-5.4.26] # make & makeinstall

Copy the configuration file

# Cpphp. ini-production/etc/php. ini

(2) edit the configuration file of the httpd server to combine the httpd server with php.

Home page of index. php

<IfModuledir_module> DirectoryIndexindex.phpindex.html </IfModule>

Support for. php web pages

AddTypeapplication/x-httpd-php.phpAddTypeapplication/x-httpd-php-source.phps

Check whether the php module is enabled

[Root@stu13php-5.4.26] # grep "^ LoadModule [[: space:] php. *"/etc/httpd-2.4.9/httpd. confLoadModulephp5_modulemodules/libphp5.so

Modify the owner Group of the httpd Session Service Process

UserusenfsGroupusenfs

Modify the root of the webpage document:

DocumentRoot "/mnt/nfs" <Directory "/mnt/nfs"> Options-Indexes-FollowSymLinksAllowOverrideNoneRequireallgranted </Directory>

3. Install the mariadb database in binary format

Export-C/usr/local [root @ localhostlocal] # ln-svmariadb-5.5.36-linux-i686mysqlcreatesymboliclink 'mysql' to 'mariadb-5.5.36-linux-i686 '[root @ localhostlocal] # ll | grepmysqllrwxrwxrwx1rootroot25Aug1720

Create a mysql user. You 'd better create it as a system user.

Root @ localhostlocal] # useradd-rmysql [root @ localhostlocal] # idmysqluid = 101 (mysql) gid = 103 (mysql) groups = 103 (mysql)

Put the data directory in/mydata.

Key points:

Data redundancy: You need to make the block device that stores data into a raid combination that provides data redundancy. Data backup: You need to make the block device that stores the data into lvm. This is skipped .....

(1) modify the owner Group of the database data storage directory

[Root @ localhost/] # chownmysql: mysql/mydata/[root @ localhost/] # ll | grepmydatadrwxr-xr-x2mysqlmysql4096Aug1721: 03 mydata

(2) modify the unzipped binary program. The owner is mysql and the group is mysql.

[Root @ localhostmysql] # chown-Rmysql: mysql./* [root @ localhostmysql] # lltotal216drwxr-xr-x2mysqlmysql4096Aug1720: 02bin-rw-r -- r -- 1mysqlmysql17987Feb2407: 50 COPYING ...... Drwxr-xr-x4mysqlmysql4096Aug1720: 02sql-benchdrwxr-xr-x4mysqlmysql4096Aug1720: 02support-files

(3) initialize mysql.

[Root @ localhostmysql] # scripts/mysql_install_db -- user = mysql -- datadir =/mydataInstallingMariaDB/MySQLsystemtablesin '/mydata'... OKFillinghelptables... OK

Change owner to root

[Root @ localhostmysql] # chown-Rroot. [root @ localhostmysql] # cpsupport-files/my-large.cnf/etc/my. cnf

Edit the configuration file as needed and add the following two lines

[Root @ localhostmysql] # vim/etc/my. cnthread_concurrency = 4 ------> ing between CPU and thread datadir =/web ------> data storage directory

(4) Provide the MySQL STARTUP script and check whether the execution permission is available.

[Root @ localhostmysql] # cpsupport-files/mysql. server/etc/init. d/mysqld [root @ localhostmysql] # chkconfig -- addmysqld [root @ localhostmysql] # chkconfig -- listmysqldmysqld0: off1: off2: on3: on4: on5: on6: off [root @ localhostmysql] # chkconfigmysqldoff

(5) Start the Database Server

[Root @ localhostmysql] # servicemysqldstartStartingMySQL... [OK]

Test whether the database can be operated

[Root @ localhostmysql] #./bin/mysqlWelcometotheMariaDBmonitor. Commandsendwith; or \ g. YourMariaDBconnectionidis2 ..... MariaDB [(none)]> showdatabases; + -------------------- + | Database | + -------------------- + | information_schema | mydb | mysql | performance_schema | test | + ------------------ + 5 rowsinset (0.00sec)

Note: The default user when installing the database. You can log on to the database system without a password. For security considerations. Therefore, you need to delete it or add a password.

MariaDB [(none)]> selectuser, host, passwordfrommysql. user; + ------ + ---------------- + ---------- + | user | host | password | + ------ + ---------------- + ---------- + | root | localhost | root | nfs.9527du.com | root | 127.0.0.1 | root |:: 1 | localhost | nfs.9527du.com | + ------ + ---------------- + ---------- + 6 rowsinset (0.00sec)

Clear unwanted users

MariaDB [(none)]> dropuser 'root' @ 'nfs .9527du.com '; MariaDB [(none)]> dropuser 'root' @': 1 '; mariaDB [(none)]> dropuser ''@ 'localhost'; MariaDB [(none)]> dropuser'' @ 'nfs .9527du.com '; MariaDB [(none)]> dropuser 'root' @ 'localhost ';

Set password:

MariaDB [(none)]> setpasswordfor 'root' @ '127. 0.0.1 '= password ('root'); MariaDB [(none)]> selectuser, host, passwordfrommysql. user; + ------ + ----------- + Principal + | user | host | password | + ------ + ----------- + Principal + | root | 127.0.0.1 | * Principal | + ------ + ----------- + Principal + 1 rowinset (0.00sec)

Users who add a database management interface can log on to the database from any IPv4 address. Authorize all rights to operate databases

MariaDB [(none)]> grantallon *. * to 'root' @ '%. %' identifiedby 'root'; QueryOK, 0 rowsaffected (0.00sec)

Refresh the database authorization table to take effect immediately

MariaDB [(none)]> flushprivileges; QueryOK, 0 rowsaffected (0.00sec)

Iii. Test the LAMP platform:

1. httpd A (192.168.60.99) and httpd B (192.168.60.40) mount the/web directory shared by the NFS server.

View NFS shared directories

[Root@stu13httpd-2.4.9] # showmount-e192.168.60.88Exportlistfor192.168.60.88:/web192.168.60.0/24

Mount and check whether the mounting is successful

[Root@stu13httpd-2.4.9] # mount-tnfs192.168.60.88:/web/mnt/nfs/[root@stu13httpd-2.4.9] # mount | grep "nfs [[: space:]" 192.168.60.88: /webon/mnt/nfstypenfs (rw, addr = 192.168.60.88)

View the NFS shared directory on another httpd server

[Root @ node1 ~] # Showmount-e192.168.60.88Exportlistfor192.168.60.88:/web192.168.60.0/24

Mount the shared directory and check whether the shared directory is mounted successfully.

[Root @ node1 ~] # Mount-tnfs192.168.60.88:/web/mnt/nfs/[root@node1http-2.4.9] # mount | grep "nfs [[: space:]" 192.168.60.88:/webon/mnt/nfstypenfs (rw, addr = 192.168.60.88)

2. Start the httpd A and httpd B servers to ensure that the owner of the Service session process is usenfs;

Httpd A (192.168.60.99)

[Root@stu13httpd-2.4.9] # psaux | grephttpdroot24270.22.02470213656? Ss14: 520: 00/usr/local/httpd-2.4.9/bin/httpd-kstartusenfs24280.01.93024369968? Sl14: 520: 00/usr/local/httpd-2.4.9/bin/httpd-kstartusenfs24290.01.93024369972? Sl14: 520: 00/usr/local/httpd-2.4.9/bin/httpd-kstartusenfs24310.01.93034609976? Sl14: 520: 00/usr/local/httpd-2.4.9/bin/httpd-kstart

Httpd A (192.168.60.40)

[Root@node1http-2.4.9] # psaux | grephttpdroot188801162.02470116660? Ss15: 120: 00/usr/local/http-2.4.9/bin/httpd-kstartusenfs18890.01.93024369972? Sl15: 120: 00/usr/local/http-2.4.9/bin/httpd-kstartusenfs18900.01.93034609980? Sl15: 120: 00/usr/local/http-2.4.9/bin/httpd-kstartusenfs18960.01.93024369976? Sl15: 120: 00/usr/local/http-2.4.9/bin/httpd-kstart

3. Add a test page to check whether the web page in. php format can be interpreted by the MySQL and httpd servers.

Create the checkmysql. php webpage file in the shared directory/web. Content.

<? Php $ link = mysql_connect ('2017. 168.60.88 ', 'root', 'root'); if ($ link) echo "Success... "; elseecho" Failure... ";?>

4. Test the access page

Start the mariadb database:

[Root @ nfs ~] # ServicemysqldstartStartingMySQL... [OK]

Test httpd A (192.168.60.99 ):

[Root @ nfs ~] # Curl-eIhttp: // 192.168.60.99/checkmysql. phpSuccess...

Note: httpd A (192.168.60.99) is successfully connected to the mariadb database. Enable php to interpret php code.

Test httpd B (192.168.60.40 ):

[Root @ nfs ~] # Curl-eIhttp: // 192.168.60.40/checkmysql. phpSuccess...

Note: httpd A (192.168.60.40) is successfully connected to the mariadb database. Enable php to interpret php code.

Shut down the mariadb database and test it once.

[Root @ nfs ~] # ServicemysqldstopShuttingdownMySQL. [OK] [root @ nfs ~] # Curl-eIhttp: // 192.168.60.99/checkmysql. phpFailure... [roocurl-eIhttp: // 192.168.60.40/checkmysql. phpFailure...

Note:

The two httpd servers can interact with the backend MySQL servers. This document explains the php format.

4. Deployment: wordpress-3.3.1.zh.CN blog Program:

1. Create a wordpress blog program to connect to the MySQL database and the database it uses.

MariaDB [(none)]> createdatabasewordpress; MariaDB [(none)]> grantallonwordpress. * to 'wordpress '@' 192. 168.60.% 'identifiedby 'wordpress '; MariaDB [(none)]> flushprivileges

Note:

Based on security considerations, wordpress users only have the right to use the wordpress database. You are not authorized to operate other databases.

2. Configure the wordpress blog Program

Export root@stu13nfs]unzip unzipwordpress-3.3.1-zh_cn.zip [root @ stu13wordpress] # cpwp-config-sample.phpwp-config.php

Edit the wp-config.php profile, enter the user and password to connect to MySQL data, and the database to use

[Root @ stu13wordpress] # vimwp-config.php // ** MySQL settings-specific information from the host you are using ** // ** WordPress database name */define ('db _ name ', 'wordpres');/** MySQL database username */define ('db _ user', 'wordpres '); /** MySQL Database PASSWORD */define ('db _ password', 'wordpres');/** MySQL HOST */define ('db _ host', '2014. 192. 168.60.88 ');/** default text encoding when creating a data table */define ('db _ charset', 'utf8 ');

On the server 192.168.60.99, open the wordpress Installation Wizard.

On the httpd server 192.168.60.40, open the wordpress Installation Wizard and install the wordpress blog program. For the installed interface:

Browse through another server

OK ....

This article is from the "Linux" blog, please be sure to keep this source http://9528du.blog.51cto.com/8979089/1541380

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.