Cloud/GCP

GCP - Wordpress 설치 및 DB 연결 자동화 Script

잇(IT) 2022. 6. 28. 13:08
728x90

목차

1. Script

2. Script를 이용한 인스턴스 생성


1. Script

 

- Wordpress, apache, PHP 설치 및 DB Server에 연결이 되도록 script를 자동화 부분에 넣으면 매번 직접 설치하지 않아도 인스턴스 생성시 설치 및 연결이 자동을 된다.

#! /bin/bash
sudo setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
sudo yum -y install httpd
sudo yum install -y wget
wget https://ko.wordpress.org/latest-ko_KR.tar.gz
tar xvfz latest-ko_KR.tar.gz
sudo cp -a wordpress/* /var/www/html/
sudo chown apache.apache /var/www/html/*
sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
sudo sed -i 's/database_name_here/wordpress/g' /var/www/html/wp-config.php
sudo sed -i 's/username_here/root/g' /var/www/html/wp-config.php
sudo sed -i 's/password_here/It12345!/g' /var/www/html/wp-config.php
sudo sed -i 's/localhost/10.0.16.3/g' /var/www/html/wp-config.php
sudo sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php/g' /etc/httpd/conf/httpd.conf
sudo cat > /var/www/html/index.html << EOF
<html><body><h1>GCP_WEBSERVER</h1></body></html>
EOF
sudo yum -y install epel-release yum-utils
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php73
sudo yum -y install php php-common php-opcache php-mcrypt php-cli php-gd php-crul php-mysqlnd
sudo systemctl restart httpd
sudo systemctl enable httpd

- 위의 Script는 Wordpress를 설치하고 DB가 wordpress, 사용자가 root, passwrod가 It12345!, DB Server의 주소가 10.0.16.3인 DB Server와 연결하도록 내용을 변경해주고 PHP를 설치하는 스크립트에 해당한다.


2. Script를 이용한 인스턴스 생성

 

- 인스턴스 생성 시 (관리 -> 자동화) 부분에 위에서 작성한 script를 넣는다.

 

- 생성된 인스턴스에 바로 접속하게 되면 위와 같이 이미 설정이 완료된 WEB page가 뜨는 것을 확인 할 수 있다.

(DB Server는 사전에 생성되어 있다.)

728x90

'Cloud > GCP' 카테고리의 다른 글

GCP - Auto Scaling + Load Balance  (0) 2022.06.29
GCP - Load Balance (이미지, 템플릿, 인스턴스 그룹 생성)  (0) 2022.06.29
GCP - CLI  (0) 2022.06.28
GCP - SQL(Database)  (0) 2022.06.28
GCP - Cloud DNS  (0) 2022.06.27