• mongo 集群


    1 sder@sder-kvm-yangpeng:~/go/src/epc/services$ (master) cat .env
    2 VER=1.0
    3 WORKDIR=/usr/local/epc/install
    4 UPFDIR=/home/sder/go/bin
    5 REPOSITORY=10.18.1.2:5000
    6 IMAGE=epc:dev-deploy
    7 UPFIMAGE=epcupf:dev-deploy
    8 TIMEZONE=Asia/Shanghai
    9 LOGDIR=/usr/local/epc/install/var/log/epc
    .env
      1 sder@sder-kvm-yangpeng:~/go/src/epc/services$ (master) cat docker-compose.yml
      2 version: '3.3'
      3 services:
      4   epc-redis:
      5     container_name: epc-redis-${VER}
      6     hostname: redis
      7     image: ${REPOSITORY}/redis:6.0.9
      8     ports:
      9       - "6379:6379"
     10     volumes:
     11       - ./config/redis/redis.conf:/etc/redis/redis.conf
     12       - ./config/redis/data:/data
     13       - /etc/localtime:/etc/localtime:ro
     14     restart: always
     15     extra_hosts:
     16       - "redis:127.0.0.1"
     17     environment:
     18       - TZ=${TIMEZONE}
     19 
     20   epc-mysql:
     21     container_name: epc-mysql-${VER}
     22     hostname: mysql
     23     image: ${REPOSITORY}/mysql:5.7
     24     ports:
     25       - "3306:3306"
     26     volumes:
     27       - ./config/mysql/.data:/var/lib/mysql
     28       - ./config/mysql/conf:/etc/mysql/mysql.conf.d
     29       - ./config/mysql/script:/docker-entrypoint-initdb.d/
     30       - /etc/localtime:/etc/localtime:ro
     31     restart: always
     32     extra_hosts:
     33       - "mysql:127.0.0.1"
     34     environment:
     35       - MYSQL_ROOT_PASSWORD=123456
     36       - TZ=${TIMEZONE}
     37 
     38   epc-mongo:
     39     container_name: epc-mongo-${VER}
     40     hostname: mongo
     41     image: ${REPOSITORY}/mongo:latest
     42     ports:
     43       - "27017:27017"
     44     volumes:
     45       - ./config/mongo/.data:/data/db
     46       - /etc/localtime:/etc/localtime:ro
     47     restart: always
     48     entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "mongo-replica" ]
     49     extra_hosts:
     50       - "mongo:127.0.0.1"
     51     environment:
     52       - TZ=${TIMEZONE}
     53 
     54   epc-mongo-arb:
     55     container_name: epc-mongo-arb-${VER}
     56     hostname: mongo
     57     image: ${REPOSITORY}/mongo:latest
     58     ports:
     59       - "27018:27017"
     60     volumes:
     61       - ./config/mongo/.dataarb:/data/db
     62       - /etc/localtime:/etc/localtime:ro
     63     restart: always
     64     entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "mongo-replica" ]
     65     extra_hosts:
     66       - "mongo:127.0.0.1"
     67     environment:
     68       - TZ=${TIMEZONE}
     69 
     70   epc-nginx:
     71     container_name: epc-nginx-${VER}
     72     hostname: nginx
     73     image: ${REPOSITORY}/nginx:latest
     74     ports:
     75       - "80:80"
     76     volumes:
     77       - ./config/default.conf:/etc/nginx/conf.d/default.conf
     78       - ./config/dev.tar.gz:/home/root/dev.tar.gz
     79       - /etc/localtime:/etc/localtime:ro
     80     restart: always
     81     extra_hosts:
     82       - "nginx:127.0.0.1"
     83     environment:
     84       - TZ=${TIMEZONE}
     85 
     86   epc-web:
     87     container_name: epc-web-${VER}
     88     hostname: web
     89     image: ${REPOSITORY}/java:latest
     90     volumes:
     91       - ./config/core-network-epc-1.0.0.jar:/home/web/core-network-epc-1.0.0.jar
     92       - ./config/start_lmt_epc.sh:/home/web/start_lmt_epc.sh
     93       - /etc/localtime:/etc/localtime:ro
     94     depends_on:
     95       - epc-mysql
     96       - epc-mongo
     97       - epc-nginx
     98     restart: always
     99     network_mode: host
    100     extra_hosts:
    101       - "web:127.0.0.1"
    102     environment:
    103       - TZ=${TIMEZONE}
    104     entrypoint: [ "bash", "/home/web/start_lmt_epc.sh" ]
    105 
    106   epc-mmed:
    107     container_name: epc-mmed-${VER}
    108     hostname: mmed
    109     image: ${REPOSITORY}/${IMAGE}
    110     volumes:
    111       - ./var/log/epc:${WORKDIR}/var/log/epc/
    112       - ./etc/:${WORKDIR}/etc/
    113       - /etc/localtime:/etc/localtime:ro
    114     depends_on:
    115       - epc-mongo
    116     restart: always
    117     network_mode: host
    118     extra_hosts:
    119       - "mmed:127.0.0.1"
    120     environment:
    121       - TZ=${TIMEZONE}
    122     entrypoint: [ "epc-mmed", "-l", "${LOGDIR}/mmed.log" ]
    123 
    124   epc-hssd:
    125     container_name: epc-hssd-${VER}
    126     hostname: hssd
    127     image: ${REPOSITORY}/${IMAGE}
    128     volumes:
    129       - ./var/log/epc:${WORKDIR}/var/log/epc/
    130       - ./etc/:${WORKDIR}/etc/
    131       - /etc/localtime:/etc/localtime:ro
    132     depends_on:
    133       - epc-mongo
    134     restart: always
    135     network_mode: host
    136     extra_hosts:
    137       - "hssd:127.0.0.1"
    138     environment:
    139       - TZ=${TIMEZONE}
    140     #command: sleep infinity
    141     entrypoint: [ "epc-hssd", "-l", "${LOGDIR}/hssd.log" ]
    142 
    143   epc-pcrfd:
    144     container_name: epc-pcrfd-${VER}
    145     hostname: pcrfd
    146     image: ${REPOSITORY}/${IMAGE}
    147     volumes:
    148       - ./var/log/epc:${WORKDIR}/var/log/epc/
    149       - ./etc/:${WORKDIR}/etc/
    150       - /etc/localtime:/etc/localtime:ro
    151     depends_on:
    152       - epc-mongo
    153     restart: always
    154     network_mode: host
    155     extra_hosts:
    156       - "pcrfd:127.0.0.1"
    157     environment:
    158       - TZ=${TIMEZONE}
    159     entrypoint: [ "epc-pcrfd", "-l", "${LOGDIR}/pcrfd.log" ]
    160 
    161   epc-pgwd:
    162     container_name: epc-pgwd-${VER}
    163     hostname: pgwd
    164     image: ${REPOSITORY}/${IMAGE}
    165     volumes:
    166       - ./var/log/epc:${WORKDIR}/var/log/epc/
    167       - ./etc/:${WORKDIR}/etc/
    168       - /etc/localtime:/etc/localtime:ro
    169     depends_on:
    170       - epc-mongo
    171     restart: always
    172     network_mode: host
    173     extra_hosts:
    174       - "pgwd:127.0.0.1"
    175     environment:
    176       - TZ=${TIMEZONE}
    177     entrypoint: [ "epc-pgwd", "-l", "${LOGDIR}/pgwd.log" ]
    178 
    179   epc-sgwd:
    180     container_name: epc-sgwd-${VER}
    181     hostname: sgwd
    182     image: ${REPOSITORY}/${IMAGE}
    183     volumes:
    184       - ./var/log/epc:${WORKDIR}/var/log/epc/
    185       - ./etc/:${WORKDIR}/etc/
    186       - /etc/localtime:/etc/localtime:ro
    187     depends_on:
    188       - epc-mongo
    189     restart: always
    190     network_mode: host
    191     extra_hosts:
    192       - "sgwd:127.0.0.1"
    193     environment:
    194       - TZ=${TIMEZONE}
    195     entrypoint: [ "epc-sgwd", "-l", "${LOGDIR}/sgwd.log" ]
    196 
    197   epc-upf:
    198     container_name: epc-upf-${VER}
    199     hostname: upf
    200     image: ${REPOSITORY}/${UPFIMAGE}
    201     volumes:
    202       - ./logs:${UPFDIR}/logs
    203       - ./config:${UPFDIR}/config
    204       - ./config/dpdk/usertools:${UPFDIR}/dpdk/usertools
    205       - /etc/localtime:/etc/localtime:ro
    206       - /sys/bus/pci/devices:/sys/bus/pci/devices
    207       - /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages
    208       - /sys/devices/system/node:/sys/devices/system/node
    209       - /dev:/dev:ro
    210       - /sbin:/sbin:ro
    211       - /bin:/bin:ro
    212     restart: always
    213     privileged: true
    214     user: root
    215     extra_hosts:
    216       - "upf:127.0.0.1"
    217     network_mode: host
    218     environment:
    219       - TZ=${TIMEZONE}
    220     working_dir: ${UPFDIR}
    221 #    command: sleep infinity
    222     entrypoint: [ "./upf.sh" ]
    docker-compose.yml
     1 sder@sder-kvm-yangpeng:~/go/src/epc/services$ (master) cat config/setupcluster.sh
     2 #!/bin/bash
     3 
     4 master="10.18.1.72"
     5 primary=${master}":27017"
     6 
     7 slave="10.18.1.101"
     8 second=${slave}":27017"
     9 
    10 arb=${slave}":27018"
    11 
    12 ver="1.0"
    13 
    14 cmd="rs.initiate({_id:\"mongo-replica\",members:[{_id:0,host:\"$primary\",priority:6},{_id:1,host:\"$second\",priority:3}]})"
    15 docker exec epc-mongo-$ver bash -c "mongo --eval "$cmd""
    16 
    17 sleep 30
    18 
    19 cmd="rs.addArb(\"$arb\")"
    20 docker exec epc-mongo-$ver bash -c "mongo --eval "$cmd""
    setupcluster.sh
    step:

    1.在机器10.18.1.72、10.18.1.101机器上,搭建集群。10.18.1.72、10.18.1.101都部署epc-mongo,epc-mongo-arb。
     在两机器上,docker-compose up -d epc-mongo epc-mongo-arb。此后,两台机器独立运行epc-mongo,epc-mongo-arb,无集群关联。
    2.计划使用master="10.18.1.72"作为主,slave="10.18.1.101"作为备。
    在10.18.1.72,bash config/setupcluster.sh
    docker exec epc-mongo-1.0 bash -c 'mongo --eval "rs.initiate({_id:"mongo-replica",members:[{_id:0,host:"10.18.1.72:27017",priority:6},{_id:1,host:"10.18.1.101:27017",priority:3}]})"'
    上行命令是将两容器添加集群,并设置优先级。
    docker exec epc-mongo-1.0 bash -c 'mongo --eval "rs.addArb("10.18.1.101:27018")"'
    上行命令是将添加arb节点。
    3.进入72,epc-mongo,mongo-replica:PRIMARY>
    进入101,epc-mongo,mongo-replica:SECONDARY>
    4.stop 72上epc-mongo,101上,epc-mongo切换到,mongo-replica:PRIMARY>
    5.start 72上epc-mongo,进入72,epc-mongo,mongo-replica:PRIMARY> 进入101,epc-mongo,mongo-replica:SECONDARY>
    MongoDB Compass 
    mongodb://10.18.1.72:27017,10.18.1.101:27017/epc
  • 相关阅读:
    [Swift通天遁地]五、高级扩展-(2)扩展集合类型
    [Swift通天遁地]五、高级扩展-(1)快速检测设备属性:版本、类型、屏幕尺寸
    [Swift]LeetCode266.回文全排列 $ Palindrome Permutation
    [Swift]LeetCode265.粉刷房子 II $ Paint House II
    [Swift]LeetCode264.丑数 II | Ugly Number II
    [Swift通天遁地]四、网络和线程-(15)程序内购功能
    [Swift通天遁地]四、网络和线程-(14)创建一个Socket服务端
    hdu 4888 Redraw Beautiful Drawings(最大流,判环)
    【剑指offer】斐波那契序列与跳台阶
    Asp.NET之对象学习
  • 原文地址:https://www.cnblogs.com/cjyp/p/15049475.html
Copyright © 2020-2023  润新知