# 유틸리티를 제공하는 패키지 설치: yum-utils
sudo yum install -y yum-utils
# 리포지토리 설정
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
도커 엔진 설치
최신 버전의 Docker Engine, containerd 및 Docker Compose 설치
# 최신 버전 설치 시
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 또는 특정 버전 설치 시
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin
- 에러 발생 3: Vagrantfile에 네트워크 설정을 했음에도 불구하고 static 설정이 되지 않음
- 해결
# 플러그인 버전 확인
# 낮은 버전이라면 업데이트 필요
PS C:\HashiCorp\ansible> vagrant plugin update
Updating installed plugins...
Fetching vagrant-vbguest-0.30.0.gem
Successfully uninstalled vagrant-vbguest-0.21.0
Updated 'vagrant-vbguest' to version '0.30.0'!
PS C:\HashiCorp\ansible> vagrant plugin list
vagrant-hostmanager (1.8.9, global)
- Version Constraint: > 0
vagrant-vbguest (0.30.0, global)
- Version Constraint: > 0
# 모든 가상 머신에서 사용자 생성
# 사용자 생성
[vagrant@control ~]$ sudo useradd ansible
# 패스워드 설정
[vagrant@control ~]$ sudo passwd ansible
# 패스워드 입력 없이 원격 접속하도록 설정
# 1. 컨트롤 노드에서 ssh 생성
# 2. 호스트로 복사 (host1, host2, host3, host4)
[vagrant@control-node ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/vagrant/.ssh/id_rsa.
Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:3lhOyiezamELTdrmy5HRbx7pw02DesuW6EcwACqeJhY vagrant@control-node
The key's randomart image is:
+---[RSA 2048]----+
| .. |
| . . |
|.E. . |
|..o ..o |
|.= =. Soo. |
|+ o *= Oo.o |
| =ooB=O+ . |
| .+.oXB.. |
| .++o+=o |
+----[SHA256]-----+
# host[1..4] 설정
[vagrant@control-node ~]$ ssh-copy-id ansible@host1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/vagrant/.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
ansible@host1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'ansible@host1'"
and check to make sure that only the key(s) you wanted were added.
[vagrant@control-node ~]$ ssh ansible@host1
Last failed login: Tue Jun 7 09:33:07 UTC 2022 from 192.168.56.100 on ssh:notty
There were 25 failed login attempts since the last successful login.
[ansible@host1 ~]$
host4에서 에러 발생: ansible 사용자 생성 시 디렉토리가 자동으로 생성되지 않음
[vagrant@control-node ~]$ ssh-copy-id ansible@host4
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/vagrant/.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
ansible@host4's password:
Could not chdir to home directory /home/ansible: No such file or directory
sh: 1: cd: can't cd to /home/ansible
mkdir: cannot create directory ‘.ssh’: Permission denied
vagrant@host4:~$ ls -l /home
total 8
drwxr-xr-x 3 ubuntu ubuntu 4096 Jun 7 07:36 ubuntu
drwxr-xr-x 4 vagrant vagrant 4096 Jun 7 07:51 vagrant
해결: 디렉토리 수동 생성
vagrant@host4:~$ sudo mkdir /home/ansible
vagrant@host4:~$ sudo chown ansible:ansible /home/ansible
vagrant@host4:~$ sudo chmod 755 /home/ansible
vagrant@host4:~$ sudo ls -l /home
total 12
drwxr-xr-x 2 ansible ansible 4096 Jun 7 09:44 ansible
drwxr-xr-x 3 ubuntu ubuntu 4096 Jun 7 07:36 ubuntu
drwxr-xr-x 4 vagrant vagrant 4096 Jun 7 07:51 vagrant
8. sudo 설정
패스워드 없이 sudo 명령어 사용 설정
[vagrant@control-node ~]$ sudo ls /etc/sudoers.d
vagrant
[vagrant@control-node ~]$ sudo cat /etc/sudoers.d/vagrant
%vagrant ALL=(ALL) NOPASSWD: ALL
[vagrant@control-node ~]$
[vagrant@control-node ~]$ sudo grep wheel /etc/sudoers
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
# %wheel ALL=(ALL) NOPASSWD: ALL
# 모든 가상 머신에서 파일 생성
[vagrant@control-node ~]$ sudo vi /etc/sudoers.d/ansible
ansible ALL=(ALL) NOPASSWD: ALL
ansible 파일 생성 전
[vagrant@control-node ~]$ ssh ansible@host1 "sudo id"
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
systemctl stop autofs
# autofs 서비스를 중지하면 자동으로 마운트 해제
umount /nfs_share
# autofs 관련 파일 삭제
rm -rf /etc/auto.direct
rm -rf /etc/auto.master.d/direct.autofs
설정 파일 생성
# /indirect 파일 생성
vi /etc/auto.master.d/indirect.autofs
/indirect /etc/auto.indirect
# /etc/auto.indirect 파일 생성
vi /etc/auto.indirect
share -rw,sync 10.0.2.15:/share
mysql_secure_installation
Set root password? [Y/n] y
New password: qwer1234
Re-enter new password: qwer1234
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
DB와 php를 연동하는 패키지 설치
yum install php-mysql -y
systemctl restart httpd
DB 설정
# 패스워드: qwer1234
mysql -u root -p
MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> CREATE USER wordpress@localhost IDENTIFIED BY "qwer1234";
MariaDB [(none)]> GRANT ALL ON wordpress.* TO wordpress@localhost;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit
WordPress 구축
워드프레스 설치
cd /tmp && wget http://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz -C /var/www/html
chown -R apache /var/www/html/wordpress