zoukankan      html  css  js  c++  java
  • rancher 2.X 搭建小型web集群+mysql主从复制

    一,环境配置

         rancher 2.1.6

    二,配置harbor私有仓库

      见上文

    三,配置私有镜像

       01,总文件

       

       dockerfile 为主配置文件,html 为站点文件wordpress.,官网下载更加

     1 FROM centos:7.4.1708
     2 MAINTAINER kingle
     3 ENV PHP_VARSION 5.5.32
     4 ENV NGINX_VERSION 1.14.0
     5 ADD . /usr/local/share/
     6 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
     7 RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && 
     8     curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
     9 RUN yum install -y pcre pcre-devel openssl openssl-devel gcc make gcc-c++
    10 RUN cd /usr/local/share/ && tar zxf nginx-1.14.0.tar.gz && 
    11     useradd www -s /bin/nologin -M
    12 WORKDIR /usr/local/share/nginx-1.14.0/
    13 RUN ./configure --user=www --group=www 
    14     --prefix=/application/nginx 
    15     --with-http_stub_status_module --with-http_ssl_module && 
    16     make -j 4 && make install
    17 RUN yum install vim net-tools zlib-devel openssl-devel openssl libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel libmcrypt-devel mcrypt mhash -y
    18 RUN cd /usr/local/share/ && tar zxf libmcrypt-2.5.8.tar.gz && tar zxf mcrypt-2.6.8.tar.gz && tar zxf mhash-0.9.9.9.tar.gz
    19 RUN cd /usr/local/share/libmcrypt-2.5.8 && 
    20     ./configure && make && make install && 
    21     ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config && 
    22     export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    23 RUN cd /usr/local/share/mhash-0.9.9.9 && 
    24     ./configure && make && make install
    25 RUN cd /usr/local/share/mcrypt-2.6.8 && 
    26     ./configure && make && make install
    27 RUN cd /usr/local/share/ && tar zxf libiconv-1.14.tar.gz && 
    28     tar zxf php-5.5.32.tar.gz && 
    29     cd /usr/local/share/libiconv-1.14 && 
    30     sed -i -e '/gets is a security/d' srclib/stdio.in.h && 
    31     ./configure --prefix=/usr/local/libiconv && make -j 4 && make install
    32 RUN cd /usr/local/share/php-5.5.32 && ./configure --prefix=/application/php --with-fpm-user=www 
    33     --with-fpm-group=www 
    34     --with-iconv=/usr/local/libiconv 
    35     --with-mysqli 
    36     --with-pdo-mysql 
    37     --with-openssl 
    38     --with-gd 
    39     --with-zlib 
    40     --with-gettext 
    41     --with-curl 
    42     --with-png-dir 
    43     --with-jpeg-dir 
    44     --with-freetype-dir 
    45     --with-xmlrpc 
    46     --with-mhash 
    47     --with-openssl 
    48     --enable-fpm 
    49     --enable-xml 
    50     --enable-shmop 
    51     --enable-sysvsem 
    52     --enable-inline-optimization 
    53     --enable-mbregex 
    54     --enable-mbstring 
    55     --enable-ftp 
    56     --enable-gd-native-ttf 
    57     --enable-mysqlnd 
    58     --enable-pcntl 
    59     --enable-sockets 
    60     --enable-zip 
    61     --enable-soap 
    62     --enable-session 
    63     --enable-bcmath 
    64     --enable-exif 
    65     --enable-fileinfo 
    66     --enable-opcache=no 
    67     --disable-rpath 
    68     --disable-debug 
    69     --without-pear && 
    70      touch ext/phar/phar.phar && 
    71       make -j 4 && make install && 
    72     cp ./php.ini-production /application/php/lib/php.ini && 
    73     cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && 
    74     cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
    75 RUN chmod +x /etc/init.d/php-fpm
    76 RUN echo "export PATH=$PATH:/application/php/sbin/:/application/nginx/sbin/" >>/etc/profile && source /etc/profile
    77 add start.sh /root/start.sh
    78 RUN /etc/init.d/php-fpm start
    79 RUN chmod +x /root/start.sh
    80 WORKDIR /application/
    81 ADD html/conf/nginx.conf /application/nginx/conf/nginx.conf
    82 CMD ["/application/nginx/sbin/nginx","-c","/application/nginx/conf/nginx.conf"]

        02,构建镜像

    docker build -t web-11:v3 .

         03,搭建mysql镜像

              可以通过官方的docker镜像源进行安装比较块

    wget https://codeload.github.com/docker-library/mysql/zip/master

       另一种自定义:

        

     1 [root@k8s3 mysql]# cat docker-compose.yml
     2 version: '2'
     3 services:
     4   mysql-master:
     5     build:
     6       context: ./
     7       dockerfile: master/Dockerfile
     8     environment:
     9       - "MYSQL_ROOT_PASSWORD=root"
    10       - "MYSQL_DATABASE=replicas_db"
    11     links:
    12       - mysql-slave
    13     ports:
    14       - "33065:3306"
    15     restart: always
    16     hostname: mysql-master
    17   mysql-slave:
    18     build:
    19       context: ./
    20       dockerfile: slave/Dockerfile
    21     environment:
    22       - "MYSQL_ROOT_PASSWORD=root"
    23       - "MYSQL_DATABASE=replicas_db"
    24     ports:
    25       - "33066:3306"
    26     restart: always
    27     hostname: mysql-slave
    1 [root@k8s3 mysql]# cat master/Dockerfile
    2 FROM mysql:5.7.17
    3 MAINTAINER kingle
    4 ADD ./master/my.cnf /etc/mysql/my.cnf
    5 EXPOSE 3306
    6 CMD ["mysqld"]
    [root@k8s3 mysql]# cat master/my.cnf
    [mysqld]
    server_id=100
    binlog-ignore-db=mysql
    log-bin=replicas-mysql-bin
    binlog_cache_size=1M
     binlog_format=mixed
    expire_logs_days=7
    slave_skip_errors=1062
    1 [root@k8s3 mysql]# cat slave/Dockerfile
    2 FROM mysql:5.7.17
    3 MAINTAINER kingle
    4 ADD ./slave/my.cnf /etc/mysql/my.cnf
    5 EXPOSE 3306
    6 CMD ["mysqld"]
     1 [root@k8s3 mysql]# cat slave/my.cnf
     2 [mysqld]
     3 server_id=101
     4 binlog-ignore-db=mysql
     5 log-bin=replicas-mysql-slave1-bin
     6 binlog_cache_size=1M
     7  binlog_format=mixed
     8 expire_logs_days=7
     9 slave_skip_errors=1062
    10 relay_log=replicas-mysql-relay-bin
    11 log_slave_updates=1
    12 read_only=1

    运行命令:

       1 docker-compose up -d 

    等待配置完成

    四,push镜像到harbor

        

      docker images 可以看见编排出来的包,

      这三个包弄了一下午的编排

      

      

    docker tag 192.168.0.167/web/ngphp:v0.1 192.168.0.167/web/ngphp:v3
    docker tag 192.168.0.167/web/mysql-slave:0.1 192.168.0.167/web/mysql-slave:v0.1
    docker tag 192.168.0.167/web/mysql-master:0.1 192.168.0.167/web/mysql-master:v0.1

      登入harbor私有仓库

     

    docker push 192.168.0.167/web/web1:v0.1
    docker push 192.168.0.167/web/mysql-master:v0.1
    docker push 192.168.0.167/web/mysql-slave:v0.1

      到harbor查看

      

      上传成功了

    五,rancher 搭建

        配置rancher

     

    等待启动完成

    站点访问:

      

    六,配置数据库主从

       主库从库搭建就命名不一样,其余参照下面搭建

      

       点击启动即可

          查看你

      查看主库ip

    命令编辑

      授权给从库

      create user 'repl'@'%' identified by '123456'
      GRANT REPLICATION SLAVE ON *.* to 'rep1'@'%' identified by '123456';
      FLUSH PRIVILEGES;
      show mater slave

     从库配置

      

    1 CHANGE MASTER TO MASTER_HOST='10.42.1.31', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='replicas-mysql-bin.000003',MASTER_LOG_POS=1144353;

       发现一个问题:

      解决:

      主库:

      刷写日志: 记录好binlog 和pos

      

      从库

      stop slave

    stop slave ;
    reset slave;
    CHANGE MASTER TO MASTER_HOST='10.42.1.31', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='replicas-mysql-bin.000004',MASTER_LOG_POS=154;
    start slave;

        

        成功解决

        

        从库也一样了

    七,wordpress 配置

        根据步骤填写,回不去,少了截图,大家正常发挥,有问题联系,邮箱在下面.

        点击安装即可

      

  • 相关阅读:
    源码浅析:MySQL一条insert操作,会写哪些文件?包括UNDO相关的文件吗?
    20201024 --各位码农,节日快乐
    Redis的基本使用
    Oracle 11g与12c的审计详解
    Mac 终端 Tomcat 环境配置过程
    Oracle查询如何才能行转列?-sunziren
    Redis命令大全
    MySQL8.0数据库基础教程(二)-理解"关系"
    mysql 5.7.28 中GROUP BY报错问题 SELECT list is not in GROUP BY clause and contains no
    Flink知识散点
  • 原文地址:https://www.cnblogs.com/kingle-study/p/10428134.html
Copyright © 2011-2022 走看看