A database server is an critical component of the network infrastructure necessary for today’s applications. Without the ability to store, retrieve, update, and delete data (when needed), the usefulness and scope of web and desktop apps becomes very limited.

데이터베이스 서버를 설치, 관리 및 구성하는 방법을 알고 있어야만 시스템 관리자가 가져야 할 필수 기술입니다.
이 기사에서는 MariaDB 데이터베이스 서버를 설치하고 보안하는 방법을 간단히 살펴본 후 구성하는 방법을 설명하겠습니다.
MariaDB 서버 설치 및 보안
CentOS 7.x에서 MariaDB는 MySQL을 대체했으며, Ubuntu(그리고 MariaDB)에서도 여전히 찾을 수 있습니다. openSUSE도 마찬가지입니다.
간략히 하기 위해 이 튜토리얼에서는 MariaDB만 사용할 것이지만, 서로 다른 이름과 개발 철학을 가졌다는 점을 유의하십시오. 관계형 데이터베이스 관리 시스템(RDBMSs)은 거의 동일합니다.
즉, 클라이언트 측 명령은 MySQL과 MariaDB 모두 동일하며, 구성 파일은 동일한 위치에 동일한 이름으로 저장됩니다.
MariaDB를 설치하려면 다음을 수행하십시오:
--------------- On CentOS/RHEL 7 and Fedora 23 --------------- # yum update && yum install mariadb mariadb-server # CentOS --------------- On Debian and Ubuntu --------------- $ sudo aptitude update && sudo aptitude install mariadb-client mariadb-server --------------- On openSUSE --------------- # zypper update && zypper install mariadb mariadb-tools # openSUSE
Ubuntu에서는 RDBMS 루트 사용자의 암호를 입력하라는 메시지가 표시됩니다.
위 패키지를 설치한 후 데이터베이스 서비스가 실행 중이며 부팅 시 자동으로 시작되도록 활성화되었는지 확인하십시오(CentOS 및 openSUSE에서는 이 작업을 수동으로 수행해야 하지만 Ubuntu에서는 이미 처리되었을 것입니다):
--------------- On CentOS/RHEL 7 and Fedora 23 --------------- # systemctl start mariadb && systemctl enable mariadb --------------- On openSUSE --------------- # systemctl start mysql && systemctl enable mysql
그런 다음 mysql_secure_installation
스크립트를 실행하십시오. 이 프로세스를 통해 다음을 수행할 수 있습니다:
- RDBMS 根用户의 암호를 설정하거나 리셋하기
- 匿名的 로그인을 제거하여 (따라서 유효한 계정을 가진 사용자만 RDBMS에 로그인할 수 있게) 설정하기
- 로컬호스트 이외의 기기에서의 루트 アクセ스를 사용하지 않도록 설정하기
- 사용자에 의해 액세스 가능한 테스트 데이터베이스를 제거하기
- 1에서 4까지의 변경사항을 활성화하기
이 과정에 대한 자세한 説明은 MariaDB 데이터베이스在 RHEL/CentOS/Fedora 및 Debian/Ubuntu 上的安装 의 Post installation section을 참조할 수 있습니다.
MariaDB 서버 구성하기
기본 구성 옵션은 다음 파일을 읽어들여 주어진 順序로 처리되며, /etc/mysql/my.cnf
, /etc/my.cnf
및 ~/.my.cnf
입니다.
대부분의 경우에는 /etc/my.cnf
만 存在하며, 이 파일에서 우리는 서버 전역 설정을 지정할 수 있으며 (각 사용자에 대한 동일한 설정을 ~/.my.cnf
에 재정의할 수 있습니다.) 지정할 수 있습니다.
my.cnf
에 대한 첫 번째 것은 옵션이 분류되어 있는 카테고리(또는 그룹)로 구성되어 있다는 것입니다. 어느 카테고리 이름은 사각 괄호로 감싸져 있습니다.
서버 시스템 구성은 [mysqld]
섹션에 기록되며, typically you will find only the first two settings in the table below. 나머지는 자주 사용되는 옵션입니다. (지정된 경우에는 기본 값을 우리가 결정한 사용자 지정 값으로 대체합니다):
Setting and description | Default value |
datadir is the directory where the data files are stored. | datadir=/var/lib/mysql |
socket indicates the name and location of the socket file that is used for local client connections. Keep in mind that a socket file is a resource that is utilized to pass information between applications. | socket=/var/lib/mysql/mysql.sock |
bind_address is the address where the database server will listen on for TCP/IP connections. If you need your server to listen on more than one IP address, leave out this setting (0.0.0.0 which means it will listen on all IP addresses assigned to this specific host).
이를 변경하여 서비스를 suo main address (192.168.0.13) only 듀얼하도록 지시하는 것입니다: bind_address=192.168.0.13 |
bind_address=0.0.0.0 |
port represents the port where the database server will be listening.
기본값(3306)을 20500으로 대체합니다(다만, 이 포트를 사용하고 있는 다른 것이 없는지 확인해야 합니다): 보안을 위해 불명확성을 활용하는 것이 좋은 방법이 아니라고 주장하는 사람들도 있지만, 기본 애플리케이션 포트를 더 높은 포트로 변경하는 것은 포트 스캔을 방해하는 기본적이면서도 효과적인 방법입니다. |
port=3306 |
innodb_buffer_pool_size is the buffer pool (in bytes) of memory that is allocated for data and indexes that are accessed frequently when using Innodb (which is the default in MariaDB) or XtraDB as storage engine.
기본값을 256 MB로 대체합니다: innodb_buffer_pool_size=256M |
innodb_buffer_pool_size=134217728 |
skip_name_resolve indicates whether hostnames will be resolved or not on incoming connections. If set to 1, as we will do in this guide, only IP addresses.
권한을 결정하기 위해 호스트 이름이 필요하지 않다면, 이 변수를 비활성화하는 것이 좋습니다(연결 및 쿼리를 가속화하기 위해). 그 값을 1로 설정하십시오: skip_name_resolve=1 |
skip_name_resolve=0 |
query_cache_size represents the size (in bytes) available to the query cache in disk, where the results of SELECT queries are stored for future use when an identical query (to the same database and using the same protocol and same character set) is performed.
쿼리 캐시 크기는 1) 반복 쿼리의 수와 2) 그 반복 쿼리가 반환할 기록의 대략적인 수를 기반으로 선택해야 합니다. 일단은 이 값을 100 MB로 설정하겠습니다: query_cache_size=100M |
query_cache_size=0 (which means it is disabled by default) |
max_connections is the maximum number of simultaneous client connections to the server. We will set this value to 30: max_connections=30Each connection will use a thread, and thus will consume memory. Take this fact into account while setting max_connections. |
max_connections=151 |
thread_cache_size indicates the numbers of threads that the server allocates for reuse after a client disconnects and frees thread(s) previously in use. In this situation, it is cheaper (performance-wise) to reuse a thread than instantiating a new one.
다시 말하지만, 이것은 예상하는 연결 수에 따라 달라집니다. 이 값을 max_connections의 절반으로 안전하게 설정할 수 있습니다: thread_cache_size=15 |
thread_cache_size=0 (disabled by default) |
CentOS에서는 서비스를 재시작하기 전에 SELinux에게 비표준 포트(20500)에서 MariaDB를 수신하도록 허용해야 합니다:
# yum install policycoreutils-python # semanage port -a -t mysqld_port_t -p tcp 20500
그런 다음 MariaDB 서비스를 재시작합니다.
MariaDB 성능 튜닝
우리의 특정 요구에 맞게 구성을 확인하고 조정하는 데 도움을 주기 위해 mysqltuner를 설치할 수 있습니다(우리의 데이터베이스 서버의 성능을 향상시키고 안정성을 높일 제안을 제공하는 스크립트):
# wget https://github.com/major/MySQLTuner-perl/tarball/master # tar xzf master
그런 다음 tarball에서 추출한 폴더로 디렉토리를 변경하십시오(정확한 버전은 각각 다를 수 있음):
# cd major-MySQLTuner-perl-7dabf27
그리고 실행하십시오(관리 MariaDB 계정 자격 증명을 입력하라는 메시지가 표시됩니다)
# ./mysqltuner.pl
스크립트의 출력 자체가 매우 흥미로운데, 권장 값을 사용하여 조정할 변수가 나열된 하단으로 건너뛰겠습니다:

query_cache_type
설정은 쿼리 캐시가 비활성화 (0)되었는지 활성화 (1)되었는지를 나타냅니다. 이 경우, mysqltuner는 비활성화하도록 권고하고 있습니다.
그렇다면 왜 지금 비활성화하라는 권고를 받는 걸까요? 그 이유는 쿼리 캐시가 주로 고독한 읽기/낮은 쓰기 시나리오에서 유용하기 때문입니다(우리의 경우가 아니라, 우리는 방금 데이터베이스 서버를 설치했기 때문입니다).
경고: 프로덕션 서버의 구성을 변경하기 전에, mysqltuner에서 제공하는 권고가 기존 설정에 부정적인 영향을 미치지 않도록 확인하기 위해 전문 데이터베이스 관리자와 상의하는 것이 매우 권장됩니다.
요약
이 기사에서는 MariaDB 데이터베이스 서버를 설치하고 보안을 설정한 후 구성하는 방법에 대해 설명했습니다. 위 표에 나열된 구성 변수는 서버를 사용할 때 고려할 수 있는 몇 가지 설정에 불과하며 나중에 튜닝할 때 참고할 수 있습니다. 변경하기 전에 항상 공식 MariaDB 설명서를 참조하거나 MariaDB 성능 튜닝 팁을 참조하십시오:
놓치지 마세요: 15가지 유용한 MariaDB 성능 튜닝 및 최적화 팁
언제든지 이 기사에 관한 질문이나 의견이 있으시면 언제든지 알려주십시오. 사용하고 싶은 다른 서버 설정이 있습니까? 아래의 댓글 양식을 사용하여 커뮤니티와 공유해 주시기 바랍니다.
Source:
https://www.tecmint.com/install-secure-performance-tuning-mariadb-database-server/