본문 바로가기

IaC Application/3tier-service

2tier - service

구성도

--1tier 실습 원복
[root@mariadbserver ~]# systemctl stop httpd.service
[root@mariadbserver ~]# systemctl stop php-fpm.service
[root@mariadbserver ~]# dnf -y remove httpd
[root@mariadbserver ~]# dnf -y remove php-fpm
[root@was ~]# dnf -y install httpd
[root@was ~]# dnf -y install httpd php-fpm php-mysqlnd
[root@was ~]# vi /etc/php-fpm.d/www.conf
392 security.limit_extensions = .php .php3 .php4 .php5 .php7 .htm .html

[root@was ~]# chmod 777 /var/lib/php/session/
[root@was ~]# ls -ld /var/lib/php/session/
drwxrwxrwx. 2 root apache 6 10월 20 15:09 /var/lib/php/session/

[root@was ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/httpd.service.d
             └─php-fpm.conf
     Active: active (running) since Mon 2024-03-25 12:08:41 KST; 2min 3s ago

[root@was ~]# systemctl start php-fpm
[root@was ~]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; preset: disabled)
     Active: active (running) since Mon 2024-03-25 12:08:41 KST; 1min 37s ago
--외부에서 압축파일가져와서 /var/www/html/ 아래에 풀기
[root@was html]# ls
WebTest-php8-mariadb.tar.gz  dbconn.php  index.html
[root@was html]# tar -xzvf WebTest-php8-mariadb.tar.gz
./
./index.html
./info.php
./board/
./board/board_write.php.bak
./board/upload/
./board/upload/.bash_history
./board/board_list.php
./board/board_view.php
./board/board_delete_ok.php
./board/board_file_download.php
./board/board_write.php
./board/board_write_ok.php
./member/
./member/member_nick_change.php
./member/member_login_check.php
./member/member_logout.php
./member/member_register.php
./member/member_register_ok.php
./member/member_info.php
./member/member_nick.php
./member/member_login.php
./member/member_info_change.php
./create_db.php
./db.sql
./dbconn.php.bak
./mysqli_query.php
./mysqli_query_insert.php
./mysqli_select_db.php
./test.php
./webtest_DB.sql
./index.php
./head.php
./style_contents.css
./style_head.css
./dbconn.php
./WebTest-php8-mariadb.tar.gz
[root@was html]# ls
WebTest-php8-mariadb.tar.gz  dbconn.php.bak  member                   style_head.css
board                        head.php        mysqli_query.php         test.php
create_db.php                index.html      mysqli_query_insert.php  webtest_DB.sql
db.sql                       index.php       mysqli_select_db.php
dbconn.php                   info.php        style_contents.css

[root@was html]# rm -rf index.html
[root@was html]# systemctl restart httpd

--dbconn.php 파일 /var/www/html 밑에 추가 후 확인

--dbconn.php 수정
[root@was html]# vi dbconn.php
<?php
//dbconn.php : 데이터베이스 접속용
//DB 접근 성공,실패 여부 확인
//mysqli_connect("호스트주소","사용자명","암호","DB명");
$conn = mysqli_connect("200.200.200.148","root","P@ssw0rd","WebTest");

if($conn){
    echo"DB 연결 성공";
}
else{
    echo"DB 연결 실패";
}

?>
--dbconn.php 수정했는데도 연결 안됨
--사용자 만들기
MariaDB [mysql]> create user `root`@`200.200.200.147` identified by 'P@ssw0rd';
Query OK, 0 rows affected (0.006 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.004 sec)

MariaDB [mysql]> show grants for `root`@`localhost`;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED BY PASSWORD '*8232A1298A49F710DBEE0B330C42EEC825D4190A' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                                                          |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)

--퍼미션 없으므로 DB 연결 안됨
MariaDB [mysql]> show grants for `root`@`200.200.200.147`;
+-------------------------------------------------------------------------------------------------------------------+
| Grants for root@200.200.200.147                                                                                   |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `root`@`200.200.200.147` IDENTIFIED BY PASSWORD '*8232A1298A49F710DBEE0B330C42EEC825D4190A' |
+-------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

--퍼미션 추가
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'200.200.200.147' WITH GRANT OPTION;
Query OK, 0 rows affected (0.001 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]>
MariaDB [mysql]> show grants for `root`@`200.200.200.147`;
+----------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@200.200.200.147                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`200.200.200.147` IDENTIFIED BY PASSWORD '*8232A1298A49F710DBEE0B330C42EEC825D4190A' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

--1tier에서 회원가입했던 정보로 로그인 시도

--게시판에 글 작성 후 mariadb server에서 확인
MariaDB [mysql]> use WebTest;

MariaDB [WebTest]> select * from board;
+-----------+-----------+-------------+-------------------+------------+-----------------+---------+-----------+----------+----------+---------------------+
| strNumber | strName   | strPassword | strEmail          | strSubject | strContent      | htmlTag | viewCount | filename | filesize | writeDate           |
+-----------+-----------+-------------+-------------------+------------+-----------------+---------+-----------+----------+----------+---------------------+
|         1 | 배지원    | P@ssw0rd    | baejw03@naver.com | 1st        | 1234            | T       |         0 |          |        0 | 2024-03-25 11:22:01 |
|         2 | 배지원    | P@ssw0rd    | baejw03@naver.com | 2st        | 200.200.200.147 | T       |         1 |          |        0 | 2024-03-25 12:40:08 |
+-----------+-----------+-------------+-------------------+------------+-----------------+---------+-----------+----------+----------+---------------------+
2 rows in set (0.000 sec)

'IaC Application > 3tier-service' 카테고리의 다른 글

1tier-service  (0) 2024.03.25
DBMS 실습  (0) 2024.03.22