Docker容器安装mysql8并挂载配置和数据
#拉取mysql
docker pull mysql:8.0
# 测试mysql,查看其中的构造
docker run -d -p 3306:3306 --privileged=true -e MYSQL_ROOT_PASSWORD=123456 --name mysql-test mysql:8.0
#将配置文件复制出来
docker cp mysql-test:/etc/mysql/my.cnf /Users/abc/Desktop/docker/mysql/conf/my.cnf
#正式运行mysql并挂载相应的配置和数据
docker run -d -p 3306:3306 --privileged=true -v /Users/abc/Desktop/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /Users/abc/Desktop/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql-admin mysql:8.0
#navicat连通
#完成后在my.cnf添加以下内容(是添加)
[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
\#创建用户
CREATE USER ‘abc@‘localhost' IDENTIFIED BY '9879ca5c5516b2d4';
GRANT ALL PRIVILEGES ON godb.* TO ‘abc’@‘localhost';
RENAME USER ‘abc@‘localhost' TO ‘abc@‘%’;
FLUSH PRIVILEGES;
Docker容器安装redis
拉取redis
docker pull redis
自我配置redis,下载redis.conf文件放到挂载目录
http://download.redis.io/redis-stable/redis.conf
运行redis并挂载配置文件和数据
docker run -p 6379:6379 -v /docker/redis/redis.conf:/etc/redis/redis.conf -v /docker/redis/data:/data --name redis-6379 -d redis:latest redis-server /etc/redis/redis.conf --appendonly yes
进入容器
docker exec -it [id] /bin/bash
修改密码
config set requirepass yourpassword
获取密码
config get requirepass
Docker容器安装mongodb
拉取最新镜像
docker pull mongo
运行mongodb并挂载配置和数据
docker run -d -p 27017:27017 -v /Users/yirenkeji8/Desktop/docker/mongo/configdb:/data/configdb -v /Users/yirenkeji8/Desktop/docker/mongo/db:/data/db --name mongo-27017 docker.io/mongo --auth
进入容器内部mongo命令
docker exec -it mongo-27017 mongo admin
创建管理员账户“imongo”
db.createUser({user:'imongo',pwd:'imongo',roles:[{role:"userAdminAnyDatabase",db:"admin"}]})#navicat测试连接
Docker安装Zookeeper
docker run -d --name zookeeper-2181 -p 2181:2181 --restart=always -v /Users/yirenkeji8/Desktop/docker/zookeeper/data:/data -v /Users/yirenkeji8/Desktop/docker/zookeeper/conf:/conf wurstmeister/zookeeper
检查容器状态
docker exec -it 容器id /bin/bash ./bin/zkServer.sh status
docker安装Kafka
docker run -d --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT={本机或服务器ip地址}:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://{本机或服务器ip地址}:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka
docker安装elasticsearch
docker run --name elasticsearch-9200 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" -v /docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/elasticsearch/data:/usr/share/elasticsearch/data -v /docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:6.4.3
elasticsearch.yml配置
#http.host: 0.0.0.0
cluster.name: a1203
network.bind_host: 0.0.0.0
network.publish_host: {本机或服务器ip地址}
#node.name: es01
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
访问http://localhost:9200出现上图即表示成功
docker安装Kibana
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://{本机或服务器ip地址}:9200 -p 5601:5601 -d kibana:6.4.3
kibana.yml配置(cd config/)
# Default Kibana configuration from kibana-docker.
server.name: kibana
server.host: "0"
elasticsearch.url: http://{本机或服务器ip地址}:9200
xpack.monitoring.ui.container.elasticsearch.enabled: true
访问http://localhost:5601即可对elasticsearch进行可视化操作
选中management 点击Index Patterns
将索引通过项目代码实例化调用后可以创建图案,这个后续更新
(注:es和kibana版本需要对得上,spring项目引用的es依赖也要对得上docker安装elasticsearch的版本)
环境变量(vi ~/.bash_profile source ~/.bash_profile)
###### #set java environment
JAVA_HOME=/usr/local/jdk/jdk1.8.0_311
JRE_HOME=/usr/local/jdk/jdk1.8.0_311/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
export M="/Users/yirenkeji8/Public/ApacheMaven/apache-maven-3.8.3"
export PATH="$M/bin:$PATH"