시작전 확인 사항
rpm -qa httpd mariadb → db설치 확인
sudo systemctl status httpd → 아파치 동작 확인
sudo systemctl start httpd → 아파치 실행
sudo systemctl enable httpd → 부팅 시 아파치 자동 실행
sudo systemctl status mariadb → mariadb 상태 확인
sudo systemctl start mariadb → mariadb 실행
sudo systemctl enable mariadb → 부팅 시 mariadb 자동 실행
MariaDB 데이터베이스서버의 이중화
Slave DB에서 Master와 동기화 설정
DB_Slave에서
change master to master_host=' 13.209.69.84',
master_user='slaveroot',
master_password='1234',
master_port=3306,
master_log_file='mysql-bin.000002',
master_log_pos=752;
→ 인터넷 창에서 master의 IP 주소를 확인. master_host='Master 인스턴스 IP 주소'입력
→ show master status; 명령어를 통해서 file과 position을 확인하여 master_log_file, master_log_pos에 각각 입력
flush privileges;
show slave status\G;
만약, Slave_IO_Running Yes가 아니라면
stop slave;
start slave;
show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 13.209.69.84
Master_User: slaveroot
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 918
Relay_Log_File: ip-172-31-14-255-relay-bin.000002
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 918
Relay_Log_Space: 834
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
복제 설정 시 주의점
- 1. MasterDB에서 SQL 쿼리문을 작성할 때마다 Position의 번호가 달라짐.
만약, 복제가 원활히 이루어지지 않은 상태에서 Master DB 작업이 이루어졌다면 Slave 쪽에서
Master Position 번호를 맞춰줘야 한다.
즉, 다음과 같은 작업이 필요하다.
1) Master DB에서 show master stauts; 명령어를 통해 Postion 번호 확인
2) Slave DB에서 stop slave 후 chang master~~ 명령어를 바뀐 Position 번호에 맞게(master_log=pos=바뀐 번호) 다시 입력
3) flush privileges;
4) start slave; - 복제는 데이터베이스에 이중화로 인해 안정성과 보안성을 확보할 수 있음.
그러나 Slave DB에서 보이는 바와 같이 이중화를 하기 전 있었던 데이터베이스는 여전히 존재
→ 이중화는 설치 직후 바로 설정하는 것이 좋음
이중화가 제대로구성되면 MasterDB에서 만드는 모든 데이터베이스 및 테이블이 SlaveDB에 복제됨
AWS EC2(Apache) - RDS(MySQL) 연동 워드프레스 구현
인스턴스 시작 apache
- EC2 대시보드에서 EC2 인스턴스(apache) 생성
- 이름 : apache
- AMI : Amazon Linux2
-인스턴스유형 : t2.micro
-키패어 : 기존 키페어 사용
-네트워크 설정 : 기본 보안그룹선택(ssh,web)
-스토리지 구성 : 8Gib - MobaXterm
Session 생성
퍼블릭 IPv4 주소, 키페어 설정 후 OK - 퍼블릭 IP 주소를 사용하여 원격 접속
ec2-user - EC2 인스턴스 업데이트
sudo yum update -y - 웹 서비스 프로그램 Apache 설치
sudo yum install -y httpd - php 설치
LAMP : Linux Apache Mariadb php
Linux Apache php/ MariaDB 따로 설정
EC2 - RDS
웹 서버 데이터베이스 서버를 따로 두는 형식으로 워드프레스
sudo amazon-linux-extras install -y php7.4 - 아파치 웹 서비스 시작
sudo systemctl start httpd - 재시작 시 자동으로 웹 서비스 동작 설정
sudo systemctl enable httpd - 동작 확인
sudo systemctl status httpd - 첫 시작 페이지 index.html 설정
sudo vi /var/www/html/index.html
-----------------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>apache test page</title>
</head>
<body>
테스트 페이지
</body>
</html>
-----------------------------------------------------------------------------------------
ESC → :wq - php 동작 확인
sudo vi /var/www/html/phpinfo.php
-----------------------------------------------------------------------------------------
<?php
phpinfo();
?>
-----------------------------------------------------------------------------------------
ESC → :wq - 웹 브라우저 주소창에서 확인
EC2_IP주소/index.html
EC2_IP주소/phpinfo.php
그림1 참조 - RDS를 MySQL로 구현할 예정이므로 MySQL 클라이언트 설치
sudo yum install -y mysql - wordpress 설치
sudo wget https://wordpress.org/latest.tar.gz - 압축 해제
sudo tar xfz latest.tar.gz - 압축 해제된 wordpress 폴더를 documentRoot로 복사
sudo cp -r wordpress /var/www/html - wordpress의 소유자를 apache로 변경
sudo chown -R apache.apache /var/www/html/wordpress - RDS 대시보드로 이동, RDS 데이터베이스 설치
-----------------------------------------------------------------------------------------
데이터베이스 생성
표준생성
엔진옵션 MySQL
엔진버전 MySQL 8.0.35
템플릿 프리 티어
DB 인스턴스 식별자 : wordpressDB
마스터암호 설정
스토리지 자동 조정 활성화 체크 해제
퍼블릭 엑세스 예
VPC 보안 그룹 새로 생성
이름 RDS-EC2-Connection-SecurityGroup
추가 구성
초기 데이터베이스 이름 wordpress
백업 - 자동 백업 해제
암호화 - 암호화 활성화 해제
유지관리 - 마이너 버전 자동 업그레이드 사용 해제
----------------------------------------------------------------------------------------- - wordpress의 wp-config.php생성
cd /var/www/html/wordpress
sudo cp wp-config-sample.php wp-config.php - wp-config.php 수정
sudo vi wp-config.php
-----------------------------------------------------------------------------------------
23 define( 'DB_NAME', 'wordpress' );
26 define( 'DB_USER', 'admin' );
29 define( 'DB_PASSWORD', 'password_here' );
32 define( 'DB_HOST', 'wordpressdb.ctue0oac8a8b.ap-northeast-2.rds.amazonaws.com' );
→ 새로 생성한 Amazon RDS 'wordpressDB'의 엔드포인트를 복사해서 'localhost' 자리에 붙여넣음
-----------------------------------------------------------------------------------------
ESC → :wq - RDS-EC2-Connection-SecurityGroup 수정
wordpressDB 선택 → 보안 → RDS-EC2-Connection-SecurityGroup →인바운드 규칙 편집
→유형 MYSQL/Aurora, 소스 유형 Anywhere-IPv4 → 규칙 저장 - 아파치 웹 서비스 재시작
sudo systemctl restart httpd - 윈도우 웹 브라우저에서 EC2_IP주소/wordpress를 입력하면 워드프레스의 첫 설치 과정으로 넘어감
(그림 2)
'KDT > Cloud' 카테고리의 다른 글
240105 Cloud (0) | 2024.01.05 |
---|---|
231229 Cloud (0) | 2023.12.29 |
231215 Cloud (0) | 2023.12.15 |
231204 Cloud (0) | 2023.12.04 |
231201 Cloud (0) | 2023.12.01 |