Keepalived、HAProxy

 

 

 1, and modifying A host keepalived profile HAProxy

Modify the configuration file A host keepalived

 

 

A host of haproxy modify configuration files

global
maxconn 100000
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin  process 1
stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin  process 2
user haproxy
group haproxy
daemon
nbproc 2
cpu-map 1 0
cpu-map 2 1
#cpu-map 3 2
#cpu-map 4 3
pidfile  /run/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
option  forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms


listen stats
        bind :9527
        stats enable
        stats hide-version
        stats uri /haproxy-status
        stats realm HAPorxy\Stats\Page
        stats auth haadmin:123456
        stats auth admin:123456
        stats refresh 30s
        stats admin if TRUE

listen  web_port
         bind 0.0.0.0:80
         mode http
         log global
         server web1  127.0.0.1:80  check inter 3000 fall 2 rise 5


# Official website business access entry =====================================
listen WEB_PORT_80
        bind 192.168.37.100:80
        mode tcp
        server web1 192.168.37.27:80 check inter 3000 fall 3 rise 5
        server web2 192.168.37.37:80 check inter 3000 fall 3 rise 5
listen MySQL_PORT bind 192.168.37.100:3306 monitoring database state in the haproxy mode tcp server web1 192.168.37.47:3306 cookie web-47 check inter 3000 fall 3 rise 5

  

 2, and the modified B host Keepalived profile HAProxy

global
maxconn 100000
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin  process 1
stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin  process 2
user haproxy
group haproxy
daemon
nbproc 2
cpu-map 1 0
cpu-map 2 1
#cpu-map 3 2
#cpu-map 4 3
pidfile  /run/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
option  forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms


listen stats
        bind :9527
        stats enable
        stats hide-version
        stats uri /haproxy-status
        stats realm HAPorxy\Stats\Page
        stats auth haadmin:123456
        stats auth admin:123456
        stats refresh 30s
        stats admin if TRUE

listen  web_port
         bind 0.0.0.0:80
         mode http
         log global
         server web1  127.0.0.1:80  check inter 3000 fall 2 rise 5


# Official website business access entry =====================================
listen WEB_PORT_80
        bind 192.168.37.100:80
        mode tcp
        server web1 192.168.37.27:80 check inter 3000 fall 3 rise 5
        server web2 192.168.37.37:80 check inter 3000 fall 3 rise 5
listen MySQL_PORT bind 192.168.37.100:3306 mode tcp server web1 192.168.37.47:3306 cookie web-47 check inter 3000 fall 3 rise 5

 3, the C compiler install nginx host software (version 1.14.2)

Download the official website: http://nginx.org/en/download.html

  1, nginx source package downloaded decompress

[root@centos27src]#tar -xvf nginx-1.14.2.tar.gz 

  2, the installation related libraries nginx

yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate \
gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel \
net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 \
libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

 3, and then switch to the nginx directory path is compiled source mounting

 ./configure --prefix=/apps/nginx \
 --user=www \
 --group=www \
 --with-http_ssl_module \
 --with-http_v2_module \
 --with-http_realip_module \
 --with-http_stub_status_module \
 --with-http_gzip_static_module \
 --with-pcre \
 --with-stream \
 --with-stream_ssl_module \
 --with-stream_realip_module

 4, and finally make the compiler

[[email protected]]#make -j 2 && make install

 5, create a directory nginx call

[[email protected]]#mkdir /data/nginx/wordpress  -p
[[email protected]] #vim /data/nginx/wordpress/index.php create a test page index.php
<?php
    phpinfo();                                                                                                                                   
?>

 6, create a directory server, nginx configuration file, specify the path nginx test page, include the function call

[root@centos27server]#cd /apps/nginx/conf
[root@centos27conf]#mkdir server
[root@centos27conf]#vim test.conf

 Nginx configuration file: vim test.conf

server {                                                                                                                                         
        listen 80;
        server_name www.magedu.net;
     location / {
        root /data/nginx/wordpress;
        index index.php index.html index.htm;
     }


location ~ \.php$ {
        root /data/nginx/wordpress;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }
}

 Call test.conf profile nginx main configuration file

[root@centos27conf]#vim /apps/nginx/conf/nginx.conf
user www; the same user name and the name of php
include /apps/nginx/conf/server/*.conf;   
}

 

 7. Check nginx syntax is correct, after a successful start nginx service

[root@centos27conf]#/apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful has been OK, success
[Root @ centos27conf] # / apps / nginx / sbin / nginx nginx start the service

 4, the host C compiler installed php software (5.0 or later)

1, the host C decompressing compressed php related dependencies and install

[[email protected]]#cd /usr/local/src
[[email protected]] #tar -vxf php-7.1.30.tar.gz 
[[email protected]]#cd php-7.1.30/

  Installation dependent packages

[root@centos7 ~]# yum -y install wget vim pcre pcre-devel openssl openssl-devel libicudevel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype \
freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap \
openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent  libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt \
libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

2, switch to the unpacked directory php, for compiling the source code

./configure --prefix=/apps/php --enable-fpm --with-fpmuser=www --with-fpm-group=www --with-pear --with-curl --with-png-dir --with-free-type-dir --with-iconv --with-mhash --with-zlib --with-xmlrpc --with-xsl --with-openssl 

3, designated installation package path

[[email protected]]#make -j 2 && make install

4, enter the www php program directory, and inside the user and group names changed to www.

[[email protected]]#cd /apps/php/etc/php-fpm.d
[[email protected]]#cp www.conf.default www.conf
[[email protected]] #vim www.conf modify the startup user account
user  www
group  www

 5. Create a system account, copy php.ini-production file to the configuration file directory, and named php.ini

[[email protected]] #useradd www -u 2019 -s / sbin / nologin this UID to be consistent and user name and UID php D program host.
[root@centos27etc]#cp /usr/local/src/php-7.1.30/php.ini-production  /apps/php/etc/php.ini  

 6, switch to the profile directory, rename the php default main program. 

[root@centos27etc]#cd /apps/php/etc
[root@centos27etc]#cp php-fpm.conf.default  php-fpm.conf

  7, start php-fpm program

[root@centos27etc]#/apps/php/sbin/php-fpm  -c /apps/php/etc/php.ini

 Check the status php, php at this time of the 9000 port is already open.

 

 C beginning in the host configuration file wordpress

1, wordpress package will be downloaded and stored in the specified directory

[root@centos27wordpress]#cd /data/nginx/wordpress
[root@centos27wordpress]#rz 

 2, extract the archive wordpress and wordpress directory, archive and index.php file before the test to move to other places

[Root @ centos27wordpress] #mv index.php wordpress-5.0.1-zh_CN.tar.gz / opt / test and archive file is moved to opt directory
[root@centos27wordpress]#ls
wordpress
[Root @ centos27wordpress] #mv wordpress / *. Wordpress directory to the current directory
[root@centos27wordpress]#ls
index.php    wordpress        wp-blog-header.php    wp-content   wp-links-opml.php  wp-mail.php      wp-trackback.php
license.txt  wp-activate.php  wp-comments-post.php  wp-cron.php  wp-load.php        wp-settings.php  xmlrpc.php
readme.html  wp-admin         wp-config-sample.php  wp-includes  wp-login.php       wp-signup.php
[Root @ centos27wordpress] #mv wordpress / opt the wordpress remove empty directories

 3, will be modified wordpress profiles associated with the database.

[root@centos27wordpress]#cp wp-config-sample.php wp-config.php

 Wordpress modify configuration files associated with the database

[root@centos27wordpress]#vim wp-config.php
define('DB_NAME', 'wordpress');

/ ** MySQL database username * /
define('DB_USER', 'wordpress');                                                                                                                  

/ ** MySQL database password * /
define('DB_PASSWORD', 'centos');

/ ** MySQL Host * /
define ( 'DB_HOST', '192.168.37.100'); the address written on the VIP.

/ Default when you create a character coding data tables ** * /
define('DB_CHARSET', 'utf8');

 Visit the following Web site to generate a random number, the way data content changes can be.

 

5, nginx install the software in the host compiler D 

Download the official website: http://nginx.org/en/download.html

  1, nginx source package downloaded decompress

[root@centos27src]#tar -xvf nginx-1.14.2.tar.gz 

  2, the installation related libraries nginx

yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate \
gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel \
net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 \
libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

 3, and then switch to the nginx directory path is compiled source mounting

 ./configure --prefix=/apps/nginx \
 --user=www \
 --group=www \
 --with-http_ssl_module \
 --with-http_v2_module \
 --with-http_realip_module \
 --with-http_stub_status_module \
 --with-http_gzip_static_module \
 --with-pcre \
 --with-stream \
 --with-stream_ssl_module \
 --with-stream_realip_module

 4, and finally make the compiler

[[email protected]]#make -j 2 && make install

 5, create a directory nginx call

[[email protected]]#mkdir /data/nginx/wordpress  -p
[[email protected]] #vim /data/nginx/wordpress/index.php create a test page index.php
<?php
    phpinfo();                                                                                                                                   
?>

 6, create a directory server, nginx configuration file, specify the path nginx test page, include the function call

[root@centos27server]#cd /apps/nginx/conf
[root@centos27conf]#mkdir server
[root@centos27conf]#vim test.conf

 Nginx configuration file: vim test.conf

server {                                                                                                                                         
        listen 80;
        server_name www.magedu.net;
     location / {
        root /data/nginx/wordpress;
        index index.php index.html index.htm;
     }


location ~ \.php$ {
        root /data/nginx/wordpress;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }
}

 Call test.conf profile nginx main configuration file

[root@centos27conf]#vim /apps/nginx/conf/nginx.conf
user www; the same user name and the name of php
include /apps/nginx/conf/server/*.conf;   
}

 

 7. Check nginx syntax is correct, after a successful start nginx service

[root@centos27conf]#/apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful has been OK, success
[Root @ centos27conf] # / apps / nginx / sbin / nginx nginx start the service

6, D host compiler install php software (5.0 or later)

1, the host D in the compressed packet decompression after installing php dependencies

[[email protected]]#cd /usr/local/src
[[email protected]] #tar -vxf php-7.1.30.tar.gz 
[[email protected]]#cd php-7.1.30/

  Installation dependent packages

[root@centos7 ~]# yum -y install wget vim pcre pcre-devel openssl openssl-devel libicudevel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype \
freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap \
openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent  libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt \
libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

2、切换到解压后的php目录下,进行源码编译

./configure --prefix=/apps/php --enable-fpm --with-fpmuser=www --with-fpm-group=www --with-pear --with-curl --with-png-dir --with-free-type-dir --with-iconv --with-mhash --with-zlib --with-xmlrpc --with-xsl --with-openssl 

3、指定安装包路径

[[email protected]]#make -j 2 && make install

6、后端E主机编译安装二进制mysql数据库

 执行此脚本可以编译安装完成二进制数据库。

[root@routersrc]#cd /usr/local/src   切换到此目录下
[root@routersrc]#tar -xvf mysql-5.6.34-onekey-install.tar.gz   解压数据库文件
[root@routersrc]#cat mysql-install.sh 
#!/bin/bash
DIR=`pwd`
NAME="mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz"
FULL_NAME=${DIR}/${NAME}
DATA_DIR="/data/mysql"

yum install vim gcc gcc-c++ wget autoconf  net-tools lrzsz iotop lsof iotop bash-completion -y
yum install curl policycoreutils openssh-server openssh-clients postfix -y

if [ -f ${FULL_NAME} ];then
    echo "安装文件存在"
else
    echo "安装文件不存在"
    exit 3
fi
if [ -h /usr/local/mysql ];then
    echo "Mysql 已经安装"
    exit 3 
else
    tar xvf ${FULL_NAME}   -C /usr/local/src
    ln -sv /usr/local/src/mysql-5.6.34-linux-glibc2.5-x86_64  /usr/local/mysql
    if id  mysql;then
        echo "mysql 用户已经存在,跳过创建用户过程"
    fi
        useradd  mysql  -s /sbin/nologin
    if  id  mysql;then
    	chown  -R mysql.mysql  /usr/local/mysql/* -R
        if [ ! -d  /data/mysql ];then
            mkdir -pv /data/mysql && chown  -R mysql.mysql  /data   -R
            /usr/local/mysql/scripts/mysql_install_db  --user=mysql --datadir=/data/mysql  --basedir=/usr/local/mysql/
	    cp  /usr/local/src/mysql-5.6.34-linux-glibc2.5-x86_64/support-files/mysql.server /etc/init.d/mysqld
	    chmod a+x /etc/init.d/mysqld
 	    cp ${DIR}/my.cnf   /etc/my.cnf
	    ln -sv /usr/local/mysql/bin/mysql  /usr/bin/mysql
	    /etc/init.d/mysqld start
	else
            echo "MySQL数据目录已经存在,"
			exit 3
	fi
    fi
fi

执行安装数据库脚本:

[root@routersrc]#bash mysql-install.sh 

创建数据库,并创建一个数据库用户名及授权

[root@routersrc]#mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> create  database wordpress;  创建数据库
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> grant all on wordpress.*  to "wordpress"@'192.168.37.%' identified by 'centos';  创建数据库名称
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]> flush privileges;  刷新数据库
Query OK, 0 rows affected (0.00 sec)

7、在后端E主机安装nfs共享包

 1、安装nfs-utils包

[root@routersrc]#yum install nfs-utils -y

 2、新建一个共享目录,并修改配置文件,将新建的目录共享出来,授予都写权限。

[root@routersrc]#mkdir /nfsdata/wordpress -p

  修改配置文件,将目录共享

[root@routersrc]#vim /etc/exports
/nfsdata/wordpress *(insecure,rw,async,no_root_squash)  避免客户端连接此nfs共享的目录是存在端口大于1024而被拒绝,需要加上insecure选项

 3、启动nfs服务器,并设置为开机启动

[root@routersrc]#systemctl start nfs   如果需要重启nfs,最好是重新加载,避免重启带来重新注册端口。
[root@routersrc]#systemctl enable  nfs

 在E主机安装完成nfs之后,我们需要在A或B主机进行验证一下此nfs文件是否可以挂载,是否可以看到此目录。

 在A主机安装nfs-utils包,然后挂载后端E主机的nfs路径,此时可以看到目录文件即可。

[root@centos7~]#yum install nfs-utils -y
[root@centos7~]#showmount -e  192.168.37.47  查看nfs共享的目录
Export list for 192.168.37.47:
/nfsdata/wordpress *    可以查看到nfs共享的目录

[root@centos7~]#mount -t nfs 192.168.37.47:/nfsdata/wordpress  /mnt/  测试挂载成功即可
[root@centos_17~]#umount /mnt   取消挂载

  

  

 

Guess you like

Origin www.cnblogs.com/struggle-1216/p/12105222.html