docker安装mysql、mongodb、redis和kafka、kafkamanager等数据库中间件

1、 mysql安装

sudo docker run --name mysql --restart=always -p 3306:3306 -v mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=topcom123 -d mysql:5.7.19 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=1

2、 redis安装

sudo docker run -p 6369:6379 -v redis-data:/data --name redis --restart=always -d redis:4.0.2 --appendonly yes --requirepass yourpassword

3、 mongodb安装

3.1 无密码认证


sudo docker run -p 27007:27017 --name mongo --restart=always -v mongodb-data:/data/db -d mongo:3.4.9

3.2 添加认证

方法一:

可以在上面的容器中增加账号密码,然后克隆上面容器,在命令中加入--auth即可,需要把原来无密码容器删除

方法二(推荐):

在创建容器时直接添加认证

sudo docker run -p 27008:27017 --name mongo-auth --restart=always -v /data/docker/volumes/mongodb-data/_data:/data/db -d mongo:3.4.9 --auth
####注意/data/docker/volumes/mongodb-data/_data 要为空目录

docker exec -it mongo-auth mongo admin

创建mongo账号密码

  • (1)切换到admin
use admin

  • (2)添加管理用户
db.createUser({ user: 'root', pwd: 'root', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })

image
  • (3)授权登陆admin
db.auth("root","root");

  • (4)为制定数据库db创建账号
db.createUser({user:"xxxx",pwd:"xxxx",roles:[{role:"dbOwner",db:"yourdb"}]})

方法三:用docker-compose安装(会缺少docke容器ip地址)

类似下图:

image
  • docker-compose-mongo.yml文件
version: '2'
services:
  mongodb-auth:
    image: mongo:3.4.9
    ports:
        - 27008:27017
    volumes:
        - "./data/configdb:/data/configdb"
        - "./data/db:/data/db"
    command: mongod --auth
    tty: true

执行命令
docker-compose -f docker-compose-mongo.yml up -d
参考文档:https://juejin.im/post/5a560286f265da3e33043ab0

4、docker安装 kafka&&kafkamanager

下载镜像

### zookeeper image
docker pull wurstmeister/zookeeper
### kafka image
docker pull wurstmeister/kafka
### kafka-manager image
docker pull sheepkiller/kafka-manager

方法一:docker-compose方式

docker-compose -f docker-compose-single-broker.yml up -d

  • docker-compose-single-broker.yml
version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2182:2181"
  kafka:
    image: wurstmeister/kafka
    ports:
      - "9072:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.1.108
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  kafka-manager:
    image: sheepkiller/kafka-manager
    links:
      - kafka
      - zookeeper
    environment:
      ZK_HOSTS: zookeeper:2181
      APPLICATION_SECRET: "letmein"
    ports:
      - "9001:9000"
    expose:
      - "9001"

方法二:

2.1启动zookeeper
docker run -d --name zookeeper --publish 2181:2181 \
--volume /etc/localtime:/etc/localtime \
--restart=always \
wurstmeister/zookeeper

2.2启动kafka
docker run -d --name kafka --publish 9082:9092 \
--link zookeeper:zookeeper \
--env KAFKA_BROKER_ID=100 \
--env HOST_IP=192.168.1.108 \
--env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
--env KAFKA_ADVERTISED_HOST_NAME=192.168.1.108 \
--env KAFKA_ADVERTISED_PORT=9082 \
--restart=always \
--volume /etc/localtime:/etc/localtime \
wurstmeister/kafka

2.3启动kafka-manager
docker run -d --name kafka-manager \
--link zookeeper:zookeeper \
--link kafka:kafka -p 9001:9000 \
--restart=always \
--env ZK_HOSTS=zookeeper:2181 \
sheepkiller/kafka-manager

5、 远程phantomjs服务 安装

docker run -d --restart=always --name phantomjs  -p 8910:8910 wernight/phantomjs phantomjs --webdriver=8910

参考:LI木水 https://www.jianshu.com/p/9b7abead49cc

6、 fastdfs安装

参考: LI木水https://www.jianshu.com/p/c66af05c65f3

docker run -itd \
  --name fastdfs-nginx \
  --network=host \
  -v /etc/localtime:/etc/localtime:ro \
  -v /var/log/fdfs/:/data/fdfs/logs/ \
  -v /data/fdfs/data/:/data/fdfs/data/ \
  -v /var/log/nginx/:/var/log/nginx/ \
  fastdfs-nginx \
  sh -c "/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart && /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart && /usr/sbin/nginx -g 'daemon off;'"

常用命令

fdisk -l 
#挂载硬盘
mount /dev/sda1 /home/shaol/test 

##在/var/lib/docker即为/data/docker的软连接,文件夹后面不要加 “/”,
ln -s /data/docker /var/lib/docker# 

ls -la /var/lib/docker  
lrwxrwxrwx 1 root root 12 7月  14 17:20 /var/lib/docker -> /data/docker

你可能感兴趣的:(docker安装mysql、mongodb、redis和kafka、kafkamanager等数据库中间件)