- 首先安装Vagrant,和VirtualBox,
- Vagrant下载地址:https://www.vagrantup.com/VirtualBox下载地址:https://www.virtualbox.org/
- wind+r ---cmd 输入vagrant看有没有装上
- 然后使用vagrant init centos/7下载
- 使用vagrant up 下载镜像
- 下载完镜像之后每天的启动就是vagrant ssh
- 切换root用户:切换root用户:
- 使用密码登录虚拟机: 使用密码登录虚拟机将PasswordAuthentication no改为yes
- service sshd restart 重启客户端
- 卸载已有的docker :其中 \ 是代表换行
1. sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的:
1. sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
- 设置yum源:
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 进行docker的安装 : sudo yum install docker-ce docker-ce-cli containerd.io
- 启动docker : sudo systemctl start docker
- 查看docker版本:docker -v
- 开机自启docker : sudo systemctl enable docker
- 删除所有docker中没有运行的container: docker container prune
- 配置阿里云镜像加速:
1. sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://92m9ar63.mirror.aliyuncs.com"]
}
EOF
- 重启docker后台线程:sudo systemctl daemon-reload
- 重启docker服务:sudo systemctl restart docker
- 使用docker下载mysql 5.7: sudo docker pull mysql:5.7
- 查看docker正在运行中的容器:docker ps
- 创建实例并且启动mysql:其中-v是将容器内的文件和宿主机文件进行挂载,这样修改i配置的时候就不需要再进入到重启中修改配置
1. docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
- docker进入msql内部容器:docker exec -it mysql /bin/bash
- MySQL配置:
1. [client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
- docker重启mysql : docker重启mysql
- docker下载redis(下载最新) : docker pull redis
- Docker安装redis:
- 创建配置文件夹 : mkdir -p /mydata/redis/conf
- 创建配置文件 : touch /mydata/redis/conf/redis.conf
- 使用docker命令安装并且挂在到宿主机上面 : docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf - 进入到docker的redis : docker exec -it redis redis-cli
27. yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
- docker pull elasticsearch:7.4.2
- docker pull kibana:7.4.2
- free -m
- mkdir -p /mydata/elasticsearch/config
- mkdir -p /mydata/elasticsearch/data
- echo "http.host:0.0.0.0">>/mydata/elasticsearch/config/elasticsearch.yml
- 运行docker中的elasticSearch并且挂载到宿主机 :
1. docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/conf/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2
- chmod -R 777 /mydata/elasticsearch/
- docker ps -a
- docker start "CONTAINER ID"数量进行容器的启动
- --------------------------------docker安装Kibana---------------------------------------------
- 第30步已经拉取了Kibana镜像z这里只需要运行挂载就可以:docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.56.10:9200 -p 5601:5601 \
-d kibana:7.4.2 - ------------------------------Docker安装nginx-------------------------------------------------
- 拉取nginx镜像:docker pull nginx:latest
- 查看镜像:docker images
- 运行nginx镜像:docker run --name nginxtest -p 9091:80 -d 8c
- 创建需要挂载的文件:
1. mkdir -p /server/nginx/html
mkdir -p /server/nginx/logs
mkdir -p /server/nginx/conf
- 将容器里面的配置复制到宿主机文件进行挂载:
docker cp d61e3f6b74b3:/etc/nginx/nginx.conf /server/nginx/conf
- (其中 d61e3f6b74b3是容器的id,后面的容器内的文件路径以及要复制到宿主机的文件路径)
- 进行容器挂载 :
46. docker run -d -p 80:80 --name nginx -v /server/nginx/html:/usr/share/nginx/html -v /server/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /server/nginx/conf.d:/etc/nginx/conf.d -v /server/nginx/logs:/var/log/nginx nginx