High Availability lnmmp

Source: Internet
Author: User
Tags syslog

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/3F/92/wKiom1PLPsyRmx5AAAPMdvu5o_I127.jpg "Title =" qq 40720115851.jpg "alt =" wkiom1plpsyrmx5aaapmdvu5o_i127.jpg "/>

Lab platform: rhel5.8 rhel6.4

Lab environment: node1 ---- node9 corresponds to 10.32.9.51 ---- 10.32.9.59


Tutorial steps:


I. Software Installation

Node6 node7 use RPM to install keepalived. x86_64. 2.7

Node6 node7 compile and install nginx-1.4.7

./configure   --prefix=/usr   --sbin-path=/usr/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   --with-file-aio  make && make install


Provide service scripts for nginx

#!/bin/sh## nginx - this script starts and stops the nginx daemon## chkconfig:   - 85 15 # description:  Nginx is an HTTP(S) server, HTTP(S) reverse #               proxy and IMAP/POP3 proxy server# processname: nginx# config:      /etc/nginx/nginx.conf# config:      /etc/sysconfig/nginx# pidfile:     /var/run/nginx.pid # Source function library.. /etc/rc.d/init.d/functions # Source networking configuration.. /etc/sysconfig/network # Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx"prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx
make_dirs() {   # make required directories   user=`nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`   options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`   for opt in $options; do       if [ `echo $opt | grep ‘.*-temp-path‘` ]; then           value=`echo $opt | cut -d "=" -f 2`           if [ ! -d "$value" ]; then               # echo "creating" $value               mkdir -p $value && chown -R $user $value           fi       fi   done} start() {    [ -x $nginx ] || exit 5    [ -f $NGINX_CONF_FILE ] || exit 6    make_dirs    echo -n $"Starting $prog: "    daemon $nginx -c $NGINX_CONF_FILE    retval=$?    echo    [ $retval -eq 0 ] && touch $lockfile    return $retval} stop() {    echo -n $"Stopping $prog: "    killproc $prog -QUIT    retval=$?    echo    [ $retval -eq 0 ] && rm -f $lockfile    return $retval}
restart() {    configtest || return $?    stop    sleep 1    start} reload() {    configtest || return $?    echo -n $"Reloading $prog: "    killproc $nginx -HUP    RETVAL=$?    echo} force_reload() {    restart} configtest() {  $nginx -t -c $NGINX_CONF_FILE} rh_status() {    status $prog} rh_status_q() {    rh_status >/dev/null 2>&1}
case "$1" in    start)        rh_status_q && exit 0        $1        ;;    stop)        rh_status_q || exit 0        $1        ;;    restart|configtest)        $1        ;;    reload)        rh_status_q || exit 7        $1        ;;    force-reload)        force_reload        ;;    status)        rh_status        ;;    condrestart|try-restart)        rh_status_q || exit 0            ;;    *)        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"        exit 2esac


Node1 node2 compilation and installation of nginx (refer to node6 node7)

Node1 node2 compile and install PHP-FPM (php-5.4.19)

. /Configure -- prefix =/usr/local/PHP -- With-mysql = mysqlnd -- With-OpenSSL -- With-mysqli = mysqlnd -- enable-mbstring -- With-FreeType-dir --- JPEG-dir -- With-PNG-dir -- With-zlib -- With-libxml-Dir =/usr -- enable-XML -- enable-sockets -- enable-FPM -- With-config-File -Path =/etc -- With-config-file-scan-Dir =/etc/PHP. D -- with-bz2 -- enable-maintainer-ZTS


Make & make install

The Startup Script cp sapi/FPM/init. d. php-FPM/etc/init. d/PHP-FPM is provided.

Provide the configuration file cp php. ini-production/etc/PHP. ini for PHP

Provide the configuration file CP/usr/local/PHP/etc/php-fpm.conf.default/usr/local/PHP/etc/php-fpm.conf for PHP-FPM


Node1 Node 2 RPM install drbd83-8.3.13-2.el5.centos kmod-drbd83-8.3.13-1.el5.centos


Node3 node4 general binary method for installing mysql-5.5.37

1. Create a MySQL. MySQL user and group, CP support-files/my-huge.cnf/etc/My. CNF provides the configuration file

2. initialize/script/mysql_install_db -- user = MySQL -- datadir =/mydata/Data

3. For security consideration, the owner of the directory is changed back to root after initialization, and the group is MySQL. The data directory is in the MySQL group.

4./support-files/MySQL. server startup script

5. Library, header, and help file output


Node8 node9 Yum installation memcached-1.4.4-3.el6.x86_64

Node8 node9 universal binary installation mysql-proxy-0.8.4

1. Extract the package to/usr/local/and create a MySQL-proxy soft connection under/usr/local.

2. Create a MySQL-proxy user to run mysql-proxy

3. Provide the sysv Service Startup Script For MySQL-proxy, as shown in the following figure.

#!/bin/bash## mysql-proxy This script starts and stops the mysql-proxy daemon## chkconfig: - 78 30# processname: mysql-proxy# description: mysql-proxy is a proxy daemon for mysql# Source function library.. /etc/rc.d/init.d/functionsprog="/usr/local/mysql-proxy/bin/mysql-proxy"# Source networking configuration.if [ -f /etc/sysconfig/network ]; then    . /etc/sysconfig/networkfi# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0
# Set default mysql-proxy configuration.ADMIN_USER="admin"ADMIN_PASSWD="admin"ADMIN_LUA_SCRIPT="/usr/local/mysql-proxy/share/doc/mysql-proxy/admin.lua"PROXY_OPTIONS="--daemon"PROXY_PID=/var/run/mysql-proxy.pidPROXY_USER="mysql-proxy"# Source mysql-proxy configuration.if [ -f /etc/sysconfig/mysql-proxy ]; then    . /etc/sysconfig/mysql-proxyfiRETVAL=0start() {    echo -n $"Starting $prog: "    daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID --proxy-address="$PROXY_ADDRESS" --user=$PROXY_USER --admin-username="$ADMIN_USER" --admin-lua-script="$ADMIN_LUA_SCRIPT" --admin-password="$ADMIN_PASSWORD"    RETVAL=$?    echo    if [ $RETVAL -eq 0 ]; then        touch /var/lock/subsys/mysql-proxy    fi}
stop() {    echo -n $"Stopping $prog: "    killproc -p $PROXY_PID -d 3 $prog    RETVAL=$?    echo    if [ $RETVAL -eq 0 ]; then        rm -f /var/lock/subsys/mysql-proxy        rm -f $PROXY_PID    fi}# See how we were called.case "$1" in    start)        start        ;;    stop)        stop        ;;    restart)        stop        start        ;;    condrestart|try-restart)        if status -p $PROXY_PIDFILE $prog >&/dev/null; then            stop            start        fi        ;;    status)        status -p $PROXY_PID $prog        ;;    *)        echo "Usage: $0 {start|stop|restart|reload|status|condrestart|try-restart}"        RETVAL=1        ;;esacexit $RETVAL

4. Provide the configuration file/etc/sysconfig/MySQL-proxy for the service script

# Options for mysql-proxy ADMIN_USER="admin"ADMIN_PASSWORD="admin"ADMIN_ADDRESS=""ADMIN_LUA_SCRIPT="/usr/local/mysql-proxy/share/doc/mysql-proxy/admin.lua"PROXY_ADDRESS=""PROXY_USER="mysql-proxy"PROXY_OPTIONS="--daemon --log-level=info --log-use-syslog"

The last line needs to be modified according to the actual scenario, for example:

Proxy_options = "-- daemon -- log-level = info -- log-use-syslog -- plugins = proxy -- plugins = admin -- proxy-backend-addresses = 172.16.100.6: 3306 -- proxy-read-only-backend-addresses = 172.16.100.7: 3306 -- proxy-LUA-script =/usr/local/MySQL-proxy/share/doc/MySQL-proxy/rw-splitting.lua"


Bytes -----------------------------------------------------------------------------------------

Ii. Functions

1. Implement the MySQL master-slave architecture

Edit node3 my. CNF configuration file and add the following

Server-id = 1

Datadir =/mydata/Data

Innodb_file_per_table = 1

Log_bin =/mydata/data/MySQL-bin-Log


Node3 authorizes a slave node user

Grant replication slave, replication client on *. * to [email protected] "10.32.9. %" identified by "RedHat ";


Edit node4 my. CNF configuration file and add it to/from

Server-id = 2 --- different from node3 server-ID

Datadir =/mydata/Data --- specify the data directory

Innodb_file_per_table = 1 --- InnoDB Storage engine per table space

Relay_log =/mydata/relay. Log ---- enable and specify the relay log

Read_only = 1 ---- set slave server read-only


Node4 sets slave node replication Parameters

Change master to master_host = '10. 32.9.53 ', master_user = 'Nice', master_password = 'redhat ', master_port = 3306, master_log_file = 'mysql-bin-log.000004', master_log_pos = 107;


Node4 enables replication

Start slave

High Availability lnmmp

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.