(9)AWS(아마존 웹서비스) 홈페이지 만들기 – CentOS7(Linux7) MySQL 초기 설정 및 WordPress용 DB생성하기

“내 소유의 홈페이지 사이트 만들기” 전체 설치 과정에서 이 글의 위치는 다음과 같습니다.

  • AWS 유저등록 -> EC2 인스턴스 등록 -> EC2 인스턴스 확인 ->PHP7설치 -> Apache HTTP Server설치 -> firewalld,SELinux정지 -> PHP.ini수정 -> Apache HTTP + PHP 연결 -> MySQL설치 -> WordPress용 DB작성 -> WordPress설치 -> 도메인 구입 -> Public IP구입 -> Public 도메인,IP의 DNS등록 -> 홈페이지 URL 변경 -> ssl증명서 작성(https용) -> ssl증명서 갱신 스케줄 등록 -> ssh접속 타임아웃 변경-> 가장메모리 증설 -> 타임존 변경

참고로 이 글은 AWS 웹 서비스 환경 작성을 위한 글 목록의 일부이지만 제공 업체(Azuru, GCP 등)가 다르더라도 Linux 7 운영 체제라면 이 글의 내용을 적용할 수 있습니다.

MySQL의 초기 설정

이제 초기 설정을 해줍니다. MySQL의 초기 설정을 하기 위해서는 root 유저의 패스워드가 요구됩니다. 초기 패스워드는 랜덤으로 지정되기 때문에 직접 확인해보지 않으면 알 수가 없습니다. 초기설정을 하기 전에 먼저 패스워드를 확인합니다.

$ sudo cat /var/log/mysqld.log | grep "temporary password"
2020-04-12T12:40:07.960681Z 1 [Note] A temporary password is generated for root@localhost: J)7Ji0epDke&

아래의 초기설정 커맨드를 입력하고 조금 전에 확인한 패스워드를 입력해줍니다. 그러고나면 새로운 패스워드를 입력 받습니다. 패스워드는 영어 대소문자, 특수문자, 숫자를 포함한 8자리 이상이어야 합니다. 새로운 패스워드를 2회 입력하면 root 유저의 패스워드 변경여부를 묻습니다. root 유저의 패스워드도 변경할 경우, y를 입력하여 새로운 패스워드를 2회 입력하여 변경해주고, 남은 확인사항에 전부 y를 입력해줍니다. 변경 작업이 끝나면 All done! 이 출력됩니다.

$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:J)7Ji0epDke&
The existing password for the user account root has expired. Please set a new password.
New password: Exsamplepassword&&
Re-enter new password: Exsamplepassword&&
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y
New password: Exsamplepassword&&
Re-enter new password: Exsamplepassword&&
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Dropping test database…
Success.
Removing privileges on test database…
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!

패스워드 정책 확인하기

패스워드 Policy에 관해서는 MySQL에 로그인해서 확인할 수 있습니다.

$ mysql -u root -p
Enter password: Exsamplepassword&&
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

아래는 디폴트 값입니다.

mysql> SHOW GLOBAL VARIABLES LIKE 'validate%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+

SQL을 통해 폴리시를 조절하고 패스워드를 수정할 수 있습니다. 필요에 따라 설정해주세요.

・validate_password_check_user_name : 패스워드에 유저ID 포함 여부 체크
・validate_password_dictionary_file : 패스워드 보안 수준이 Strong일 경우 패스워드로써 피해야하는 단어가 정의된 파일을 지정합니다.
・validate_password_length : 패스워드 최소 길이
・validate_password_mixed_case_count : 최소한 포함해야하는 영어 대소문자 수
・validate_password_number_count : 최소한 포함해야하는 숫자 수
・validate_password_policy : 패스워드 보안 수준. Low가 가장 낮은 값이며 Low로 설정해도 패스워드 최소 길이 정책은 유효합니다. 가장 높은 값은 Strong입니다. 위의 validate password dictionary file 옵션을 사용합니다.
・validate_password_special_char_count : 최소한 포함해야하는 특수문자 수

예시)

mysql> SET GLOBAL validate_password_length=4;
mysql> SET GLOBAL validate_password_policy=LOW;
mysql> SET GLOBAL validate_password_special_char_count=2;

root 유저의 패스워드를 수정할 때는 아래의 SQL문을 사용합니다. 설정이 끝났다면 quit 명령어로 MySQL에서 빠져나옵니다.

mysql> set password for root@localhost=password('새 패스워드');
mysql> quit
Bye
$

my.cnf를 수정하여 문자 인코딩 설정과 패스워드 교체 주기를 설정해줍니다. 아래 설정내용을 기존설정의 최하단에 추가 기입해주세요.

$ sudo vi /etc/my.cnf
[mysqld]
........중간생략.......
character-set-server = utf8
default_password_lifetime = 0

WordPress용 MySQL 데이터베이스 작성하기

MySQL에 다시 로그인해서 WordPress용 데이터베이스를 작성합니다. 임의로 데이터베이스의 이름을 정해주세요. 데이터베이스명,유저명,패스워드는 워드프레스 설치에서 사용합니다. 기록해두세요.
예)
데이터베이스 명 : sampldb
유저 명 : sampleuser
패스워드 : Examplepassword&&

$ mysql -u root -p
Enter password: Exsamplepassword&&
....중간생략....
mysql>
mysql>create database 데이터베이스명;
Query OK, 1 row affected (0.00 sec)
mysql>grant all privileges on 데이터베이스명.* to 유저명@localhost identified by '패스워드';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>quit
Bye
$

AWS 웹 서비스 환경 구축 전체 목록

이 글은 AWS 웹 서비스 환경 작성을 위한 전체 절차의 한 부분입니다. 전체 목록은 다음을 참조하십시오.

AWS EC2 웹 서비스(Wordpress) 구축 전체 글 목록
EC2(Elastic Compute Cloud) 웹 서비스 구축 전체 글 워드프레스 설치 , 환경 설정 전체 글

다음 글

(10)AWS(아마존 웹서비스) 홈페이지 만들기 - CentOS7(Linux7) Wordpress설치하기
"내 소유의 홈페이지 사이트 만들기" 전체 설치 과정에서 이 글의 위치는 다음과 같습니다. AWS 유저등록 -> EC2 인스턴스 등록 -> EC2 인스턴스 확인 ->PHP7설치 -> Apache HTTP Server...
제목과 URL을 복사했습니다