Linux 26 . php , DB, wordprocess 연결을 script로 자동화하기
2024. 2. 27. 21:16ㆍLinux/CentOS7

위와 같은 세팅을
스크립트를 이용해 자동화 해보겠다!
1번 서버
#! /bin/bash
yum install -y haproxy
sed -i 's/*:5000/*:80/g' /etc/haproxy/haproxy.cfg
sed -i 's/ server app1 127.0.0.1:5001 check/ server app1 172.16.0.11:50080 check/g' /etc/haproxy/haproxy.cfg
sed -i 's/ server app2 127.0.0.1:5002 check/ server app2 172.16.0.12:50180 check/g' /etc/haproxy/haproxy.cfg
sed -i 's/ server app3 127.0.0.1:5003 check/# server app3 127.0.0.1:5003 check/g' /etc/haproxy/haproxy.cfg
sed -i 's/ server app4 127.0.0.1:5004 check/# server app4 127.0.0.1:5004 check/g' /etc/haproxy/haproxy.cfg
sed -i 's/ use_backend static /# use_backend static/g' /etc/haproxy/haproxy.cfg
systemctl start haproxy
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
2번 서버
#! /bin/bash
yum install -y wget httpd epel-release yum-utils
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum install -y php php-cli php-gd php-common php-opcache php-mcrypt php-mysqlnd php-curl
sed -i 's/ DirectoryIndex index.html/ DirectoryIndex index.php/g' /etc/httpd/conf/httpd.conf
sed -i 's/Listen 80/Listen 50080/g' /etc/httpd/conf/httpd.conf
wget https://ko.wordpress.org/wordpress-5.8.8-ko_KR.tar.gz
tar xvfz wordpress-5.8.8-ko_KR.tar.gz
cp -ar wordpress/* /var/www/html/
cp /var/www/html/{wp-config-sample.php,wp-config.php}
sed -i 's/database_name_here/wordpress/g' /var/www/html/wp-config.php
sed -i 's/username_here/root/g' /var/www/html/wp-config.php
sed -i 's/password_here/It12345!/g' /var/www/html/wp-config.php
sed -i 's/localhost/172.16.0.13/g' /var/www/html/wp-config.php
systemctl start httpd
firewall-cmd --permanent --add-port=50080/tcp
firewall-cmd --reload
ifdown ens33
3번 서버
#! /bin/bash
yum install -y wget httpd epel-release yum-utils
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum install -y php php-cli php-gd php-common php-opcache php-mcrypt php-mysqlnd php-curl
sed -i 's/ DirectoryIndex index.html/ DirectoryIndex index.php/g' /etc/httpd/conf/httpd.conf
sed -i 's/Listen 80/Listen 50180/g' /etc/httpd/conf/httpd.conf
wget https://ko.wordpress.org/wordpress-5.8.8-ko_KR.tar.gz
tar xvfz wordpress-5.8.8-ko_KR.tar.gz
cp -ar wordpress/* /var/www/html/
cp /var/www/html/{wp-config-sample.php,wp-config.php}
sed -i 's/database_name_here/wordpress/g' /var/www/html/wp-config.php
sed -i 's/username_here/root/g' /var/www/html/wp-config.php
sed -i 's/password_here/It12345!/g' /var/www/html/wp-config.php
sed -i 's/localhost/172.16.0.13/g' /var/www/html/wp-config.php
systemctl start httpd
firewall-cmd --permanent --add-port=50180/tcp
firewall-cmd --reload
ifdown ens33
4번 서버
#! /bin/bash
yum install -y http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/mysql-community.repo
yum install -y mysql-community-server
systemctl start mysqld
password_match=`cat /var/log/mysqld.log | grep password | awk '{print $(NF)}'`
echo $password_match
mysql -uroot -p$password_match --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'It12345!' ; flush privileges'"
password=It12345!
mysql -uroot -p$password -e "grant all privileges on *.* to 'root'@'%' IDENTIFIED BY 'It12345!' ; create database wordpress; flush privileges;"
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
ifdown ens33




스크립트를 작성하는 것이 굉장이 어려울 수도 있다.
하지만 먼저 수동으로 설치한 뒤에 history 명령어로
내가 입력한 명령어들을 확인하고
순서대로 정리하면 쉽게 만들어진다.
MySQL의 경우 초기 password를 불러와 변경 시키는 것을
awk 명령어를 사용해 변수에 대입해줬다.
쉘 스크립트 파일에 입력한 다음
sh 명령어로 다시 실행시키면 자동 설치가 완료된다.





잘 작동하는 것을 볼 수 있다!!
이상으로 스크립트를 사용해
PHP Web, MySQL, Wordpress 를 자동으로 구성 해보았다.
'Linux > CentOS7' 카테고리의 다른 글
Linux 29. Database 이중화 (0) | 2024.05.10 |
---|---|
Linux 27. XE로 웹서비스 (0) | 2024.05.07 |
Linux 25 . MySql, php, wordpress 구성 (0) | 2024.02.27 |
Linux 24 . MySql (0) | 2024.02.26 |
Linus 23 . HAProxy (1) | 2024.02.25 |