博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lamp架构扩展
阅读量:6425 次
发布时间:2019-06-23

本文共 9660 字,大约阅读时间需要 32 分钟。

Lamp架构扩展

Lamp架构扩展

  • Client1台,访问站点www.mylinuxops.com
  • PowerDNS服务器1台,对用户访问的网址做域名解析
  • LVS服务器1台,实现apache负载均衡
  • apache+php服务器2台,分担访问压力
  • NFS-Sever服务器1台,存放站点动态和静态页面
  • NFS-backup服务器1台,实时备份NFS主机上站点数据
  • ProxySQL服务器1台,对背后数据库服务器进行读写分离
  • MySQL-Maser,主数据库服务器1台,接受对数据库写请求,向后端从服务器同步数据
  • MySQL-slave{1,2},从数据库服务器2台,接受对数据库读请求
主机 系统 IP
Client 6 172.22.46.10
powerdns 7 172.22.46.70
route 7 172.22.46.57;192.168.15.107;10.0.0.200
LVS 7 192.168.15.108;10.0.0.100
webSV1 7 192.168.15.111;10.0.0.100
webSV2 7 192.168.15.112;10.0.0.100
proxysql 7 192.168.15.113
mysqlmaster 7 192.168.15.114
mysqlslave1 7 192.168.15.115
mysqlslave2 7 192.168.15.116
NFS 7 192.168.15.118
NFSbak 7 192.168.15.119

一,配置proxysql,mysql主从

在3台数据库主机上安装MySQL

  • yum -y install mariadb-server

Master服务器操作

1,修改配置文件

vim /etc/my.cnf[mysqld]log-bin=/data/bin/mysql-binbinlog-format=rowserver-id=4

2.创建二进制日志目录

mkdir /data/binchown -R mysql.mysql /data/bin

3.启动服务

systemctl start mariadb

4.创建主从复制用的账号

mysql -e "GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'192.168.73.%' IDENTIFIED BY 'centos';"

5.查看二进制日志位置

mysql -e "SHOW MASTER LOGS;"+------------------+-----------+| Log_name         | File_size |+------------------+-----------+| mysql-bin.000003 |       245 |+------------------+-----------+

配置mysqlslave1

1.修改配置文件

vim /etc/my.cnf[mysqld]read-onlyserver-id=5

2.启动服务

systemctl start mariadb

3.数据库同步

CHANGE MASTER TO  MASTER_HOST='192.168.15.114',MASTER_USER='repluser',MASTER_PASSWORD='centos',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=245;

4.启动复制线程

MariaDB [(none)]> START SLAVE;MariaDB [(none)]> SHOW SLAVE STATUS\G;

6.测试主从复制

MariaDB [(none)]> CREATE DATABASE DB1;
  • 从服务器查看是否同步

配置mysqlslave2

1.修改配置文件

vim /etc/my.cnf[mysqld]read-onlyserver-id=6

2.启动服务

systemctl start mariadb

3.数据库同步

CHANGE MASTER TO  MASTER_HOST='192.168.15.114',MASTER_USER='repluser',MASTER_PASSWORD='centos',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=245;

4.启动复制线程

MariaDB [(none)]> START SLAVE;MariaDB [(none)]> SHOW SLAVE STATUS\G;

6.测试主从复制

MariaDB [(none)]> CREATE DATABASE DB2;
  • 从服务器查看是否同步

配置ProxySQL

1.在ProxySQL主机上配置yum源

  • ProxySQL内置了一个轻量级的数据库,所以需要有MySQL客户端连上去对其进行配置
  • cat <<EOF | tee /etc/yum.repos.d/proxysql.repo

    [proxysql_repo]
    name= ProxySQL YUM repository
    baseurl=
    gpgcheck=1
    gpgkey=
    EOF
    yum repolist
    yum install proxysql mariadb -y

    2.启动ProxySQL服务

    service proxysql start

    3.连接管理端口

    mysql -uadmin -padmin -P6032 -h127.0.0.1

    4.将MySQL主从服务器信息添加入mysql_servers表中

  • 向ProxySQL中添加MySQL主从服务器,proxysql根据read-only,自动分到读组和写组
  • MySQL [(none)]>insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.15.115',3306);

    MySQL [(none)]>insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.15.116',3306);
    MySQL [(none)]> select * from mysql_servers;

    5.在MySQL服务器的主节点上为ProxySQL添加账号用来查看MySQL节点是主还是从

    MariaDB [(none)]> grant replication client on . to monitor@'192.168.15.%' identified by 'centos';

    6.在Proxy上配置监控账号

    MySQL [(none)]> set mysql-monitor_username='monitor';

    MySQL [(none)]> set mysql-monitor_password='centos';

    7.将配置加载至内存,将配置保存至磁盘

    MySQL [(none)]> load mysql variables to runtime;

    MySQL [(none)]> save mysql variables to disk;

    8.测试,监控模块的指标保存在monitor库的log表中

  • 查看监控连接是否正常的 (对connect指标的监控):(如果connect_error的结果为NULL则表示正常)
  • MySQL> select from mysql_server_connect_log;

    MySQL> select from mysql_server_ping_log;

    9.在master节点上创建一个账户让客户端连接调度器去访问主从服务器

    MySQL> grant all on . to sqluser@'192.168.15.%' identified by 'centos';

    10.设置读写分组

  • 在ProxySQL配置,将用户sqluser添加到mysql_users表中, default_hostgroup默认组设置为写组10,当读写分离的路由规则不符合时,会访问默认组的数据库
  • MySQL [(none)]> insert into mysql_replication_hostgroups VALUES(10,20,"test");

    MySQL [(none)]> SELECT * FROM mysql_replication_hostgroups;
    +------------------+------------------+---------+
    | writer_hostgroup | reader_hostgroup | comment |
    | 10 | 20 | test |
    +------------------+------------------+---------+

11.让读写表生效

MySQL>  load mysql users to runtime;

12.查看mysql_server表此时已经将服务器分组

MySQL [(none)]> SELECT * FROM mysql_servers;

13.保存配置至磁盘

MySQL>  save mysql users to disk;

定义读写分离规则

1.在ProxySQL服务器上,将sqluser用户添加至mysql_users表中

MySQL [(none)]> INSERT INTO mysql_users(username,password,default_hostgroup) VALUES ('sqluser','centos',10);

2.查看mysql_user表信息

MySQL [(none)]> SELECT * FROM mysql_users;

3.生效存盘

MySQL [(none)]> load mysql users to runtime;MySQL [(none)]> save mysql variables to disk;

4.在ProxySQL上定义调度规则

MySQL [(none)]> INSERT INTO mysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply) VALUES (1,1,'^SELECT.*FOR UPDATE$',10,1),(2,1,'^SELECT',20,1);

5.查看定义规则

MySQL [(none)]> select * from mysql_query_rules\G;

6.生效存盘

MySQL [(none)]> load mysql users to runtime;MySQL [(none)]> save mysql variables to disk;

在192.168.15.117z主机测试

[root@centos7 ~]# mysql -usqluser -pcentos -h192.168.15.113 -P6033 -e "SELECT @@server_id;"[root@centos7 ~]# mysql -usqluser -pcentos -h192.168.15.113 -P6033 -e 'begin;use db1;insert t1 values(1);select @@server_id;commit'

二.配置NFS

配置NFS

yum install nfs-utils -y

在apache1,apache2主机上查看apache用户id

id apacheuid=997(apache) gid=995(apache) groups=995(apache)id apacheuid=997(apache) gid=995(apache) groups=995(apache)

在nfs上创建一个apache用户,将来访问的用户映射成apache用户

useradd -r -u 48  -s /sbin/nologin apacheid apacheuid=48(apache) gid=48(apache) groups=48(apache)

创建出共享的目录

mkdir /data/html

定义共享规则

vim /etc/exports/data/html 192.168.15.111(rw,no_root_squash,anonuid=997,anongid=995) 192.168.15.112(rw,no_root_squash,anonuid=997,anongid=995)systemctl restart nfs

配置nfs实时备份

1.在nfs和nfsbak服务器上安装rsync

yum -y install rsync

2.在nfsbak端配置为rsync服务

mkdir /data/backupvim /etc/rsyncd.confuid = root                          gid = root use chroot = no max connections = 0log file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidreverse lookup = nohost allow = 192.168.15.118[backup]path = /data/backup/comment = backupreadonly = noauth users = rsyncusersecrets file = /etc/rsync.pass

3.生成验证用的账户密码,修改为安全权限

echo "rsyncuser:centos" > /etc/rsync.passchmod 600 /etc/rsync.pass

4..启动服务

systemctl start rsyncd

5.nfs端配置,测试rsync一次性任务

yum install inotify-tools -yecho "centos" > /etc/rsync.passchmod 600 /etc/rsync.passtouch /data/html/testrsync -avz --password-file=/etc/rsync.pass /data/html/ rsyncuser@192.168.15.119::backup

让inotify配合sync实时同步

1.在nfs端创建脚本

vim rsync.sh #!/bin/bashSRC='/data/html/'DEST='rsyncuser@192.168.15.119::backup'inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib ${SRC} |while read DATE TIME DIR FILE;doFILEPATH=${DIR}${FILE}rsync -az --delete --password-file=/etc/rsync.pass $SRC $DEST && echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync" >> /var/log/changelist.logdone

2.运行脚本

bash rsync.sh

3.在nfs端创建文件测试

touch /data/html/f1

三.部署Apache+PHP

分别在2台httpd主机上源码编译安装httpd

yum install php-fpm php-mysql -y

1.配置apache+php(1)服务器

vim /app/httpd24/conf/httpd.confDirectoryIndex index.php index.htmlLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.soaddtype application/x-httpd-php-source .phpsproxyrequests offproxypassmatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost/data/html
servername www.mylinuxops.comDocumentroot /data/html
require all granted

2.修改php.ini中的时区

vim /etc/php.inidate.timezone = Aisa/Shanghai

3.修改php-fpm配置文件配置为(UDS模式)

vim /etc/php-fpm.d/www.conf ;listen = 127.0.0.1:9000listen = /var/run/php.sock;listen.allowed_clients = 127.0.0.1listen.mode = 0666

4.将nfs共享目录挂载至apache服务器

showmount -e 192.168.15.118vim /etc/fstab192.168.15.118:/data/html       /data/html     nfs      defaults        0 0mount -adf

5.在apache下的共享目录创建站点测试页

vim /data/html/index.php

6.测试访问

7.RS脚本配置

vim VS.sh#!/bin/bashvip='10.0.0.100'iface='lo:1'mask='255.255.255.255'dev=lo:1case $1 instart)echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 1 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 2 > /proc/sys/net/ipv4/conf/all/arp_announceecho 2 > /proc/sys/net/ipv4/conf/lo/arp_announceifconfig $dev $vip netmask $mask #broadcast $vip up#route add -host $vip dev $dev;;stop)ifconfig $dev downecho 0 > /proc/sys/net/ipv4/conf/all/arp_ignoreecho 0 > /proc/sys/net/ipv4/conf/lo/arp_ignoreecho 0 > /proc/sys/net/ipv4/conf/all/arp_announceecho 0 > /proc/sys/net/ipv4/conf/lo/arp_announce;;*)echo "Usage: $(basename $0) start|stop"exit 1;;esacbash RS.sh

配置路由和LVS

配置路由启用ip_forward转发

vim /etc/sysctl.confnet.ipv4.ip_forward = 1sysctl -pifconfig ens33:1 10.0.0.200/24

配置LVS

配置

yum install ipvsadm net-tools -yvim VS.sh#!/bin/bashvip='10.0.0.100'iface='lo:1'mask='255.255.255.255'port='80'rs1='192.168.15.111'rs2='192.168.15.112'scheduler='wrr'type='-g'case $1 instart)ifconfig $iface $vip netmask $mask #broadcast $vip upiptables -Fipvsadm -A -t ${vip}:${port} -s $scheduleripvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1;;stop)ipvsadm -Cifconfig $iface down;;*)echo "Usage $(basename $0) start|stop"exit 1esacbash VS.sh

搭建PowerDNS

搭建LAM

1.安装amp

yum install httpd php php-mysql mariadb-server -ysystemctl start httpd mariadb

2.安装PowerDNS

yum install pdns pdns-backend-mysql -ymysql < pdns.sql vim /etc/pdns/pdns.conf launch=gmysqlgmysql-host=localhostgmysql-port=3306gmysql-dbname=powerdnsgmysql-user=powerdnsgmysql-password=centos

3.启动powerdns

systemctl start pdns systemctl enable pdns

4.安装PowerDNS的WEB管理界面

yum -y install httpd php php-devel php-gd php-mcrypt php-imap phpldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring phpmcrypt php-mhash gettextsystemctl restart httpd mariadbsystemctl enable httpd mariadbtar xf poweradmin-2.1.7.tgz -C /var/www/html/mv /var/www/html/poweradmin-2.1.7 /var/www/html/poweradmin

5.访问web界面

rm -rf /var/www/html/poweradmin/install

Lamp架构扩展

使用client客户端访问

访问www.mylinuxops.com

转载于:https://blog.51cto.com/13586612/2400438

你可能感兴趣的文章
万能adapter
查看>>
开发指南专题六:JEECG微云高速开发平台代码生成
查看>>
cocos2d-x 游戏优化方案
查看>>
1.3 Quick Start中 Step 6: Setting up a multi-broker cluster官网剖析(博主推荐)
查看>>
remote desktop connection manager
查看>>
开源库RxJava、ButterKnife
查看>>
JDK内置工具jstack(Java Stack Trace)(转)
查看>>
百度之星 / 初赛第二场 B题
查看>>
Http压测工具wrk使用指南
查看>>
Excel VBA 循环“我中毒了~”
查看>>
CSS 教程Part4 [盒子模型](摘录自 W3C School)
查看>>
android开发技巧
查看>>
五个有趣的拓扑变换问题 [转]
查看>>
asp.net中的比较完美的验证码
查看>>
HDU 3277 Marriage Match III(最大流+二分+并查集)
查看>>
FPSMeter – 简单的、可定制主题的 FPS 仪表库
查看>>
Android应用中使用百度地图API定位自己的位置(二)
查看>>
24点经典算法
查看>>
内核及其组成部分
查看>>
.NET 程序集单元测试工具 SmokeTest 应用指南
查看>>