This article is the first in a series of big data clustering based on Docker
The main content
- Docker structures,
- Docker deployment CentOS
- Container-free key communication
- The container is saved as an image
- Docker image released
The environment
- Linux 7.6
Docker installation
Installing the Tool Package
# yum install -y yum-utils # yum install package will not complete without these dependencies
Setting up the remote Repository
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
The installation
yum install docker-ce
Start the
systemctl start docker
Check the version
docker version
check
docker run hello-world
Docker deploy CentOS
Pull the mirror
docker pull centos
Check whether the pull is successful
docker imsages
Set up a Docker bridge for assigning fixed IP addresses
Docker network create --subnet=172.15.0.0/16 netgroup
Create a container
–name Container name
-h Specifies the host name of a container
Net Sets the bridge
— IP Specifies the container IP address
master
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-master -h cluster-master --net netgroup - IP 172.15.0.2 centos/usr/sbin/initCopy the code
slave1
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-slave1-h cluster-slave1--net netgroup - IP 172.15.0.3 centos/usr/sbin/initCopy the code
slave2
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-slave2-h cluster-slave2--net netgroup - IP 172.15.0.4 centos/usr/sbin/initCopy the code
slave3
docker run -d --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup --name cluster-slave3-h cluster-slave3--net netgroup - IP 172.15.0.5 centos/usr/sbin/initCopy the code
View the running container
docker ps
View all containers, including those that are not running
docker pa -a
Run the container
Docker run Specifies the container name or container ID
Into the container
Docker run exec-ti container name or container ID bash
Configuring the hosts file
# yum install VIM /etc/hosts # 172.15.0.2 cluster-master 172.15.0.3 cluster-slave1 172.15.0.4 Cluster-slave2 172.15.0.5 cluster-slave3 # Send the configuration file to other nodes SCP /etc/hosts cluster-slave1: /etc/scp /etc/hosts cluster-slave2:/etc/ scp /etc/hosts cluster-slave3:/etc/Copy the code
Container key free communication
Change ali YUM source
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repoCopy the code
Deploy the OpenSSH
yum -y install openssh openssh-server openssh-clients
systemctl start sshdCopy the code
Generate the key
Type the following command and press Enter three times
ssh-keygen -t rsa
Setting a User Password
passwd root
Public key distribution
Do this after all nodes have generated keys
master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3Copy the code
slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3Copy the code
slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3Copy the code
slave3
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-master
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave1
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave2
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cluster-slave3Copy the code
Test free key
The first time you type the following command, you will be asked. Type yes and then enter the password of the corresponding host
When you run the SSH command for the second time, you can access it directly without entering a password
Run the exit command to exit the current user
master
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1Copy the code
slave1
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1Copy the code
slave2
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1Copy the code
slave3
ssh cluster-master
ssh cluster-slave1
ssh cluster-slave1
ssh cluster-slave1Copy the code
Four, the container is saved as a mirror image
Docker commit -m 'Commit text Description' -a 'author' Container name Commit image name: commit image tag nameCopy the code
5. Push the image to the remote repository
The new account
hub.docker.com/
Create a mirror repository
Label the image to be pushed
Docker tag Image ID User name of the repository to be pushed/repository name to be pushed: newly defined tagCopy the code
Push an image to the repository
Docker push username/username of the repository to be pushed: image tagCopy the code