'MySQL-MariaDB'에 해당되는 글 11건

  1. 2016.04.27 리눅스 MariaDB 설치하기

리눅스 MariaDB 설치하기


OS : CentOS 6.3 x64



1. 다운로드


다운로드 : https://downloads.mariadb.org


현재 최신 안전화버전은 10.1 이다.



설치방법은 소스컴파일 방식과 패키지 설치방식이 있는데 어느쪽이 더 좋은가는 


본인의 편의성,운영스타일 등을 생각해 스스로 선택하면 된다.


인터넷에 떠도는 카더라 소식통을 보면 특정 플랫폼에서 어떤 방식이 더 좋니마니 하는 얘기가 많은데


이것도 믿을지 말지는 본인 몫이다. 


systemv는 컴파일 방식을 선호하기에 mariadb-10.1.13.tar.gz 을 다운받았다.



2. 설치


설치에 필요한 패키지를 먼저 yum 으로 설치한다.


yum install -y gcc gcc-c++ cmake ncurses-devel bison libxml2-devel


다운받은 압축파일을 서버의 적당한 위치에 올려두고 압축을 푼다.


tar xvfz mariadb-10.1.13.tar.gz


cd mariadb-10.1.13


설치는 cmake(configure), make, make install 의 과정을 거친다.



2.1 cmake


cmake에 붙여쓸수 있는 옵션은 굉장히 다양하지만 정확한 용도와 가능을 모른다면 안쓰느니만 못하다.


인터넷에 나도는 복붙수준의 장황한 옵션들은 절대 필수가 아니므로 스스로 아는 범위내에서 꼭 필요한 옵션만 추가하자.


systemv가 권장하는 옵션은 아래 5가지이다.


DEFAULT_CHARSET

DEFAULT_COLLATION

ENABLED_LOCAL_INFILE

CMAKE_INSTALL_PREFIX

MYSQL_DATADIR


위에 두가지는 기본 언어셋 관련 설정이고 3번째는 로컬파일로 대량데이터 인서트시 유용하다.


4번째,5번째는 설치될 기본경로와 데이터파일의 경로를 지정한것이다.



그래서 결국 완성된 옵션은..


cmake \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DENABLED_LOCAL_INFILE=1 \

-DCMAKE_INSTALL_PREFIX=/app/mariadb \

-DMYSQL_DATADIR=/app/mariadb/data



아래와 같이 configure가 이상없이 끝난것을 확인 할 수 있다.


-- Looking for include file security/pam_appl.h - not found

-- Looking for strndup

-- Looking for strndup - found

-- Looking for event.h

-- Looking for event.h - not found

-- Configuring done

-- Generating done

-- Build files have been written to: /root/mariadb-10.1.13

[root@localhost mariadb-10.1.13]# 


configure에서 별 문제가 없었다면 make, make install 을 실행해 설치를 마친다.



2.2 make


make 시에 -j 옵션을 쓸수 있는데 자세한 내용은 리눅스 컴파일 속도 향상시키기 make -j  를 참고하자.


make


...

......

Scanning dependencies of target udf_example

[100%] Building C object sql/CMakeFiles/udf_example.dir/udf_example.c.o

Linking C shared module udf_example.so

[100%] Built target udf_example

Scanning dependencies of target my_safe_process

[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o

Linking CXX executable my_safe_process

[100%] Built target my_safe_process

[root@localhost mariadb-10.1.13]# 



2.3 make install


make install


...

.....

-- Installing: /app/mariadb/support-files/policy/apparmor

-- Installing: /app/mariadb/support-files/policy/apparmor/usr.sbin.mysqld.local

-- Installing: /app/mariadb/support-files/policy/apparmor/README

-- Installing: /app/mariadb/support-files/policy/apparmor/usr.sbin.mysqld

-- Installing: /app/mariadb/share/pkgconfig/mariadb.pc

-- Installing: /app/mariadb/share/aclocal/mysql.m4

-- Installing: /app/mariadb/support-files/mysql.server

[root@localhost mariadb-10.1.13]# 



3. 추가작업


소소한 추가작업 몇가지만 더 해준다.


3.1 사용자추가


useradd -M -s /sbin/nologin mysql


-M 은 /home/mysql 등의 홈데렉토리를 만들지 않겠다는 것이며


-s 는 로그인쉘을 지정할수 있다. mysql 계정은 데몬 실행시에 필요한 권한이지 쉘권한은 필요없기때문에 nologin을 줬다.

(사실 패스워드 지정을 안하면 로그인은 어차피 안된다.)



3.2 my.cnf


원하는 기능들은 추후에 얼마든지 my.cnf를 수정해 사용할수 있지만 


데이터 경로나 innodb 관련 파일등의 셋팅을 위해서라도 my.cnf를 먼저 구성해두면 좋다.


my.cnf 설정에 대한 자세한 내용 나중에 다시 정리하도록 하겠다.



3.3 mysql_install_db


mariadb 최소 실행에 필요한 기초 데이터베이스와 사용자등을 생성해준다.


mysql_install_db 는 설치경로(/app/mariadb)안에 scripts 디렉토리에 있다.


하지만 


~# /app/mariadb/scripts/mysql_install_db 


혹은


~# cd /app/mariadb/scripts ; ./mysql_install_db 


이런 식으로 실행하면 안된다. 스크립트 안에 참조하는 경로들이 이미 선언되어 있기 때문에


반드시 설치디렉토리(/app/mariadb)에서 실행해야 한다.


cd /app/mariadb


./scripts/mysql_install_db


...

.....


2016-04-27 23:41:17 139804154201888 [Note] InnoDB: Waiting for purge to start

2016-04-27 23:41:18 139804154201888 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.28-76.1 started; log sequence number 1616809

2016-04-27 23:41:18 139803347433216 [Note] InnoDB: Dumping buffer pool(s) not yet started

OK


To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system


PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:


'./bin/mysqladmin' -u root password 'new-password'

'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'


Alternatively you can run:

'./bin/mysql_secure_installation'


which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.


See the MariaDB Knowledgebase at http://mariadb.com/kb or the

MySQL manual for more instructions.


You can start the MariaDB daemon with:

cd '.' ; ./bin/mysqld_safe --datadir='./data'


You can test the MariaDB daemon with mysql-test-run.pl

cd './mysql-test' ; perl mysql-test-run.pl


Please report any problems at http://mariadb.org/jira


The latest information about MariaDB is available at http://mariadb.org/.

You can find additional information about the MySQL part at:

http://dev.mysql.com

Support MariaDB development by buying support/new features from MariaDB

Corporation Ab. You can contact us about this at sales@mariadb.com.

Alternatively consider joining our community based development effort:

http://mariadb.com/kb/en/contributing-to-the-mariadb-project/


[root@localhost mariadb]#


중간쯤에... OK 보이는가? 잘된거다. 


혹시 모르니 data 디렉토리에 필요한 파일들이 잘 생성됐는지 확인해보면 된다.


[root@localhost mariadb]# ls -alh ./data/


total 109M

drwxr-xr-x.  5 root root 4.0K Apr 27 23:41 .

drwxr-xr-x. 12 root root 4.0K Apr 27 22:12 ..

-rw-rw----.  1 root root  16K Apr 27 23:41 aria_log.00000001

-rw-rw----.  1 root root   52 Apr 27 23:41 aria_log_control

-rw-rw----.  1 root root  12M Apr 27 23:41 ibdata1

-rw-rw----.  1 root root  48M Apr 27 23:41 ib_logfile0

-rw-rw----.  1 root root  48M Apr 27 23:41 ib_logfile1

drwx------.  2 root root 4.0K Apr 27 23:41 mysql

drwx------.  2 root root 4.0K Apr 27 23:41 performance_schema

drwxr-xr-x.  2 root root 4.0K Apr 27 22:11 test


이상이 없다면 data 디렉토리를 mysql 소유권으로 바꿔준다. 


chown mysql. ./data -R


-R 옵션은 지정한 디렉토리 뿐만 아니라 그안에 있는 모든 디렉토리와 파일등을 몽땅 바꿔주겠다는 의미다.



mariadb를 실행/종료할수 있는 방법은 다양하지만 제공되는 스크립트가 있으므로 가져다 쓰면 편하다.


cp -a support-files/mysql.server /etc/rc.d/init.d/mysqld



4. 실행


방금 위에서 가져다논 실행파일을 이용하면 된다.


실행 :


[root@localhost mariadb]# /etc/rc.d/init.d/mysqld start

Starting MySQL. SUCCESS! 


종료 :


[root@localhost mariadb]# /etc/rc.d/init.d/mysqld stop

Shutting down MySQL.. SUCCESS! 



5. 마무리


5.1 PATH


/app/mariadb/bin 에 mariadb 실행파일들이 모두 있기 때문에 얘를 PATH로 걸어주면


쉘에서 관리하기 편하다.  


echo "PATH=$PATH:/app/mariadb/bin" >> ~/.bash_profile



5.2 secure


/app/mariadb/bin/mysql_secure_installation 을 실행해 기본 보안설정을 할수 있다.



실행하면 아래처럼 먼저 현재 root 비밀번호를 물어보는데 우린 방금 설치를 마쳤기때문에 root 패스워드가 없으므로 그냥 엔터!


[root@localhost bin]# ./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

you haven't set the root password yet, the password will be blank,

so you should just press enter here.


Enter current password for root (enter for none): 



그러면 패스워드 지금 설정할꺼냐고 물어본다. 엔터! 치고 원하는 mariadb root 패스워드 두번 입력.


Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.


Set root password? [Y/n] 

New password: 

Re-enter new password: 



mysql_install_db 실행시 익명사용자가 생성되는데 아무짝에 쓸모 없다. 지울껀지 물어보면 지운다고 엔터!!


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]



root 를 로컬이 아닌 외부에서 접속할수 없게 하겠냐고 물어본다. 외부접속을 막을꺼면 엔터!!


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] 



역시 mysql_install_db 실행시 test 데이터베이스 생성하는데 아무짝에 쓸모 없으므로 엔터!!


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] 



마지막으로 여지껏 수정한 내용으로 권한 업데이트를 할꺼냐고 물어몬다. 당연히 엔터!!


Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.


Reload privilege tables now? [Y/n] 



깔끔하게 끝.


Cleaning up...


All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.


Thanks for using MariaDB!

[root@localhost bin]# 





to Top