• nginx反代+lamp+MySQL主从同步的简单实现


    五台机器,一台做nginx,两台MySQL主从,两台web
    系统软件环境:centos6.5
    php/5.6.40
    Apache/2.2.15
    mysql/5.6.49
    nginx/1.10.3
    防火墙关闭,selinux禁用
    ##都是使用RPM包搭建##

    1.首先搭建MySQL主从同步(MySQL5.6)
    每台MySQL主机执行:
    获取MySQL源:rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm
    yum clean all;yum repolist
    yum list installed |grep mysql
    yum repolist all|grep mysql
    yum-config-manager --enable mysql56-community
    yum-config-manager --disable mysql80-community
    yum install mysql-community-server
    rpm -qal mysql-community-server
    service mysqld start
    主库配置:在/etc/my.cnf启用binlog,设置server_id,并且GRANT语句创建复制数据的用户,授予replication slave权限以及授权从库主机

    mysql> GRANT REPLICATION SLAVE ON *.* TO 'replicater'@'192.168.4.%' IDENTIFIED BY 'pwd123';
    主库执行:show master statusG;
    从库配置:在/etc/my.cnf设置server_id要与主库ID不同,然后指定主库信息CHANGE MASTER TO....,最后启动START SLAVE;

    1. mysql> CHANGE MASTER TO MASTER_HOST='192.168.4.10',
    2. -> MASTER_USER='replicater',
    3. -> MASTER_PASSWORD='pwd123',
    4. -> MASTER_LOG_FILE='dbsvr1-bin.000002',     //对应Master的日志文件
    5. -> MASTER_LOG_POS=334;                         //对应Master的日志偏移位置
    6. Query OK, 0 rows affected, 2 warnings (0.12 sec)


    从库:show slave statusG;

    2.安装Apache httpd+PHP(5.6)
    yum list installed |grep httpd
    yum install httpd
    rpm -qal httpd
    service httpd start
    yum list installed | grep php
    PHP5.6需要安装yum源:rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
    yum -y install php56w.x86_64
    yum -y --enablerepo=webtatic install php56w-devel
    yum -y install php56w-pdo php56w-xml php56w-gd php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
    yum -y install php56w-fpm
    php -v
    service php-fpm start

    php连接MySQL驱动:https://www.php.net/manual/en/ref.pdo-mysql.php
    3.nginx做反向代理
    yum install nginx
    vim /etc/nginx/nginx.conf
    在nginx.conf的http模块中定义后端web:upstream XXX{server web1:80;server web2:80;}
    在server模块的location中应用proxy_pass http://XXX;

  • 相关阅读:
    程序员练手项目
    文件描述符
    安卓深度探索(卷一)第九章
    安卓深度探索(卷一)第十章
    安卓深度探索(卷一)第八章
    安卓深度探索(卷一)第六章
    安卓深度探索(卷一)第七章
    安卓深度探索(卷一)第五章
    记一次联想A820t救砖线刷
    记一次酷派尚锋Y75刷机
  • 原文地址:https://www.cnblogs.com/Haihong72H/p/13337559.html
Copyright © 2020-2023  润新知