💻 Linux
CentOS7 웹 서버와 DB서버 따로 구축 후 연동
sa1t
2022. 4. 20. 13:50
반응형
# DB와 web 분리 구축
# 서버 구축
CentOS7 First vmware
# 브릿지 설정
centos newwork Adapter - nat에서 bridged로 변경
vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO="static"
IPADDR=192.168.0.41
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=8.8.8.8
systemctl restart network
# httpd, php, mariadb, mariadb-server, php-mysqlnd 설치
yum -y install httpd php mariadb mariadb-server php-mysqlnd
systemctl restart httpd
systemctl restart mariadb
systemctl status httpd
systemctl status mariadb
systemctl enable httpd
systemctl enable mariadb
# 방화벽
systemctl stop firewalld
systemctl diable firewalld
setenforce 0
# XE 서버 구축
cd /home/centos/다운로드
mv xe.zip /var/www/html
cd /var/www/html
unzip xe.zip
yum -y install php-*
yum -y --skip-broken install php-*
vim /etc/httpd/conf/httpd.conf
>> :set nu
>> 151
>> AllowOverride All
systemctl restart httpd
chmod 707 xe
cd xe
systemctl restart httpd
# DDOS 공격 방어하기 명령어
iptables -I INPUT -p tcp --dport 80 -m state --state NEW -m recent --update --seconds 1 --hitcount 10 -j DROP
# DB 구축
Centos7 Second vmware
# 브릿지 설정
centos newwork Adapter - nat에서 bridged로 변경
vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO="static"
IPADDR=192.168.0.42
NETMASK=255.255.255.0
GATEWAY=192.168.0.2
DNS1=8.8.8.8
systemctl restart network
# 방화벽 해제
systemctl stop firewalld
systemctl diable firewalld
setenforce 0
# DB설치
yum -y install mariadb mariadb-server
yum -y --skip-broken install php php-*
systemctl restart mariadb
systemctl enable mariadb
# mariadb database 오류
mysql
GRANT ALL PRIVILEGES ON wpDB.* TO wpUser@'%' IDENTIFIED BY '1234';
# wpDB에 접근해서 사용하는 모든 명령어의 권한을
# 어디서 접속하든 wpUser에게 사용가능하게 함
GRANT ALL PRIVILEGES ON wpDB.* TO wpUser@localhost IDENTIFIED BY '1234';
# wpDB에 접근해서 사용하는 모든 명령어의 권한을
# 로컬에서 접속할때 wpUser에게 사용가능하게 함
EXIT
mysql -u wpUser -p1234
CREATE DATABASE wpDB; #wpDB데이터 베이스 생성 가능
# mariadb database 외부 접속 허용
mysql -u root -p
use mysql; #database를 mysql로 변경
select host,user from user;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234';
# *.*은 모든 DB접근, '%' 모든 IP에 대해 허용
flush privileges; # grant all 명령어 적용
# 방화벽 설정
systemctl restart firewalld
firewall-cmd --zone=public --permanent --add-port=3306/tcp
# CentOS에서 기본적으로 3306port가 방화벽에서 차단되어있기에 차단 해제
firewall-cmd --reload #방화벽 재로딩
# 서버와 데이터 베이스 연동 확인
mysql -h 192.168.0.42 -u webUser -p1234;
# webUser 데이터 베이스를 구축한 centos second ip주소 입력 ,
# 데이터베이스 계정 비밀번호 입력
Welcome to the MariaDB monitor. Commands end with ; or \\g.
Your MariaDB connection id is 13
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.
# 접속 완료 확인
# 데이터 베이스 확인
SHOW DATABASES;
# webDB 데이터 베이스 확인
반응형