공부하기 위해서 설치해봅니다.
ansible 설치하기
apt install -y ansible
관리할 서버 접속 설정하기 (사전에 ssh-keygen 설정 필요)
# pub 파일이 id_rsa.pub 인지 다른 이름인지 반드시 확인 필요
# 저는 다른 vm이 있어서 접속 테스트 했습니다.
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.0.205
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.0.206
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.0.207
ansible 테스트
root@13500T-ubuntu:~# mkdir /etc/ansible
root@13500T-ubuntu:~# touch /etc/ansible/hosts
root@13500T-ubuntu:~# cat /etc/ansible/hosts
#192.168.0.205 k8s-master
192.168.0.205
#192.168.0.206 k8s-node1
192.168.0.206
#192.168.0.207 k8s-node2
192.168.0.207
root@13500T-ubuntu:~# ansible all -m ping
192.168.0.207 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
192.168.0.206 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
192.168.0.205 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
root@13500T-ubuntu:~#
일반 유저로 설정을 하니 아래와 같이 권한 문제가 발생하여 ssh로 root 접속할 수 있도록 설정하여 수행하였습니다.
root@13500T-ubuntu:~# ansible all -m ping
192.168.0.205 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.0.205: Permission denied (publickey,password).",
"unreachable": true
}
192.168.0.206 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.0.206: Permission denied (publickey,password).",
"unreachable": true
}
192.168.0.207 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.0.207: Permission denied (publickey,password).",
"unreachable": true
}
root@13500T-ubuntu:~#
/usr/bin/ssh-copy-id: ERROR: No identities found 발생 시
root@13500T-ubuntu:~# ssh-copy-id master@192.168.0.205
/usr/bin/ssh-copy-id: ERROR: No identities found
1단계: 사이사이 물어보면 "엔터"만 치시면 됩니다.
root@13500T-ubuntu:~# ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/root/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_ed25519
Your public key has been saved in /root/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:tXRz---------------------------- root@13500T-ubuntu
The key's randomart image is:
+--[ED25519 256]--+
| *EBX|
| o*B^*|
| o Bo/*B|
| o = X =*|
| S . ..o|
| . |
| |
| |
| |
+----[SHA256]-----+
root@13500T-ubuntu:~#
2단계: pub 파일이 어떤 이름인지 꼭 확인해보세요. 저는 " id_rsa.pub"가 아닌 " id_ed25519.pub" 였습니다.
root@13500T-ubuntu:~# ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.0.205
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ed25519.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
root@192.168.0.205's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.0.205'"
and check to make sure that only the key(s) you wanted were added.
root@13500T-ubuntu:~# ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.0.206
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ed25519.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
root@192.168.0.206's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.0.206'"
and check to make sure that only the key(s) you wanted were added.
root@13500T-ubuntu:~# ssh-copy-id -i ~/.ssh/id_ed25519.pub root@192.168.0.207
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ed25519.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
root@192.168.0.207's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.0.207'"
and check to make sure that only the key(s) you wanted were added.
root@13500T-ubuntu:~#
일반사용자로 등록하는 방법입니다.
root가 아닌 일반사용자로도 ansible 사용방법이 있는 것 같은데, 추후 확인 후 업그레이드 하겠습니다.
root@13500T-ubuntu:~# ssh-copy-id -i ~/.ssh/id_ed25519.pub master@192.168.0.205
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ed25519.pub"
The authenticity of host '192.168.0.205 (192.168.0.205)' can't be established.
ED25519 key fingerprint is SHA256:Rg4V0-------------------------OmwKSq8s.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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
master@192.168.0.205's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'master@192.168.0.205'"
and check to make sure that only the key(s) you wanted were added.
root@13500T-ubuntu:~# ssh-copy-id -i ~/.ssh/id_ed25519.pub node1@192.168.0.206
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ed25519.pub"
The authenticity of host '192.168.0.206 (192.168.0.206)' can't be established.
ED25519 key fingerprint is SHA256:Rg4V0-------------------------OmwKSq8s.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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
node1@192.168.0.206's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'node1@192.168.0.206'"
and check to make sure that only the key(s) you wanted were added.
root@13500T-ubuntu:~# ssh-copy-id -i ~/.ssh/id_ed25519.pub node2@192.168.0.207
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ed25519.pub"
The authenticity of host '192.168.0.207 (192.168.0.207)' can't be established.
ED25519 key fingerprint is SHA256:Rg4V0-------------------------OmwKSq8s.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: [hashed name]
~/.ssh/known_hosts:4: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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
node2@192.168.0.207's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'node2@192.168.0.207'"
and check to make sure that only the key(s) you wanted were added.
root@13500T-ubuntu:~#
3단계: 패스워드 없이 계정 접속하기
root@13500T-ubuntu:~# ssh master@192.168.0.205
Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 6.8.0-48-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
Expanded Security Maintenance for Applications is not enabled.
139 updates can be applied immediately.
24 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
Last login: Mon Nov 18 14:55:57 2024 from 192.168.0.201
master@k8s-master:~$
'기술 노트 > ubuntu' 카테고리의 다른 글
ufw 사용 방법 (0) | 2024.05.13 |
---|---|
influxdb.conf 설정 파일 (0) | 2024.03.18 |
influxdb v1으로 설치하기 (0) | 2024.03.18 |
influxdb v1 설치 후 telegraf 연동하기 (0) | 2024.03.18 |
MIB search path: mibs (0) | 2024.03.15 |