docker第三篇:docker安装常用中间件

1、mysql

docker run --name mysql -h mysql -e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=sBL2y7Uuxqyi -e MYSQL_DATABASE=test -p 3306:3306 --restart=always -d bitnami/mysql:8.4.4-debian-12-r1

MYSQL_DATABASE环境变量用于指定自动创建的数据库,只能指定一个,多个数据库名用逗号分隔识别不出来。见https://hub.docker.com/r/bitnami/mysql

2、postgresql

docker run --name postgresql -h postgresql -e TZ=Asia/Shanghai -e POSTGRES_PASSWORD=sBL2y7Uuxqyi -p 5432:5432 --restart=always -d postgres:17.2-bookworm

3、redis

docker run --name redis -h redis -e TZ=Asia/Shanghai -e REDIS_PASSWORD=sBL2y7Uuxqyi -p 6379:6379 --restart=always -d bitnami/redis:7.4.2-debian-12-r5

可以在run时指定环境变量来修改配置,在/opt/bitnami/redis/etc目录中会生成一份自定义的redis.conf文件。还有很多其他的环境变量可以指定,见https://hub.docker.com/r/bitnami/redis

redis8.0开始原生支持布隆过滤器,不用再额外安装RedisBloom插件了。https://hub.docker.com/_/redis

docker run --name redis -h redis -e TZ=Asia/Shanghai -p 6379:6379 --restart=always -d redis:8.0-M03-bookworm

操作布隆过滤器的命令的关键字是bf,见https://redis.io/docs/latest/commands/?name=bf

如bf.reserve bf 0.0001 100000000,创建一个容量是1亿,错误率是万分之一的布隆过滤器。

4、kafka

docker run --name kafka -h kafka -e TZ=Asia/Shanghai -e KAFKA_CFG_NODE_ID=0 -e KAFKA_CFG_PROCESS_ROLES=controller,broker -e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 -e KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT -e KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093 -e KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER -p 9092:9092 --restart=always -d bitnami/kafka:3.9.0-debian-12-r7

5、pulsar

docker run --name pulsar -h pulsar -p 6650:6650 -p 8081:8080 --restart=always -d apachepulsar/pulsar:4.0.2 bin/pulsar standalone

6、elasticsearch 

docker run --name elasticsearch -h elasticsearch -e TZ=Asia/Shanghai -e ALLOW_EMPTY_PASSWORD=yes -p 9200:9200 --restart=always -d bitnami/elasticsearch:8.17.1-debian-12-r5

7、filebeat

filebeat配置文件:

复制代码
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /path/to/log1/*.log
    - /path/to/log2/*.log
  exclude_lines: ['^$']
  multiline:
    type: pattern
    pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
    negate: true
    match: after
output.elasticsearch:
  enabled: true
  hosts: ["http://host.docker.internal:9200"]
  indices:
    - index: "%{[index]}-%{+yyyy.MM.dd}"
      when.equals:
        level: "info"
    - index: "error-%{[detail.name]}-%{+yyyy.MM.dd}"
      when.contains:
        status: "ERR"
    - index: "default-%{+yyyy.MM.dd}"
复制代码

如上,可以同时多个文件。

docker run -d --name filebeat -h filebeat -u root -v /etc/localtime:/etc/localtime:ro -v /home/koushengrui/blackbox/ELK/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro --add-host=host.docker.internal:host-gateway -d elastic/filebeat:8.16.3 filebeat --strict.perms=false

还有,别忘了把日志文件映射到容器的指定目录。

8、kibana

docker run --name kibana -h kibana -e TZ=Asia/Shanghai -e KIBANA_ELASTICSEARCH_URL=host.docker.internal:9200 --add-host=host.docker.internal:host-gateway -p 5601:5601 -d bitnami/kibana:8.17.1-debian-12-r1

9、mongodb

docker run --name mongodb -h mongodb -e TZ=Asia/Shanghai -p 27017:27017 --restart=always -d bitnami/mongodb:8.0.4-debian-12-r3

10、openresty

利用openresty官方提供的openresty镜像。openresty自带的配置文件nginx.conf在/usr/local/openresty/nginx/conf目录,其include了/etc/nginx/conf.d目录中所有以conf结尾的文件,所以我们只需要把宿主机中的自定义配置文件所在的目录通过-v映射到/etc/nginx/conf.d目录即可。nginx.conf默认开启了access_log,并且把access.log、error.log放在了/usr/local/openresty/nginx/logs目录中,我们可以把日志文件目录映射出来。

windows环境:

docker run --name openresty -h openresty -v D:\\openresty\\conf.d:/etc/nginx/conf.d -v D:\\openresty\\logs:/usr/local/openresty/nginx/logs -p 80:80 --restart=always -d openresty/openresty:1.27.1-1-debian-12-r8

mac/linux环境:

docker run --name openresty -h openresty --add-host=host.docker.internal:host-gateway -e TZ=Asia/Shanghai -v /root/openresty/conf.d:/etc/nginx/conf.d -v /root/openresty/logs:/usr/local/openresty/nginx/logs -p 80:80 --restart=always -d openresty/openresty:1.27.1-1-debian-12-r8

如果要使用https,则要指定TLS证书,如果宿主机的TLS证书的用户是root,则必须要用-u指定用户是root。

-v /etc/letsencrypt:/etc/letsencrypt -u root -p 443:443
如果要启用http/2,则参考https://nginx.org/en/docs/http/ngx_http_v2_module.html配置。
自定义配置文件default.conf内容如下:
复制代码
upstream user_service {
    server host.docker.internal:9000;
}

upstream feed_service {
    server host.docker.internal:9001;
}

server {
    listen 80;
    location / {
       root   /usr/local/openresty/nginx/html;
       index  index.html index.htm;
    }
}

server { 
    listen 443 ssl; 
    http2 on; 

    ssl_certificate     /etc/letsencrypt/live/www.koushr.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.koushr.online/privkey.pem;

    location / {
        root   /usr/local/openresty/nginx/html;
        index  index.html index.htm;
    }

    location /user/ {
        proxy_pass http://user_service;
    }

    location /feed/ {
        proxy_pass_header Server;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_pass http://feed_service;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/openresty/nginx/html;
    }
}
复制代码

11、clickhouse
docker run --name clickhouse -e TZ=Asia/Shanghai -e CLICKHOUSE_ADMIN_PASSWORD=sBL2y7Uuxqyi -p 8123:8123 -p 9004:9004 --restart=always -d bitnami/clickhouse:25-debian-12
12、influxdb
docker run --name influxdb -e TZ=Asia/Shanghai -e INFLUXDB_ADMIN_USER_PASSWORD=sBL2y7Uuxqyi -p 8086:8086 --restart=always -d bitnami/influxdb:2.7.11-debian-12-r5

posted on   koushr  阅读(93)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示