웹사이트 검색

MariaDB 데이터베이스 서버 설치, 보안 및 성능 조정 방법


데이터베이스 서버는 오늘날의 애플리케이션에 필요한 네트워크 인프라의 중요한 구성 요소입니다. 데이터를 저장, 검색, 업데이트 및 삭제할 수 있는 기능(필요한 경우)이 없으면 웹 및 데스크톱 앱의 유용성과 범위가 매우 제한됩니다.

또한 데이터베이스 서버를 설치, 관리 및 구성하는 방법(예상대로 작동하도록)을 아는 것은 모든 시스템 관리자가 갖춰야 할 필수 기술입니다.

이 기사에서는 MariaDB 데이터베이스 서버를 설치하고 보호하는 방법을 간략하게 검토한 다음 이를 구성하는 방법을 설명합니다.

MariaDB 서버 설치 및 보안

CentOS 7.x에서는 MariaDB가 MariaDB와 함께 여전히 Ubuntu에서 찾을 수 있는 MySQL을 대체했습니다. openSUSE의 경우도 마찬가지입니다.

간결하게 하기 위해 이 튜토리얼에서는 MariaDB만 사용하지만, 이름과 개발 철학이 서로 다른 것 외에도 관계형 데이터베이스 관리 시스템(RDBMS) Strong> 줄여서) 거의 동일합니다.

이는 클라이언트측 명령이 MySQLMariaDB 모두에서 동일하며 구성 파일의 이름이 지정되고 동일한 위치에 있음을 의미합니다.

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 루트 사용자의 비밀번호를 입력하라는 메시지가 표시됩니다.

위 패키지가 설치되면 데이터베이스 서비스가 실행 중이고 부팅 시 시작되도록 활성화되었는지 확인하세요(CentOSopenSUSE에서는 이 작업을 수동으로 수행해야 함). , 반면 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 스크립트를 실행하세요. 이 프로세스를 통해 다음을 수행할 수 있습니다.

  1. RDBMS 루트 사용자의 비밀번호 설정/재설정
  2. 익명 로그인 제거(따라서 유효한 계정이 있는 사용자만 RDBMS에 로그인할 수 있음)
  3. localhost 이외의 시스템에 대한 루트 액세스를 비활성화합니다.
  4. 테스트 데이터베이스 제거(누구나 액세스할 수 있음)
  5. 1~4와 관련된 변경 사항을 활성화합니다.

이 프로세스에 대한 자세한 설명은 RHEL/CentOS/Fedora 및 Debian/Ubuntu에 MariaDB 데이터베이스 설치의 설치 후 섹션을 참조하세요.

MariaDB 서버 구성

기본 구성 옵션은 지정된 순서대로 다음 파일에서 읽습니다: /etc/mysql/my.cnf, /etc/my.cnf~ /.my.cnf.

대부분 /etc/my.cnf만 존재합니다. 이 파일에서 서버 전체 설정을 지정합니다(각 사용자에 대해 ~/.my.cnf의 동일한 설정으로 재정의할 수 있음).

my.cnf에 대해 가장 먼저 주목해야 할 점은 설정이 각 범주 이름이 대괄호로 묶인 범주(또는 그룹)로 구성된다는 것입니다.

서버 시스템 구성은 [mysqld] 섹션에 제공되며 일반적으로 아래 표에서는 처음 두 설정만 찾을 수 있습니다. 나머지는 자주 사용되는 다른 옵션입니다(표시된 경우 선택한 사용자 정의 값으로 기본값을 변경합니다).

Setting and description

기본값

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.

소켓=/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).

We will change this to instruct the service to listen only on its main address (192.168.0.13):

bind_address=192.168.0.13

bind_address=0.0.0.0

port represents the port where the database server will be listening.

We will replace the default value(3306) with 20500 (but we need to make sure nothing else is using that port):
port=20500

While some people will argue that security through obscurity is not good practice, changing the default application ports for higher ones is a rudimentary -yet effective- method to discourage port scans.

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.

We will replace the default value with 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.

Unless you require hostnames to determine permissions, it is advisable to disable this variable (in order to speed up connections and queries) by setting its value to 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.

You should choose a query cache size that matches your needs based on 1) the number of repetitive queries, and 2) the approximate number of records those repetitive queries are expected to return. We will set this value to 100 MB for the time being:

query_cache_size=100M

query_cache_size=0(기본적으로 비활성화되어 있음을 의미)

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.

Again, this depends on the number of connections you are expecting. We can safely set this value to half the number of max_connections:

thread_cache_size=15

thread_cache_size=0(기본적으로 비활성화됨)

CentOS에서는 SELinuxMariaDB가 비표준 포트(20500)에서 수신 대기하도록 허용해야 합니다. ) 서비스를 다시 시작하기 전에:

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 성능 조정 및 최적화 팁

언제나 그렇듯, 이 기사에 대해 질문이나 의견이 있으면 주저하지 말고 알려주시기 바랍니다. 사용하고 싶은 다른 서버 설정이 있나요? 아래 댓글 양식을 사용하여 커뮤니티의 다른 사람들과 자유롭게 공유하세요.