Docker 部署中间件
来源:SegmentFault
时间:2023-01-22 12:27:12 357浏览 收藏
本篇文章给大家分享《Docker 部署中间件》,覆盖了数据库的常见基础知识,其实一个语言的全部知识点一篇文章是不可能说完的,但希望通过这些问题,让读者对自己的掌握程度有一定的认识(B 数),从而弥补自己的不足,更好的掌握它。
Docker 安装
1. 卸载旧版本
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
2. 安装基础依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
3. 配置 docker yum 源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4. 安装并启动 docker
yum install -y docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.io
systemctl enable docker systemctl start docker
5. 查看 docker 版本
docker --version
6. 配置 docker 加速
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json
7. 设置开机自启动
sudo systemctl daemon-reload sudo systemctl restart docker
Docker-Compose 安装
1. 安装
sudo curl -L https://github.com/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
2. 查看版本
docker-compose --version
Docker 部署 Nginx
1. 拉取镜像
docker pull nginx:1.20
2. 运行容器
docker run --name nginx -d -p 80:80 nginx:1.20
3. 进入容器内部
docker exec -it nginx bash
4. 拷贝配置文件
docker cp nginx:/etc/nginx /data/software/docker/nginx/
5. 配置文件
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
6. 数据卷挂载
docker run --name nginx -v /data/software/docker/nginx/conf:/etc/nginx -v /data/software/docker/nginx/data:/usr/share/nginx -v /data/software/docker/nginx/log:/var/log/nginx -p 80:80 -d nginx:1.20
命令说明:
挂载配置文件
-v /data/software/docker/nginx/conf:/etc/nginx
挂载数据
-v /data/software/docker/nginx/data:/usr/share/nginx
挂载日志文件
-v /data/software/docker/nginx/log:/var/log/nginx
Docker 部署 MySQL
1. 拉取镜像
docker pull mysql:5.7
2. 运行容器
docker run --name mysql -d -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
3. 进入容器内部
docker exec -it mysql bash
4. 拷贝配置文件
docker cp mysql:/etc/mysql/mysql.conf.d /data/software/docker/mysql/conf/
5. 配置文件
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/log/mysql/error.log # By default we only accept connections from localhost bind-address = 0.0.0.0 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
6. 数据卷挂载
docker run --name mysql -d -v /data/software/docker/mysql/conf:/etc/mysql/conf.d -v /data/software/docker/mysql/data:/var/lib/mysql -v /data/software/docker/mysql/log:/var/log/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
命令说明:
挂载配置文件
-v /data/software/docker/mysql/conf:/etc/mysql/conf.d
挂载数据
-v /data/software/docker/mysql/data:/var/lib/mysql
挂载日志文件
-v /data/software/docker/mysql/log:/var/log/mysql
注意:
chmod 777 /data/software/docker/mysql/log/
指定root用户命令
-e MYSQL_ROOT_PASSWORD=123456
Docker 部署 Redis
1. 拉取镜像
docker pull redis:6.2.6
2. 运行容器
docker run --name redis -d -p 6379:6379 redis:6.2.6
3. 进入容器内部
docker exec -it redis bash
4. 配置文件
port 6379 bind 0.0.0.0 requirepass 123456 daemonize no pidfile /var/run/redis_6379.pid logfile "/var/log/redis.log" dbfilename dump.rdb dir /data/ databases 16 appendonly yes appendfilename "appendonly.aof" # appendfsync always appendfsync everysec # appendfsync no
5. 数据卷挂载
docker run --name redis -d -p 6379:6379 -v /data/software/docker/redis/conf:/usr/local/etc/redis -v /data/software/docker/redis/data:/data -v /data/software/docker/redis/log:/var/log redis:6.2.6 redis-server /usr/local/etc/redis/redis.conf
命令说明:
挂载配置文件
-v /data/software/docker/redis/conf:/usr/local/etc/redis
挂载数据
-v /data/software/docker/redis/data:/data
挂载日志文件
-v /data/software/docker/redis/log:/var/log/redis.log
注意:
chmod 777 /data/software/docker/redis/log/
指定配置文件
redis-server /usr/local/etc/redis/redis.conf
6. Redis 客户端
进入客户端
docker exec -it redis redis-cli
登录
auth 123456
Docker 部署 MongoDB
1. 拉取镜像
docker pull mongo:5.0.8
2. 运行容器
docker run --name mongo -d -p 27017:27017 mongo:5.0.8
3. 进入容器内部
docker exec -it mongo bash
4. 拷贝配置文件
docker cp mongo:/etc/mongod.conf.orig /data/software/docker/mongo/conf/
5. 配置文件
# mongod.conf # for documentation of all options, see: # https://www.mongodb.com/docs/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: /data/db journal: enabled: true # engine: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: 0.0.0.0 # how the process runs processManagement: timeZoneInfo: /usr/share/zoneinfo #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
6. 数据卷挂载
docker run --name mongo -d -v /data/software/docker/mongo/conf:/data/configdb -v /data/software/docker/mongo/data:/data/db -v /data/software/docker/mongo/log:/var/log/mongodb -p 27017:27017 mongo:5.0.8 --config /data/configdb/mongod.conf --auth
命令说明:
挂载配置文件
-v /data/software/docker/mongo/conf:/data/configdb
挂载数据
-v /data/software/docker/mongo/data:/data/db
挂载日志文件
-v /data/software/docker/mongo/log:/var/log/mongodb
注意:
chmod 777 /data/software/docker/mongo/log/
指定配置文件
--config /data/configdb/mongod.conf
Mongo带验证
--auth
7. MongoDB 操作
进入mongo客户端
docker exec -it mongo mongo
进入
use admin
创建系统用户
db.createUser({ user:'root',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
用户登录命令
db.auth('root','123456');
创建指定数据库用户命令
db.createUser({user:"test",pwd:"123456",roles:[{role:'dbOwner',db:'test'}]})
Docker 部署 Zookeeper
1. 拉取镜像
docker pull zookeeper:3.6.3
2. 运行容器
docker run --name zookeeper -d -p 2181:2181 -p 2888:2888 -p 3888:3888 zookeeper:3.6.3
3. 进入容器内部
docker exec -it zookeeper bash
4. 拷贝配置文件
docker cp zookeeper:/conf/zoo.cfg /data/software/docker/zookeeper/conf/
5. 配置文件
dataDir=/data dataLogDir=/datalog tickTime=2000 initLimit=5 syncLimit=2 autopurge.snapRetainCount=3 autopurge.purgeInterval=0 maxClientCnxns=60 standaloneEnabled=false admin.enableServer=false server.1=localhost:2888:3888;2181
6. 数据卷挂载
docker run --name zookeeper -d -v /data/software/docker/zookeeper/conf:/conf -v /data/software/docker/zookeeper/data:/data -v /data/software/docker/zookeeper/log:/datalog -p 2181:2181 -p 2888:2888 -p 3888:3888 zookeeper:3.6.3
命令说明:
挂载配置文件
-v /data/software/docker/zookeeper/conf:/conf
挂载数据
-v /data/software/docker/zookeeper/data:/data
挂载日志文件
-v /data/software/docker/zookeeper/log:/datalog
7. 客户端操作
进入Zookeeper客户端
docker exec -it zookeeper ./bin/zkCli.sh
Docker 部署 Kafka
1. 拉取镜像
docker pull bitnami/kafka:2.8.1
2. 运行容器
docker run --name kafka -d -e ALLOW_PLAINTEXT_LISTENER=yes bitnami/kafka:2.8.1
3. 进入容器内部
docker exec -it kafka bash
4. 拷贝配置文件
docker cp kafka:/opt/bitnami/kafka/config /data/software/docker/kafka/conf/
5. 配置文件
############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker. broker.id=0 ############################# Socket Server Settings ############################# listeners=PLAINTEXT://0.0.0.0:9092 # Hostname and port the broker will advertise to producers and consumers. If not set, # it uses the value for "listeners" if configured. Otherwise, it will use the value # returned from java.net.InetAddress.getCanonicalHostName(). advertised.listeners=PLAINTEXT://ip:9092 # Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details #listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL # The number of threads that the server uses for receiving requests from the network and sending responses to the network num.network.threads=3 # The number of threads that the server uses for processing requests, which may include disk I/O num.io.threads=8 # The send buffer (SO_SNDBUF) used by the socket server socket.send.buffer.bytes=102400 # The receive buffer (SO_RCVBUF) used by the socket server socket.receive.buffer.bytes=102400 # The maximum size of a request that the socket server will accept (protection against OOM) socket.request.max.bytes=104857600 ############################# Log Basics ############################# # A comma separated list of directories under which to store log files log.dirs=/bitnami/kafka/data # The default number of log partitions per topic. More partitions allow greater # parallelism for consumption, but this will also result in more files across # the brokers. num.partitions=1 # The number of threads per data directory to be used for log recovery at startup and flushing at shutdown. # This value is recommended to be increased for installations with data dirs located in RAID array. num.recovery.threads.per.data.dir=1 ############################# Internal Topic Settings ############################# # The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state" # For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3. offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 ############################# Log Retention Policy ############################# # The minimum age of a log file to be eligible for deletion due to age log.retention.hours=168 # A size-based retention policy for logs. Segments are pruned from the log unless the remaining # segments drop below log.retention.bytes. Functions independently of log.retention.hours. #log.retention.bytes=1073741824 # The maximum size of a log segment file. When this size is reached a new log segment will be created. log.segment.bytes=1073741824 # The interval at which log segments are checked to see if they can be deleted according # to the retention policies log.retention.check.interval.ms=300000 ############################# Zookeeper ############################# zookeeper.connect=ip:2181/kafka # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=18000 group.initial.rebalance.delay.ms=0 auto.create.topics.enable=true max.partition.fetch.bytes=1048576 max.request.size=1048576 sasl.enabled.mechanisms=PLAIN,SCRAM-SHA-256,SCRAM-SHA-512 sasl.mechanism.inter.broker.protocol=
6. 数据卷挂载
docker run --name kafka -d -v /data/software/docker/kafka/conf:/bitnami/kafka/config -v /data/software/docker/kafka/data:/bitnami/kafka/data -p 9092:9092 -e ALLOW_PLAINTEXT_LISTENER=yes bitnami/kafka:2.8.1
命令说明:
挂载配置文件
-v /data/software/docker/kafka/conf:/bitnami/kafka/config
挂载数据
-v /data/software/docker/kafka/data:/bitnami/kafka/data -p 9092:9092
注意:
chmod 777 /data/software/docker/kafka/data/
Docker 部署 RabbitMQ
1. 拉取镜像
docker pull rabbitmq:3.8-management
说明:镜像带management表示已经安装RabbitMQ后台管理插件。
2. 运行容器
docker run --name rabbitmq -d -p 5672:5672 -p 15672:15672 rabbitmq:3.8-management
3. 进入容器内部
docker exec -it rabbitmq bash
4. 拷贝配置文件
docker cp rabbitmq:/etc/rabbitmq /data/software/docker/rabbitmq/conf/
5. 配置文件
loopback_users.guest = false listeners.tcp.default = 5672 management.tcp.port = 15672
6. 数据卷挂载
docker run --name rabbitmq -p 5672:5672 -p 15672:15672 -v /data/software/docker/rabbitmq/conf:/etc/rabbitmq -v /data/software/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia -v /data/software/docker/rabbitmq/log:/var/log/rabbitmq/log -e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=123456 -d rabbitmq:3.8-management
命令说明:
挂载配置文件
-v /data/software/docker/rabbitmq/conf:/etc/rabbitmq
挂载数据
-v /data/software/docker/rabbitmq/data:/var/lib/rabbitmq/mnesia
挂载日志文件
-v /data/software/docker/rabbitmq/log:/var/log/rabbitmq/log
指定后台管理界面的登录用户名、密码
-e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=123456
Docker 部署 Elastic Search
安装Elastic Search
1. 拉取镜像
docker pull elasticsearch:6.8.22
2. 运行容器
docker run --name elasticsearch -d elasticsearch:6.8.22
启动报错:
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:
在centos虚拟机中,修改配置sysctl.conf
vim /etc/sysctl.conf
加入如下配置
vm.max_map_count=262144
启用配置
sysctl -p
3. 进入容器内部
docker exec -it elasticsearch bash
4. 拷贝配置文件
docker cp elasticsearch:/usr/share/elasticsearch/config/ /data/software/docker/elasticsearch/conf/
5. 配置文件
cluster.name: "docker-cluster" network.host: 0.0.0.0
说明:
注意指定
docker run --name elasticsearch -d -p 9200:9200 -p 9300:9300 -v /data/software/docker/elasticsearch/conf:/usr/share/elasticsearch/config -v /data/software/docker/elasticsearch/data:/usr/share/elasticsearch/data -v /data/software/docker/elasticsearch/log:/usr/share/elasticsearch/logs elasticsearch:6.8.22
命令说明:
挂载配置文件
-v /data/software/docker/elasticsearch/conf:/usr/share/elasticsearch/config
挂载数据
-v /data/software/docker/elasticsearch/data:/usr/share/elasticsearch/data
挂载日志文件
-v /data/software/docker/elasticsearch/log:/usr/share/elasticsearch/logs
注意:
chmod 777 /data/software/docker/elasticsearch/data/
chmod 777 /data/software/docker/elasticsearch/log/
安装 Kibana
1. 拉取镜像
docker pull kibana:6.8.22
2. 运行容器
docker run -d --name kibana -e ELASTICSEARCH_URL=http://ip:9200 -p 5601:5601 kibana:6.8.22
3. 进入容器内部
docker exec -it kibana bash
4. 拷贝配置文件
docker cp kibana:/usr/share/kibana/config/ /data/software/docker/kibana/conf/
5. 配置文件
server.name: kibana server.host: "0" elasticsearch.hosts: [ "http://ip:9200" ] xpack.monitoring.ui.container.elasticsearch.enabled: true
6. 数据卷挂载
docker run -d --name kibana -v /data/software/docker/kibana/conf:/usr/share/kibana/config -v /data/software/docker/kibana/data:/usr/share/kibana/data -p 5601:5601 kibana:6.8.22
命令说明:
挂载配置文件
-v /data/software/docker/kibana/conf:/usr/share/kibana/config
挂载数据
/data/software/docker/kibana/data:/usr/share/kibana/data
注意:
chmod 777 /data/software/docker/kibana/data/
文中关于mysql的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《Docker 部署中间件》文章吧,也可关注golang学习网公众号了解相关技术文章。
声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
499 收藏
-
160 收藏
-
105 收藏
-
286 收藏
-
244 收藏
最新阅读
更多>
-
209 收藏
-
497 收藏
-
335 收藏
-
467 收藏
-
303 收藏
-
176 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 507次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习