pioneerxj 2023. 7. 15. 15:04

 

aws 접속

ssh + username@Public IP + -i 키페어

 

리눅스

Ctrl + a 맨앞에 

Ctrl + e 맨 뒤

 

$ dnf search 키워드

$ yum search 키워드

 

$ dnf info 패키지명

$ dnf info 패키지명

 

[amazon linux 2]

$ yum info httpd

  설치 가능한, 설치 했는지, 버전, 아키턱처 등

 

$ dnf install 패키지명

$ yum install 패키지명

[amazon linux 2]

$ yum install httpd -y

 

repository 저장소에서 다운해서 설치까지 함. (의존성있는 패키지도 함께 설치해줌)

rpm -qa httpd 설치 되었는지 확인

 

$ rpm -gc 

sudo systemctl status httpd

 

sudo vi /var/www/html/index.html

 

:10 10번 라인으로 커서 이동

:w test.txt 현재위치에 test.txt 이름으로 저장이 됨 

 

ifconfig 대신 ip addr 해도 됨

net tools가 깔려있으면 netstat 써도 되고 없으면 ss -antp 써야됨

 

redhat, centos debian, ubuntu
설치 패키지 확장 .rpm .deb
패키지 관리 프로그램 rpm (redhat package manager) dpkg (deb package)
패키지 명령어 rpm -qa 패키지명
rpm -ql 패키지명
dpkg -l 패키지명 (설치확인)
dpkg -L 패키지명 (설치파일 확인)
저장소에서 패키지 다운로드 후 설치 dnf install 패키지명 apt install 패키지명

ubuntu 계열

$ sudo apt update

$ sudo apt search apache

$ sudo apt show apache2  

$ sudo apt install apache2 -y

 

VPC등 생성 

가용영역 2개,  public subnet 2개, private subnet 2개,  NAT 게이트 웨이 1개

 

첫번째 웹서버 : amazon linux 2023  (public subnet 가용영역a )

amazon linux 2023
#! /bin/bash
dnf install -y httpd
systemctl start httpd
systemctl enable httpd
echo "TEST PAGE" > /var/www/html/index.html

 

두번째 웹서버 : ubuntu 22.04  (public subnet 가용영역b )

ubuntu linux 22.04
apt update
apt install apache2
echo "TEST PAGE2" > /var/www/html/index.html
systemctl restart apache2

private subnet에 DB1 : ami amazon linux 2023

ssh 접속 : windows  > web server로 ssh 접속 > webserver에서 db서버로 ssh 접속

mariadb105-server, mariadb 설치 (생성할 때 패키지 설치, 데몬 동작)

#! /bash/bash
sudo dnf update -y
sudo dnf install mariadb105-server  mariadb105 -y
sudo systemctl start mariadb
sudo systemctl enable mariadb

$ ps -ef | grep mariadb

$ ss -antp | grep :3306

$ sudo mysql_secure_installation

$ mysql -u root -p

 

MariaDB [(none)]> use mysql;

MariaDB [mysql]> select User,Host from user;

*db사용자 추가하기

CREATE USER  'admin'@'10.0.%' IDENTIFIED BY 'qwer1234';

GRANT ALL ON *.* TO 'admin'@'localhost';

grant all privileges on [데이터베이스명.테이블명] to [사용자@호스트] identified by '비밀번호' [with grant option];
FLUSH PRIVILEGES;

MariaDB [mysql]> exit

$ exit

 

web server에서

sudo dnf install mariadb105 -y

mysql -u admin -p -h  [DB서버사설IP 또는 DNS]

 

```

 ubuntu 인스턴스에서 패키지 설치하는 방법

$ sudo apt update  (저장소 URL 업데이트함)

$ sudo apt search mariadb (패키지 검색, server용/ client용)

$ sudo apt show mariadb-server  (해당 패키지 이름의 버전 등 정보확인)

$ sudo apt show mariadb-client

$ sudo apt install mariadb-server mariadb-client  -y

$ sudo systemctl status mariadb

$ ps -ef | grep mariadb

$ ss -antp | grep :3306

문제가 발생함.  ->  웹서버에서 db로 접근이 안됨.

$ sudo mysql_secure_installation    (root 암호 qwer1234! )

$ mysql -u root -p  (서버에 접속)

> use mysql;

> select User,Host from user;

> CREATE USER  'admin'@'10.0.%' IDENTIFIED BY 'qwer1234';

> flush privileges;

```

 

ubuntu mariadb 설정

ubuntu@ip-10-0-133-227:~$ ss -antp | grep :3306

LISTEN 0      80         127.0.0.1:3306      0.0.0.0:*

localhost 자신의 요청에 대해서만 응답을 함. -> 0.0.0.0:3306로 변경

 

ubuntu@ip-10-0-133-227:~$ cat /etc/mysql/mariadb.conf.d/50-server.cnf

bind-address            = 127.0.0.1 이부분을 변경해야함.

ubuntu@ip-10-0-133-227:~$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf

bind-address            = 0.0.0.0

sudo systemctl restart mariadb

ubuntu@ip-10-0-133-227:~$ ss -antp | grep :3306

LISTEN 0      80           0.0.0.0:3306      0.0.0.0:*

ubuntu@ip-10-0-133-227:~$ exit

 

웹서버에서 sudo apt install mariadb-client -y

웹서버에 php설치 - ubuntu OS 인 경우
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip libapache2-mod-php php php-cli php-common php-mysql php-json

ubuntu DB서버에서

mariadb-server 설치, wordpress가 사용할 database 생성, user사용자 생성, 사용자에게 db 권한부여

 

ubuntu 웹서버에서

wordpress 소스 다운로드, wp-config.php 파일에 db서버ip, db,  user, 암호 설정

 

$ cd ~

$ wget https://wordpress.org/latest.tar.gz   게시판소스다운로드

$ tar -xzf latest.tar.gz

$ cp wordpress/wp-config-sample.php wordpress/wp-config.php

$ vi wordpress/wp-config.php

 

변경전
 22 /** The name of the database for WordPress */
 23 define( 'DB_NAME', 'database_name_here' );
 24
 25 /** Database username */
 26 define( 'DB_USER', 'username_here' );
 27
 28 /** Database password */
 29 define( 'DB_PASSWORD', 'password_here' );
 30
 31 /** Database hostname */
 32 define( 'DB_HOST', 'localhost' );

 

define('DB_NAME', 'wordpress-dbwordpress');    DB 서버에 생성한 DB명
define('DB_USER', 'wordpress-useradmin');  DB서버에 생성한 사용자명
define('DB_PASSWORD', 'your_strong_passwordqwer1234');  그암호
define('DB_HOST', 'localhost[privateIP]');   DB서버의 IP주소나 DNS로 변경



변경후
 22 /** The name of the database for WordPress */
 23 define( 'DB_NAME', 'wordpress' );
 24
 25 /** Database username */
 26 define( 'DB_USER', 'admin' );
 27
 28 /** Database password */
 29 define( 'DB_PASSWORD', 'qwer1234' );
 30
 31 /** Database hostname */
 32 define( 'DB_HOST', '10.0.157.143' );

 

$ sudo mv ~/wordpress/*  /var/www/html/

$ ps -ef | grep httpd   (redhat 계열일 경우)

apache(사용자이름) httpd (프로세스이름)

$ ps -ef | grep apache2 (debian 계열일 경우-ubuntu)

www-data apache2

$ sudo chown apache:apache /var/www/html -R  

$ sudo systemctl restart httpd



$ curl localhost

index.html 내용이 보임 

index.php가 있으나 보이지 않음

http.conf 환경설정 변경이 필요함.

 

*redhat계열인 경우

[ec2-user@ip-10-0-18-13 httpd]$ ls -l /etc/httpd/conf/httpd.conf

-rw-r--r--. 1 root root 12005 Mar 16 15:18 /etc/httpd/conf/httpd.conf

[ec2-user@ip-10-0-18-13 httpd]$ sudo vi /etc/httpd/conf/httpd.conf

 

변경전
168 <IfModule dir_module>
169     DirectoryIndex index.html
170 </IfModule>
변경후
168 <IfModule dir_module>
169     DirectoryIndex index.php index.html
170 </IfModule>

 

[ec2-user@ip-10-0-18-13 httpd]$ sudo systemctl restart httpd  데몬재시작

[ec2-user@ip-10-0-18-13 httpd]$ sudo systemctl status httpd

 

*debian(ubuntu) 계열인경우

$ ls -l /etc/apache2/mods-available/dir.conf

$ sudo vi /etc/apache2/mods-available/dir.conf

변경 전
<IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
변경 후
<IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

$ sudo systemctl  restart apache2

 

웹브라우저로 접근 설정 완료

AWS  리소스 삭제하기  (default, VPC, subnet, 보안 그룹은 삭제하지마세요)
  1. EC2 > 인스턴스 삭제 (인스턴스 상태 > 종료)  -> “종료됨”
  2. VPC > NAT 게이트웨이 > 작업 > 삭제 >    상태가 Deleting   >  Deleted (대기)
  3. VPC > 인터넷 게이트웨이 > 작업 > VPC와 분리  >  상태: Detached  > 작업>삭제
default VPC의 인터넷 게이트웨이는 삭제하지 마세요. (이름이 없음)
  1. VPC > 탄력적 IP > IP주소 체크 하고 > 릴리즈
  2. VPC > subnet > public, private 체크 > 작업 > 서브넷 삭제
  3. VPC > 라우팅 테이블 > 라우팅 테이블 생성한거 체크 > 작업 > 라우팅 테이블 삭제
  4. VPC > 생성한 VPC 체크 > 작업 > VPC 삭제
  보안그룹 (security group)는 자동으로 선택되어 삭제됨.
ssh key 페어는 그냥 둠