본문 바로가기

Project

[Linux] LoadBalncer, ISCSI, NFS,wordpress 를 이용한 인프라 구성

반응형

환경

VM : KVM

OS : CentOS7

Selinux 는 공통적으로 disabled상태로 진행했습니다.

PC화면 기준으로 작성하였습니다.

 

Storage Server

1. Network 설정

    LoadBalancer

        NAT 192..168.122.10/24

        Priv1 192.168.123.10/24

        Priv2

    Web1

        NAT

        Priv1 192.168.123.20/24

        Priv2 192.168.123.20/24

    Web2

        NAT

        Priv1 192.168.123.21/24

        Priv2 192.168.123.21/24

    Storage Server

        NAT

        Priv1

        Priv2 192.168.124.30/24

    Database Server

        NAT

        Priv1

        Priv2 192.168.124.40/24

 

 

2. NFS 설정 및 Apache 설치

    2-1 NFS pakage 설치          (Storage Server)

        [student@storage ~]$ sudo yum install -y nfs-utils

    2-2 /webcontent 생성 및 마운트  (Storage Server)

        [student@storage ~]$ sudo mkdir /webcontent

              -파티션 생성은 생략-

        [student@storage ~]$sudo mkfs.xfs /dev/vdb1

        [student@storage ~]$ sudo vi /etc/fstab

                                                      /dev/vdb1     /webcontent      xfs      defaults      0       0

        [student@storage ~]$ sudo mount -a

    2-3  디렉터리에 접근 할 경로 설정 (/etc/exports)                     (Storage Server)

        [student@storage ~]$ sudo vi /etc/exports

        /webcontent 192.168.124.0/24(rw,sync,no_root_squash)  저장

        [student@storage ~]$ sudo exportfs -r
    2-4 서비스 실행 및 방화벽해제          (Storage Server)

        [student@storage ~]$ sudo systemctl start nfs-server

        [student@storage ~]$ sudo systemctl enable nfs-server

        [student@storage ~]$ sudo firewall-cmd --permanent --add-service=nfs

        [student@storage ~]$ sudo firewall-cmd --permanent --add-service=rpc-bind
        [student@storage ~]$ sudo firewall-cmd --permanent --add-service=mountd
        [student@storage ~]$ sudo firewall-cmd --reload 

    2-5 Client에 nfs-utils 설치      (Web1과Web2 동일)

        [student@web1 ~]$ sudo yum install -y nfs-utils

    2-6 Mount 하기              (Web1과Web2 동일)
        [student@web1 ~]$ sudo mount -o rw,sync 192.168.124.30:/webcontent /var/www
        [student@web1 ~]$ vi /etc/fstab 

                                                         12 192.168.124.30:/webcontent /var/www nfs4 rw,sync 0 0
        [student@web1 ~]$ mount -a

    2-7 아파치 설치 & 실행 & 방화벽해제     (Web1과Web2 동일)

        [student@web1 ~]$ sudo yum install -y httpd

        [student@web1 ~]$ sudo systemctl start httpd

        [student@web1 ~]$ sudo systemctl enable httpd

        [student@web1 ~]$ sudo firewall-cmd --permanent --add-service=http

        [student@web1 ~]$ sudo firewall-cmd --reload

 

 

3. ISCSI 설정

     3-1 target pakage 설치       (Storage Server)

            [student@storage ~]$ yum install -y targetcli

     3-2 target 실행           (Storage Server)

             [student@storage ~]$ targetcli

     3-3 block 생성                (Storage Server)

        /> /backstores/block  create block1 /dev/vdc 

    3-4 IQN 주소설정                  (Storage Server)

          /> /iscsi/iqn.2020-06.com.example:server/tpg1/acls create iqn.2020-06.com.example:client

    3-5 ACL 설정                      (Storage Server)

          /> /iscsi/iqn.2020-06.com.example:server/tpg1/acls create iqn.2020-06.com.example:client

    3-6 LUN 설정                (Storage Server)

        /> /iscsi/iqn.2020-06.com.example:server/tpg1/luns create /backstores/block/block1

    3-7 나가기                     (Storage Server)

          /> exit

    3-8 서비스 실행&영구적용                 (Storage Server)

        [student@storage ~]$ sudo systemctl start target

        [student@storage ~]$ sudo systemctl enable target

    3-9 포트 열어주기(3206/tcp)                 (Storage Server)

        [student@storage ~]$ sudo firewall-cmd --add-port=3260/tcp --permanent 
        [student@storage ~]$ firewall-cmd --reload 
    3-10  초기자 설치          (Database Server)

        [student@database ~]$ sudo yum install -y iscsi-initiator-utils
    3-11 IQN 설정

        [student@database ~]$ sudo vim /etc/iscsi/initiatorname.iscsi

         InitiatorName=iqn.2020-06.com.example:client  저장

    3-12 서비스활성화

        [student@database ~]$ sudo systemctl start iscsi
        [student@database ~]$ sudo systemctl enable iscsi

    3-13 target 검색하기

         [student@database ~]$ sudo iscsiadm -m discovery -t st -p 192.168.124.30

    3-14    접속

        [student@database ~]$ sudo iscsiadm -m node -T iqn.2020-06.com.example:server -l

    3-15  확인

       [student@database ~]$ lsblk

sda => iscsi 로 가져온 storage

    3-16 LV 생성(파티션 생성 생략)

        [student@database ~]$ sudo pvcreate /dev/sda1
        [student@database ~]$ sudo vgcreate vg_db /dev/sda1
        [student@database ~]$ sudo lvcreate -n lv_db -l 1279 /dev/vg_db

        [student@database ~]$ mkfs.xfs /dev/vg_db/lv_db

    3-17 논리볼륨과 MariaDB 생성할 디렉터리랑 Mount 하기

        [student@database ~]$ sudo vi /etc/fstab

                    /dev/vg_db/lvdb       /var/lib/mysql           xfs       _netdev      0       0

 

이제 WordPress 를 구성해보자.

Wordpress 홈페이지 wordpress.org/

요구사항 : PHP 7.3 이상

                    MariaDB 10.1 이상

 

4. PHP 7.3 업데이트 및 설치 (Web1, Web2 동일)

    4-1 epel-release 업데이트

        [student@web1 ~]$ sudo yum install -y epel-release.noarch

    4-2 remi-release 7 다운받기

        [student@web1 ~]$ wget http://ftp.riken.jp/Linux/remi/enterprise/remi-release-7.rpm

                   (* wget 명령어가 안된다면 yum install -y wget)

    4-3 RPM 적용

        [student@web1 ~]$ sudo rpm -Uvh remi-release-7.rpm

    4-4 yum utils 다운

        [student@web1 ~]$ sudo yum install -y yum-utils

    4-5 php 7.3 버전으로 다운받도록 변경

        [student@web1 ~]$ sudo yum-config-manager --enable remi-php73

    4-6 php 설치

        [student@web1 ~]$ sudo yum install -y php

    4-7 php 버전확인

        [student@web1 ~]$ php -v

    4-8 Apache와 php 연결

    [student@web1 ~]$ sudo vi /etc/httpd/conf/httpd.conf 

       306 번째줄에   AddOutputFilter INCLUDES .shtml 라고써있는 부분이 있는데

                                      그  아랫줄에다가

                              AddType application/x-httpd-php .html .htm .php .inc
                              AddType application/x-httpd-php-source .phps 넣고 저장하기

308,309 가 작성한 부분

    4-9 확인

        [student@web1 ~]$ systemctl restart httpd 재시작

        [student@web1 ~]$ sudo vi /var/www/html/index.php 에 아래 사진 처럼 넣기

인터넷에 검색했을때 이렇게 나오면 성공

5. MariaDB 업데이트 및 설치  (Database Servre)

    5-1 MariaDB repo 작성

        [student@web2 ~]$ sudo vi /etc/yum.repos.d/MariaDB.repo  아래 사진 작성

                downloads.mariadb.org/mariadb/repositories/#distro=CentOS&distro_release=centos7-amd64--centos7&mirror=nav&version=10.4 참고로 여기가서 OS랑 버전 선택하면 하는방법 아주 자세히 나와있다.

    5-2 MariaDB server 설치

       [student@database ~]$ sudo yum install -y mariadb-server

    5-3 MariaDB 실행 및 영구적용

        [student@database ~]$ sudo systemctl start mariadb

        [student@database ~]$ sudo systemctl enable mariadb

    5-4 MariaDB 접속

        [student@database ~]$ mysql -u root -p 

root 비밀번호 설정을 안했기때문에 Enter키로 접속

    5-5 Web 에서 접속할 수 있는 권한을 가진 사용자 와 wordpress DB 생성

         MariaDB [(none)]> use mysql;            =>  생성을위해 mysql DB접속
         MariaDB [mysql]> create user 'wp-admin'@'192.168.124.20' identified by '1234';
                     Query OK, 0 rows affected (0.00 sec)         

                                     => wp-admin 사용자가 IP 192.168.124.20 접속할 수있는 사용자를 만든다. 그 비밀번호는 1234 이다.
         MariaDB [mysql]> create user 'wp-admin'@'192.168.124.21' identified by '1234';
                     Query OK, 0 rows affected (0.00 sec)

                                     => wp-admin 사용자가 IP 192.168.124.21 접속할 수있는 사용자를 만든다. 그 비밀번호는 1234 이다.

         MariaDB [mysql]> create database wordpress

                                     =>  wordpress DB생성

         MariaDB [mysql]> show databases;   => 생성된 DB목록보기

생성된 DB 확인

        MariaDbMariaDB [mysql]> grant all privileges on wordpress.* to 'wp-admin'@'192.168.124.20';

        MariaDbMariaDB [mysql]> grant all privileges on wordpress.* to 'wp-admin'@'192.168.124.21';

                                     => wp-admin@IP 에 모든 권한주기

        MariaDbMariaDB [mysql]> exit

    5-6 방화벽해제

        [student@database ~]$ sudo firewall-cmd --permanent --add-service=mysql

        [student@database ~]$ sudo firewall-cmd --reload

 

6. WordPress 설치하기 (Web1 & Web2는 /var/www 가 공유되어 있으므로 한군데에서만 하면 둘다 적용됩니다.)

    6-1 WordPress 다운받기

        [student@web1 ~]$ wget https://ko.wordpress.org/latest-ko_KR.tar.gz

    6-2 /var/html/www 압축풀기

        [student@web1 ~]$ sudo tar -xvzf latest.tar.gz -C /var/www/html

    6-3 접속

                 인터넷창에 192.168.123.20/wordpress 입력

                  (언어선택창이 나온다면 한국어 설정하시고 하시면 알아보기 쉽습니다.)

Let's GO!

   * 추가 만약 접속이 안되고 아래 화면처럼 나온다면

       [student@web2 ~]$ sudo yum install -y php-mysqlnd

       [student@web2 ~]$ sudo systemctl restart httpd

           하면 해결됩니다.

 

 

 

6-4 설정

      6-5 당황하지마라 (아래화면이 안나온다면 넘어가세요)

                   만약 이런 화면이 떴는데 무시하고 Run the Installation 버튼을 누르면 다시 초기화면으로 돌아간다.

                   글을 읽어보면 wp-config.php 파일을 추가하고 안에 아래 박스글자를 넣으면 해결된다.

                    [student@web1 ~]$ cd /var/www/html/wordpress/
                    [student@web1 wordpress]$ sudo vi wp-cofig.php

                                       회색박스 안의 내용 모두 복사후에 넣고 저장

    6-6 사이트 기본설정

    6-7 완성된 화면

로그인창 화면
홈페이지 설정
홈페이지 메인화면

 

7. 로드밸런싱 설정

    7-1 HAproxy 설치

        [student@loadbalance ~]$ sudo yum install -y haproxy
    7-2 설정파일 수정

        [student@loadbalance ~]$ sudo vim /etc/haproxy/haproxy.cfg

           7-2-1 63번째줄 5000 -> 80

변경전
변경후

          7-2-2 80번째 url 추가

변경전
변경후

    7-3 실행 및 방화벽 해제

        [student@loadbalance ~]$ sudo systemctl start haproxy

        [student@loadbalance ~]$ sudo systemctl enable haproxy

        [student@loadbalance ~]$ sudo firewall-cmd --permanent --add-service=http

        [student@loadbalance ~]$ sudo firewall-cmd --reload

 

    7-4 로드밸런싱 Test 하기

       7-4-1 Web1 은 그대로 두고 Web2의 NFS로 연결된 /var/www 언마운트 하기

             [student@web2 ~]$ sudo umount /var/www

       7-4-2 html 폴더를 만들고 index.html 만들어주기

             [student@web2 ~]$ sudo mkdir /var/www/html

             [student@web2 ~]$ sudo vim /var/www/html/index.html 

web2 인것을 알아보기위해 작성

        7-4-3 web1 에도 index.html 만들어주기기

              [student@web1 wordpress]$ sudo vi /var/www/html/index.html

web1 인것을 알아보기위해 작성

            7-4-4 로드 밸런서 주소로 접속을 한후 새로고침해서 web1 , web2 자동으로 바뀌는 지 확인

               

web1 연결

 

web2 연결

 

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

 

* 고쳐야 할 부분

1. Web2(192.168.123.21/wordpress) 메인화면 접속은 되는데 다른 페이지 넘어갈때  왜 192.168.123.20으로 전송이 되는가?

 즉 Web1 서버를 종료시키면 Web2 메인화면 접속 말고는 다른 버튼 눌렀을때 192.168.123.20으로 전송되면서 연결이 안된다.

2. Storage 가 Database 에게 ISCSI 서비스를 제공하는데 껐다키면 왜 Target 이 날라가는가?

 

[참고사항]

PHP 업데이트 부분 참고 opentutorials.org/module/1701/10235]

MariaDB 업데이트 downloads.mariadb.org/mariadb/repositories/#distro=CentOS&distro_release=centos7-amd64--centos7&mirror=nav&version=10.4

WordPress wordpress.org/

WordPress 설치 참고 dejavuqa.tistory.com/340

반응형