docker安装gitlab,mysql,elasticsearch,redis.consul,rabbitmq

docker:18.05.0-ce-rc1

  • ubuntu版本 18.04 LTS(bionic)
    • 可使用如下命令查看
lsb_release -a
  • 运行如下脚本
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable edge test"
sudo apt-get update
sudo apt-get install -y docker-ce
  • 查看安装情况
docker version

gitlab:latest

  • 运行如下脚本(其中需要修改的地方如下)
    • hostname,external_url 需要修改成实际的ip
    • 邮件相关用户名密码修改成对应的值,密码在登录163邮箱后(设置->更多设置->客户端授权密码)进行设置
mkdir -p ~/docker/gitlab
cd ~/docker/gitlab
cat > docker-compose.yml <<EOF
m1:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: '192.168.2.218'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://192.168.2.218'
      gitlab_rails['gitlab_shell_ssh_port'] = 2224
      gitlab_rails['smtp_enable'] = true
      gitlab_rails['smtp_address'] = "smtp.163.com"
      gitlab_rails['smtp_port'] = 25
      gitlab_rails['smtp_user_name'] = "xxx@163.com"
      gitlab_rails['smtp_password'] = "xxx"
      gitlab_rails['smtp_domain'] = "163.com"
      gitlab_rails['smtp_authentication'] = "login"
      gitlab_rails['smtp_enable_starttls_auto'] = false
      gitlab_rails['smtp_openssl_verify_mode'] = "peer"

      gitlab_rails['gitlab_email_from'] = "xxx@163.com"
      user["git_user_email"] = "gitlab@163.com"
  ports:
    - '80:80'
    - '2224:22'
  volumes:
    - '/var/gitlab/config:/etc/gitlab'
    - '/var/gitlab/logs:/var/log/gitlab'
    - '/var/gitlab/data:/var/opt/gitlab'
EOF
  • 运行如下命令启动gitlab
docker-compose up -d
  • 浏览器访问 [ gitlab ]
  • 使用默认用户名(root)密码( 5iveL!fe)登录
  • Admin area–>settings –> Sign-in Restrictions去掉Sign-up enabled对勾

mysql:5.7

  • 运行如下脚本创建并启动mysql主从
mkdir -p ~/docker/mysql-5.7
cd ~/docker/mysql-5.7
cat > my.cnf<<EOF
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
symbolic-links=0
!includedir /etc/mysql/conf.d/
EOF
cat > hosts<<EOF
127.0.0.1   localhost
172.18.0.2  m1
172.18.0.3  s1
EOF
cat > docker-compose.yml <<EOF
version: '2'
services:
  m1:
    build: ./m1
    container_name: mysql_m1
    ports:
      - '3306:3306'
    volumes:
      - ./m1/my.cnf:/etc/mysql/conf.d/my.cnf
      - /etc/localtime:/etc/localtime
      - ./hosts:/etc/hosts
      - /var/mysql/m1:/var/lib/mysql
    networks:
      mysql:
        ipv4_address: 172.18.0.2
    ulimits:
      nproc: 65535
    hostname: m1
    mem_limit: 1024m
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 111111
  s1:
      build: ./s1
      container_name: mysql_s1
      ports:
        - '3307:3306'
      volumes:
        - ./s1/my.cnf:/etc/mysql/conf.d/my.cnf
        - /etc/localtime:/etc/localtime
        - ./hosts:/etc/hosts
        - /var/mysql/s1:/var/lib/mysql
      networks:
        mysql:
          ipv4_address: 172.18.0.3
      links:
        - m1
      ulimits:
        nproc: 65535
      hostname: s1
      mem_limit: 1024m
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: 111111
networks:
  mysql:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 172.18.0.0/24
        gateway: 172.18.0.1
EOF
mkdir m1
cd m1
cat >my.cnf<<EOF
[mysqld]
lower_case_table_names=1
server-id=2
log-bin=m1-bin
log-bin-index=m1-bin.index
EOF
cat >Dockerfile<<EOF
[mysqld]
FROM mysql:5.7
CMD ["mysqld"]
EOF
cd ..
mkdir s1
cd s1
cat >my.cnf<<EOF
[mysqld]
lower_case_table_names=1
server-id=3
log-bin=s1-bin
sync_binlog=1
EOF
cat >Dockerfile<<EOF
FROM mysql:5.7
CMD ["mysqld"]
EOF
cd ..
docker-compose up -d
  • 运行如下命令进入主数据库
docker exec -it mysql_m1 bash
mysql -u root -p111111
  • 运行如下命令创建数据库同步账号
    • 记录下控制台出现的File,Position的值
create user replica;
GRANT REPLICATION SLAVE ON *.* TO "replica"@"172.18.0.%" IDENTIFIED BY "replica123";
FLUSH TABLES WITH READ LOCK;
show master status;
exit;
  • 运行如下命令进入从数据库
docker exec -it mysql_s1 bash
mysql -u root -p111111
  • 运行如下命令同步从数据库
    • master_log_file,master_log_pos对应填写上面记录的File,Position的值
change master to master_host='m1',master_port=3306,master_user='replica',master_password='replica123',master_log_file='m1-bin.000004',master_log_pos=644;
start slave;
exit;
  • 进入主数据库
    docker exec -it mysql_m1 bash
    mysql -u root -p111111
    exit;
  • 创建数据库replica_db_test,用户replica_db_test_user
create user 'replica_db_test_user';
create database replica_db_testDEFAULT CHARSET utf8 COLLATE utf8_general_ci;  
grant all privileges on `replica_db_test`.* to 'replica_db_test_user'@'%' identified by '123456' WITH GRANT OPTION;
flush privileges;
exit;
  • 运行如下命令进入从数据库并查看是否同步成功
docker exec -it mysql_s1 bash
mysql -u root -pqcsjs1
show databases;

elasticsearch:6.2.4

  • 运行如下命令启动lasticsearch
mkdir -p ~/docker/es-6.2.4/build
cd ~/docker/es-6.2.4
cat > docker-compose.yml <<EOF
version: '2.2'
services:
  m1:
    build: build  
    container_name: myelasticsearch
    environment:
      - cluster.name=es-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200
      - 9300:9300
EOF
cd build
cat > Dockerfile <<EOF
FROM docker.elastic.co/elasticsearch/elasticsearch:6.2.4
EXPOSE 9200 9300
ENV ES_VERSION 6.2.4
COPY elasticsearch-analysis-ik-${ES_VERSION}.zip  .
RUN set -ex \
&& bin/elasticsearch-plugin install file:///usr/share/elasticsearch/elasticsearch-analysis-ik-${ES_VERSION}.zip \
&& rm elasticsearch-analysis-ik-${ES_VERSION}.zip
EOF
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.4/elasticsearch-analysis-ik-6.2.4.zip
cd ..
docker-compose up -d

redis:4.0.9

  • 运行如下命令启动redis
mkdir -p ~/docker/redis-4.0.9/build
cd ~/docker/redis-4.0.9
cat > docker-compose.yml <<EOF
m1:
  build: .
  restart: always
  container_name: 'myredis'
  ports:
    - '6379:6379'
  volumes:
    - /data/redis:/data
    - ./redis.conf:/data/redis.conf
EOF
cat > build/Dockerfile<<EOF
FROM redis:4.0.9
CMD [ "redis-server", "/data/redis.conf" ]
EOF
cat > redis.conf<<EOF
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/data/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum no
dbfilename dump.rdb
dir /data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync yes
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
aof-rewrite-incremental-fsync yes
hz 10
EOF
docker-compose up -d

consul:1.1.0

  • 运行如下命令启动consul
docker run  -p 8300-8302:8300-8302 \
            -p 8301-8302:8301-8302/udp \
            -p 8400:8400 -p 8500:8500 \
            -p 8600:53 -p 8600:53/udp \
            -v /var/consul/data:/consul/data \
            -v /var/consul/config:/consul/config \
            -h consul_m1 --name consule-dev -d -e CONSUL_BIND_INTERFACE=eth0 consul:1.1.0

rabbitmq:3.7.5-rc.1-management

  • 运行如下命令启动rabbitmq
docker run -d  -h my-rabbit --name my-rabbit -p 5672:5672 -p 15672:15672 -v /var/rabbitmq/data:/var/lib/rabbitmq rabbitmq:3.7.5-rc.1-management
阅读更多
个人分类: 运维
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

docker安装gitlab,mysql,elasticsearch,redis.consul,rabbitmq

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭