Install docker and a series of software in Linux environment

One, Linux install docker

Docker installation requires CentOS7 or higher to install

1. Check the CentOS version:

cat /etc/redhat-release

2. Install the required software packages

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

3. Set up stable mirror warehouse:

sudo yum-config-manager \

--add-repo \

https://download.docker.com/linux/centos/docker-ce.repo

 

Carriage return 

 

4. Enable edge and test mirror warehouse:

 sudo yum-config-manager --enable docker-ce-edge

 sudo yum-config-manager --enable docker-ce-testing

5. Update the yum package index:

 sudo yum makecache fast

 

6. Install the latest version of Docker:

sudo yum install docker-ce

- Choose y to continue 

 

--Until the installation is complete 

 

7. Start Docker

sudo systemctl start docker

 

8. Verify whether the startup is successful:

sudo docker run hello-world

 

Docker installation is complete! 

 

 

Two, docker install fastdfs

1. View the image of fastdfs

Docker search fastdfs

2. Pull the fastDFS image containing nginx

 

Here is an example of delron/fastdfs

docker pull delron/fastdfs

 

3. Start the storage service

docker run -d --network=host --name tracker -v /home/xxx/docker/fastdfs/tracker:/var/fdfs delron/fastdfs tracker

 

4. Start the storage service

docker run -d --network=host --name storage -e TRACKER_SERVER=10.0.14.50:22122 -v /home/xxx/docker/fastdfs/storage:/var/fdfs -e GROUP_NAME=group1 delron/fastdfs storage

 

5. View all containers

docker ps -a

 - View the running container

docker ps

 

6. Modify Nginx port

In this image, nginx listens on port 8888 by default, if you don’t need to modify it, you can ignore this step

 --Enter the storage container 7cac30fe4f4f to view the CONTAINER ID of storange in docker ps

docker exec -it 7cac30fe4f4f bash

 

vi /etc/fdfs/storage.conf

Modify the last line to:

# the port of the web server on this storage server

http.server_port=80

--Modify the Nginx port to be consistent with the above

vi /usr/local/nginx/conf/nginx.conf


--Restart the container 7cac30fe4f4f is the CONTAINER ID of storange in the docker ps view

docker restart 7cac30fe4f4f

7. Test whether the configuration is successful


 --Copy a picture (a.png) to the directory /home/xxx/docker/fastdfs/storage

 --Enter the storage container 7cac30fe4f4f to view the CONTAINER ID of storange in docker ps

docker exec -it 7cac30fe4f4f bash

 

--Enter the fdfs directory

cd / var / fdfs

 

--Run the command

/ usr / bin / fdfs_upload_file /etc/fdfs/client.conf a.png

运行成功后会返回地址:

group1/M00/00/00/CgAOMl58eJuAXYfgAALnd0AYnuI035.png

 

  1. 在浏览器中访问

http://10.0.14.50/group1/M00/00/00/CgAOMl58eJuAXYfgAALnd0AYnuI035.png

 

fastDFS和 nginx部署完成!

 

 

三、docker安装redis

  1. 查看redis的镜像

docker search redis

 

2、拉取redis镜像

docker pull redis

 

3、启动

docker run --name redis -p 6379:6379 -d --restart=always redis redis-server --appendonly yes --requirepass "bichart"

参数讲解

 

--name为容器取一个唯一的名字

 

-p端口映射,把宿主机的端口映射到容器内的端口

 

--restar=always随容器启动而启动

 

redis-server --appendonly yes在容器里执行redis-server命令,打开redis持久化

 

--requirepass密码  请自行设置

 

4、查看容器

docker ps

5、连接进入容器

docker exec -it 6e50f2be93f4 redis-cli

 

6、测试

--输入密码

auth admin123

 

--储存数据

set a helloword

 

--获取储存数据

get a

 

 

Redis数据库部署完成!

 

 

 

四、docker安装mysql 5.7

1、查看镜像

docker search mysql

 

2、拉取镜像

sudo docker pull mysql:5.7

 

  1. 查看镜像

sudo docker images

 

4、创建文件夹保存数据

mkdir -p /data/mysql/conf  (保存mysql配置文件)

mkdir -p /data/mysql/data  (保存mysql数据)

mkdir -p /data/mysql/log      (保存mysql日志)

 

  1. 创建容器  密码请自行设置

sudo docker run -p 3306:3306 --name mysql -v /data/mysql/conf:/etc/mysql -v /data/mysql/log:/var/log/mysql -v /data/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root  -d mysql:5.7

参数说明

-p        3306(本机端口):3306(容器端口)     将容器3306的端口映射到本机的3306端口

--name    mysql   为创建的容易命名

-v        /data/mysql/conf:/etc/mysql      将本地文件夹映射到容器的文件夹里

-e        MYSQL_ROOT_PASSWORD=root    设置root的密码

-d        指定创建容器的image

 

 

 不同的镜像,对应容器里面的文件夹路径也不同,如果路径不存在会报错。如果想查看容易内的mysql文件的路径,可参考下面做法:

--创建一个守护态的docker容器

sudo docker run -itd mysql:5.7 /bin/bash

 

--查看容器信息

docker ps -a

 

--使用docker attach进入该容器

sudo docker attach 407717ba3d18(对应容器的ID)

 

 

Mysql数据库部署完成!

Guess you like

Origin blog.csdn.net/weixin_44511845/article/details/108040394