TrueNAS MariaDB Jail 구축하기

MariaDB는 오픈 소스 DBMS입니다. 데이터베이스를 생성하고 관리하는 역할을 하는 프로그램이죠. 이런 DBMS는 웹 서버를 구축하거나 할 때 많이 이 사용됩니다. 오늘은 MariaDB Jail을 구축해 보도록 하겠습니다.

 

MariaDB

MariaDB는 MySQL이 오라클로 인수 된 후 개발된 DBMS입니다. 오라클이 독과점 전략을 사용하는 것으로 유명한데, MySQL이 오라클에 인수되어 더 이상 오픈소스로 사용되지 못할 것을 우려하여 개발된 것이 MariaDB입니다. 그래서 MariaDB는 기본적으로 MySQL과 거의 대부분 호환됩니다.

MariaDB 이외에도 PostgreSQL  많은 DBMS가 있지만, 굳이 MariaDB를 사용하는 이유는 MariaDB가 다른 DBMS에 비해서 가볍기 때문입니다. 성능도 준수한 편이고요.

 

MariaDB Jail을 만드는 이유

일반적으로 어떤 서비스를 설치할 때에는 새로운 Jail을 만들고, 해당 Jail 내에 프로그램을 설치합니다. 데이터베이스가 필요한 프로그램의 경우 각 Jail 내에 DBMS를 설치하여도 됩니다. 물론 이것은 굉장히 비효율적이지요.

따라서 MariaDB Jail을 따로 만들면, 다른 Jail에 설치된 프로그램 입장에서는 외부에 데이터베이스 서버가 있는 것으로 인식할 터이니 설정만 잘 해주면 되고, 데이터베이스를 관리할 때에도 MariaDB Jail에 들어가기만 하여도 되니까 훨씬 편리합니다.

 

그럼 이제 설치해보도록 하겠습니다.

 

Jail 만들기

Jails로 가 주세요. Add를 눌러 Jail을 만듭니다.

Jail의 이름은 MariaDB로 설정해 주세요.

Jail Type은 Basejail로 설정해 주세요.

Jail의 IP는 고정IP로 설정해 주세요.

 

MariaDB 설치하기

iocage console MariaDB

MariaDB Jail에 로그인해 줍니다.

pkg update && pkg upgrade

pkg를 업데이트 해 줍니다.

pkg install mariadb105-client mariadb105-server

MariaDB 10.5 버전을 설치합니다.

 

MariaDB 초기 설정하기

service mysql-server onestart

설치가 다 되었으면, 초기 설정을 위해 MariaDB를 실행시켜 줍니다.

mysql_secure_installation

초기 설정을 시작합니다.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): #아직 루트 패스워드가 설정되지 않았으니 그냥 엔터를 누르시면 됩니다.
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

#Unix_socket을 이용한 로그인 방법인데, 해당 포스팅에서는 사용하지 않는 방법입니다. n을 입력
Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

#루트 패스워드를 설정할 것인지 묻습니다. 설정할 것이므로 y를 입력해 주세요. 충분히 복잡하게 설정해 주세요.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] y
 ... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

위의 내용처럼 설정을 진행시켜 주시면 됩니다.

vi /usr/local/etc/mysql/conf.d/server.cnf

MariaDB 설정 파일을 수정합니다.

아래와 같은 내용을 추가해주시면 됩니다.

[mysqld]
innodb_file_per_table = 1
init_connect="SET collation_connection = utf8mb4_general_ci"
init_connect="SET NAMES utf8mb4"
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci

[client]
default-character-set = utf8mb4

[mysqldump]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

 

MariaDB 로그인하기

mysql -u root -p

위의 명령어를 입력한 뒤 비밀번호를 입력하여 MariaDB 콘솔에 로그인할 수 있습니다.

 

MariaDB 서비스 시작하기

sysrc mysql_enable="YES"

자동 시작에 MariaDB를 등록해 주고,

service mysql-server restart

MariaDB를 재시작 해 줍니다.

 

마치면서

MariaDB Jail 생성이 끝났습니다.

다른 Jail에서 MariaDB Jail을 외부 데이터베이스 서버처럼 접근하여 사용할 수 있습니다.

답글 남기기