zoukankan      html  css  js  c++  java
  • 专职DBA-基于Dcoker环境初始化三台虚拟机

    -- 专职DBA-基于Dcoker环境初始化三台虚拟机
    -- 请提前安装好Docker环境。
    作者:周万春
    微信:lovemysql3306
    
    
    -- 构建CentOS-SSH系统镜像
    [root@mysql-host1 ~]# cd ./docker_images/Dockerfile/system/zhouwanchun-centos-ssh/
    
    
    [root@mysql-host1 ~/docker_images/Dockerfile/system/zhouwanchun-centos-ssh]# cat Dockerfile
    # Docker for CentOS
    # Base image
    FROM centos:7.9.2009
    # Who
    MAINTAINER zhouwanchun zhou_wanchun@163.com
    # EPEL
    RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
    # Base pkg
    RUN yum install -y openssl openssh-clients openssh-server openssl-devel supervisor sudo
    RUN yum -y install bash-completion bash-completion-extras 
                       vim vim-enhanced sudo 
                       iproute net-tools traceroute wget git lrzsz bind-utils 
                       screen tmux tree lsof telnet dos2unix 
                       mtr nc nmap tcpdump 
                       ntp ntpdate 
                       gcc gcc-c++ glibc make zlib-devel ncurses-devel libaio-devel 
                       tar zip unzip pigz gzip 
                       sysstat perf htop iftop iotop nethogs ps_mem psmisc iptraf dstat numactl bc 
                       OpenIPMI-tools openssl-devel 
                       xorg-x11-server-utils xorg-x11-utils xorg-x11-xauth 
                       httpd-tools sshpass 
        && yum clean all
    
    # For sshd
    RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
    RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
    RUN ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
    # Set root password
    RUN echo "root:mysql" | chpasswd
    # Supervisord config
    ADD supervisord.conf /etc/supervisord.conf
    ADD sshd.ini /etc/supervisord.d/sshd.ini
    # Outside port
    EXPOSE 22
    # Supervisord start
    CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
    
    
    -- supervisor主配置文件的变更只需要修改nodaemon=true
    [root@mysql-host1 ~/docker_images/Dockerfile/system/zhouwanchun-centos-ssh]# cat supervisord.conf | egrep -v "^;|^$"
    [unix_http_server]
    file=/var/run/supervisor/supervisor.sock   ; (the path to the socket file)
    [supervisord]
    logfile=/var/log/supervisor/supervisord.log  ; (main log file;default $CWD/supervisord.log)
    logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
    logfile_backups=10          ; (num of main logfile rotation backups;default 10)
    loglevel=info               ; (log level;default info; others: debug,warn,trace)
    pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
    nodaemon=true              ; (start in foreground if true;default false)
    minfds=1024                 ; (min. avail startup file descriptors;default 1024)
    minprocs=200                ; (min. avail process descriptors;default 200)
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    [supervisorctl]
    serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL  for a unix socket
    [include]
    files = supervisord.d/*.ini
    */
    
    
    [root@mysql-host1 ~/docker_images/Dockerfile/system/zhouwanchun-centos-ssh]# cat sshd.ini
    [program:sshd]
    command=/usr/sbin/sshd -D
    process_name=%(program_name)s
    autostart=true
    stdout_logfile_maxbytes=100MB
    stdout_logfile_backups=10
    
    
    [root@mysql-host1 ~/docker_images/Dockerfile/system/zhouwanchun-centos-ssh]# docker build -t zhouwanchun/centos-ssh:7.9.2009 .
    
    
    -- 创建网络
    [root@mysql-host1 ~]# docker network create --subnet=192.168.56.0/16 dbnet
    
    [root@mysql-host1 ~]# docker network ls
    NETWORK ID     NAME      DRIVER    SCOPE
    a216a032d7a3   bridge    bridge    local
    6a2ce16fc8a0   dbnet     bridge    local
    14004f866602   host      host      local
    d32520d61cf0   none      null      local
    
    [root@mysql-host1 ~]# docker network inspect dbnet
    [
        {
            "Name": "dbnet",
            "Id": "6a2ce16fc8a082aa66cd9fc42956efab1b2f7a41c3dd9c619813083bde0ca587",
            "Created": "2021-02-13T04:33:46.907260473+08:00",
            "Scope": "local",
            "Driver": "bridge",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": {},
                "Config": [
                    {
                        "Subnet": "192.168.56.0/16",
                        "Gateway": "192.168.0.1"
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {},
            "Options": {},
            "Labels": {}
        }
    ]
    
    
    -- /disk 软件工具共享存放
    -- /u01  数据库程序共享存放
    -- db01  计划放置不同的MySQL的data相关数据,需要持久化的数据都放在这里。
    [root@mysql-host1 ~]# mkdir -p /disk
    [root@mysql-host1 ~]# mkdir -p /u01
    [root@mysql-host1 ~]# mkdir -p /data/vm/{db01,db02,db03,mgr01,mgr02,mgr03,pxc01,pxc02,pxc03}
    
    
    -- 启动容器
    [root@mysql-host1 ~]# docker run -d --privileged -v /disk:/disk -v /u01:/u01 -v /data/vm/db01:/data -v /backup:/backup -p5611:22 --net dbnet --ip 192.168.56.11 --cap-add=NET_ADMIN --name=db01 --hostname=db01 zhouwanchun/centos-ssh:7.9.2009
    [root@mysql-host1 ~]# docker run -d --privileged -v /disk:/disk -v /u01:/u01 -v /data/vm/db02:/data -v /backup:/backup -p5612:22 --net dbnet --ip 192.168.56.12 --cap-add=NET_ADMIN --name=db02 --hostname=db02 zhouwanchun/centos-ssh:7.9.2009
    [root@mysql-host1 ~]# docker run -d --privileged -v /disk:/disk -v /u01:/u01 -v /data/vm/db03:/data -v /backup:/backup -p5613:22 --net dbnet --ip 192.168.56.13 --cap-add=NET_ADMIN --name=db03 --hostname=db03 zhouwanchun/centos-ssh:7.9.2009
    
    
    [root@mysql-host1 ~]# docker ps
    CONTAINER ID   IMAGE                             COMMAND                  CREATED          STATUS          PORTS                  NAMES
    82992f77595e   zhouwanchun/centos-ssh:7.9.2009   "/usr/bin/supervisor…"   8 seconds ago    Up 7 seconds    0.0.0.0:5613->22/tcp   db03
    09060282cf3d   zhouwanchun/centos-ssh:7.9.2009   "/usr/bin/supervisor…"   16 seconds ago   Up 15 seconds   0.0.0.0:5612->22/tcp   db02
    de2420658bd0   zhouwanchun/centos-ssh:7.9.2009   "/usr/bin/supervisor…"   25 seconds ago   Up 24 seconds   0.0.0.0:5611->22/tcp   db01
    
    
    -- 连接容器
    [root@mysql-host1 ~]# ssh root@192.168.56.11
    [root@mysql-host1 ~]# ssh root@192.168.56.12
    [root@mysql-host1 ~]# ssh root@192.168.56.13
    
    
    -- 宿主机ssh秘钥拷贝到容器虚拟机里面
    [root@mysql-host1 ~]# scp -rp ~/.ssh root@192.168.56.11:~/
    [root@mysql-host1 ~]# scp -rp ~/.ssh root@192.168.56.12:~/
    [root@mysql-host1 ~]# scp -rp ~/.ssh root@192.168.56.13:~/
    
    
    [root@mysql-host1 ~]# vim .bash_profile
    # ssh in docker.
    alias ssh1='/usr/bin/ssh db01'
    alias ssh2='/usr/bin/ssh db02'
    alias ssh3='/usr/bin/ssh db03'
    
    
    [root@mysql-host1 ~]# vim /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    
    # vmware.
    10.0.0.11   mysql-host1
    10.0.0.12   mysql-host2
    10.0.0.13   mysql-host3
    10.0.0.1    zhouwanchun
    
    # docker vm.
    192.168.56.11   db01 mgr01 pxc01
    192.168.56.12   db02 mgr02 pxc02
    192.168.56.13   db03 mgr03 pxc03
    
    
    [root@mysql-host1 ~]# ssh db01
    [root@mysql-host1 ~]# ssh db02
    [root@mysql-host1 ~]# ssh db03
    
    
    [root@mysql-host1 ~]# ssh1
    [root@mysql-host1 ~]# ssh2
    [root@mysql-host1 ~]# ssh3
    
    
    [root@mysql-host1 ~]# ./docker_in.sh db01
    [root@mysql-host1 ~]# ./docker_in.sh db02
    [root@mysql-host1 ~]# ./docker_in.sh db03
  • 相关阅读:
    转-iOS开发系列--地图与定位
    转-关于UIView的autoresizingMask属性的研究
    UIAlertController的使用,代替UIAlertView和UIActionSheet
    设置当前导航栏(navigationController)的标题
    tabBar隐藏方式
    ubuntu 安装qq 及解决安装完搜狗输入法不显示键盘的方法
    python 读写文件
    Ubuntu:如何显示系统托盘图标(systray)
    python tesseract 识别图片中的文字的乱码问题(ubuntu系统下)
    让Ubuntu可以压缩/解压缩RAR文件
  • 原文地址:https://www.cnblogs.com/zhouwanchun/p/14401272.html
Copyright © 2011-2022 走看看