Published 6月 09, 2019 by with 0 comment

6 - 02 - Create a Machine




In my lab, there are three KVMs (KVM1 KVM2 and KVM3), and running the ubuntu-16.04.6-desktop-amd64.iso.
KVM1 install Docker Machine first. I will create Docker Machine in KVM2 and KVM3


1. KVM1 ping KVM2(192.168.122.251) and KVM3(192.168.122.64)
peter@peter-KVM:~$ docker version 
Client:
 Version:           18.09.6
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        481bc77
 Built:             Sat May  4 02:35:27 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       481bc77
  Built:            Sat May  4 01:59:36 2019
  OS/Arch:          linux/amd64
  Experimental:     false
peter@peter-KVM:~$ 
peter@peter-KVM:~$ ping -c 3 192.168.122.251
PING 192.168.122.251 (192.168.122.251) 56(84) bytes of data.
64 bytes from 192.168.122.251: icmp_seq=1 ttl=64 time=0.660 ms
64 bytes from 192.168.122.251: icmp_seq=2 ttl=64 time=0.501 ms
64 bytes from 192.168.122.251: icmp_seq=3 ttl=64 time=0.513 ms

--- 192.168.122.251 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2052ms
rtt min/avg/max/mdev = 0.501/0.558/0.660/0.072 ms
peter@peter-KVM:~$ 
peter@peter-KVM:~$ ping -c 3 192.168.122.64
PING 192.168.122.64 (192.168.122.64) 56(84) bytes of data.
64 bytes from 192.168.122.64: icmp_seq=1 ttl=64 time=0.971 ms
64 bytes from 192.168.122.64: icmp_seq=2 ttl=64 time=0.382 ms
64 bytes from 192.168.122.64: icmp_seq=3 ttl=64 time=0.489 ms

--- 192.168.122.64 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2011ms
rtt min/avg/max/mdev = 0.382/0.614/0.971/0.256 ms
peter@peter-KVM:~$ 


2. Go to KVM2, Add user (peter) in to sudo group
peter@peter-KVM2:~$ sudo usermod -a -G sudo peter

2a. Setup sudo which do not need typing password.
peter@peter-KVM2:~$ sudo visudo

2b. Add this in the end of file
peter   ALL=(ALL:ALL) NOPASSWD: ALL


3. Go to KVM3, Add user (peter) in to sudo group
peter@peter-KVM3:~$ sudo usermod -a -G sudo peter

3a. Setup sudo which do not need typing password.
peter@peter-KVM3:~$ sudo visudo

3b. Add this in the end of file
peter   ALL=(ALL:ALL) NOPASSWD: ALL


4. Go back KVM1, generating a new SSH key
peter@peter-KVM:~$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/peter/.ssh/id_rsa): 
Created directory '/home/peter/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/peter/.ssh/id_rsa.
Your public key has been saved in /home/peter/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:JJu+9GhsbrdriN+lzW+u6iNUt69tI+gkZvFUzObG/kQ peter@peter-KVM
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|         o       |
|      . . =      |
|       =.=.      |
|      +.S.+.E    |
|     ..+ o..     |
|     +*.o.o..    |
|    .+BB==.+=    |
|     *=*X==O=.   |
+----[SHA256]-----+
peter@peter-KVM:~$ 

5. Copy KVM1 local user peter SSH public key to KVM2 and KVM3
peter@peter-KVM:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub peter@192.168.122.251
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/peter/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
peter@192.168.122.251's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'peter@192.168.122.251'"
and check to make sure that only the key(s) you wanted were added.

peter@peter-KVM:~$
peter@peter-KVM:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub peter@192.168.122.64
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/peter/.ssh/id_rsa.pub"
The authenticity of host '192.168.122.64 (192.168.122.64)' can't be established.
ECDSA key fingerprint is SHA256:7Xzpx4rSknq2+pk3DDu7VfEndQSVeweKmx1IiRZpGcQ.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
peter@192.168.122.64's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'peter@192.168.122.64'"
and check to make sure that only the key(s) you wanted were added.

peter@peter-KVM:~$


6. Before let's check the docker machine.
peter@peter-KVM:~$ docker-machine ls
NAME   ACTIVE   DRIVER   STATE   URL   SWARM   DOCKER   ERRORS
peter@peter-KVM:~$ 


7. Creating docker machine in KVM2
peter@peter-KVM:~$ docker-machine create --driver generic \
> --generic-ip-address=192.168.122.251 \
> --generic-ssh-user=peter \
> host1
Running pre-create checks...
Creating machine...
(host1) No SSH key specified. Assuming an existing key at the default location.
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env host1
peter@peter-KVM:~$ 
peter@peter-KVM:~$ docker-machine ls
NAME    ACTIVE   DRIVER    STATE     URL                          SWARM   DOCKER     ERRORS
host1   -        generic   Running   tcp://192.168.122.251:2376           v18.09.6   
peter@peter-KVM:~$


8. Creating docker machine in KVM3
peter@peter-KVM:~$ docker-machine create --driver generic \
> --generic-ip-address=192.168.122.64 \
> --generic-ssh-user=peter \
> host2
Running pre-create checks...
Creating machine...
(host2) No SSH key specified. Assuming an existing key at the default location.
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env host2
peter@peter-KVM:~$


9. Verify.
peter@peter-KVM:~$ docker-machine ls
NAME    ACTIVE   DRIVER    STATE     URL                          SWARM   DOCKER     ERRORS
host1   -        generic   Running   tcp://192.168.122.251:2376           v18.09.6   
host2   -        generic   Running   tcp://192.168.122.64:2376            v18.09.6   
peter@peter-KVM:~$ 
peter@peter-KVM:~$ docker-machine env host1
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.122.251:2376"
export DOCKER_CERT_PATH="/home/peter/.docker/machine/machines/host1"
export DOCKER_MACHINE_NAME="host1"
# Run this command to configure your shell: 
# eval $(docker-machine env host1)
peter@peter-KVM:~$ 
peter@peter-KVM:~$ docker-machine env host2
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.122.64:2376"
export DOCKER_CERT_PATH="/home/peter/.docker/machine/machines/host2"
export DOCKER_MACHINE_NAME="host2"
# Run this command to configure your shell: 
# eval $(docker-machine env host2)
peter@peter-KVM:~$ 


最初發表 / 最後更新: 2019.06.09 / 2019.06.09

0 comments:

張貼留言