서버 운영 관리 [ Tip ]

CentOS 7 - MySQL 5.7 소스설치

MySQL 은 데이타베이스의 한 종류로 많은 사용자를 가진 무료 RDBMS 입니다.

리눅스 DB 서버라고 하면 대부분 MySQL 이 설치되어있으며, 홈페이지의 회원정보, 결제정보, 게시물 내용 등을 저장하거나 ERP 데이타 수집 및 관리 목적으로도 사용되는 등 데이타 저장 및 조회를 위해 다양하게 활용이 됩니다.

Oracle 데이타베이스를 개발하는 썬마이크로시스템즈사에서 에서 MySQL을 인수하여 대대적인 버그 수정을 하고 퍼포먼스를 향상 시켜왔기 때문에 어느정도 안정적이라 볼 수 있으며 무엇보다 무료로 사용할 수 있기에 인기가 많습니다.

 

아래 설치과정은 CentOS7 환경에서 진행했습니다.

 

Mysql 설치


 

1. 필수 구성요소 설치

# yum install -y vim wget epel-release

# mkdir -p /usr/local/src/APM_Setup

# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

# yum update -y

# yum install -y libdb-devel enchant-devel libxslt libxslt-devel net-snmp-devel readline-devel readline aspell-devel unixODBC unixODBC-devel libicu-devel icu libicu libc-client libc-client-devel libc-client-2007f freetype-devel freetype* freetype libXpm libXpm-devel libpng-devel libpng* libvpx-devel libvpx libcurl libcurl-devel curl* curl-devel curl tcp_wrappers-devel libzip environment-modules uw-imap-utils uw-imap-devel uw-imap uw-imap-static pam-devel libldb-devel openldap-devel cyrus-sasl-devel bzip2-devel bzip2 bzip2-libs ncurses-devel ncurses mysql-devel libjpeg-devel libjpeg* libjpeg-devel openssl-devel openssl* openssl-libs libxml* libxml2 libxml2-devel libmcrypt libmcrypt-devel libmcrypt* mcrypt mhash* mhash mhash-devel libmhash libmhash-devel expat-devel expat expat* gmp* gmp gmp-devel krb5* krb5-devel db4 db4-devel wget make cmake libtool* pcre* gdbm* gdbm gdbm-devel libtiff* libtiff libtiff-devel flex zlib* zlib-devel zlib gd* gd gd-devel patch t1lib t1lib-devel readline libedit-devel libtidy libtidy-devel gcc* gcc gcc-c++ libtermcap-devel dialog sqlite-devel oniguruma oniguruma-devel libzip5 mod_ssl postgresql-devel lcov systemtap-sdt-devel mod_ldap elfutils-devel libwebp-devel libwebp git gzip libnghttp2-devel valgrind* mod_proxy* editline editline-devel patchelf systemd-devel ImageMagick-devel libzstd-devel libffi libffi-devel libraqm-devel libraqm libsodium libsodium-devel

 

imap 관련 64비트 32비트 라이브러리 설정

# ln -s /usr/lib64/libc-client.a /usr/lib/libc-client.a

# unlink /usr/include/db.h

# ln -s /usr/include/libdb4/db.h /usr/include/db.h

# ln -s /usr/include/sqlext.h /usr/local/include/sqlext.h

# ln -s /usr/lib64/libgdbm_compat.so /usr/local/lib64/libdbm.so

 

openldap 호환

# \cp -arpf /usr/lib64/libldap* /usr/lib/

# ln -sf /usr/lib64/libm.so /usr/lib/libm.so

# ln -sf /usr/lib64/libssl.so /usr/lib/libssl.so

 

libXpm 모듈 32비트 호환

# ln -s /usr/lib64/libXpm.so /usr/lib/

# ln -s /usr/lib64/libXpm.so.4 /usr/lib/

# ln -s /usr/lib64/libXpm.so.4.11.0 /usr/lib/

 

2. default 환경변수 설정

# echo " " >> /etc/profile

# echo "####default PATH#####" >> /etc/profile

# echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:" >> /etc/profile

# echo "#####################" >> /etc/profile 

 

3. MySQL 계정 추가

# groupadd -g 400 mysql

# useradd -u400 -g400 -d /usr/local/mysql -s /bin/false mysql 

* MySQL 설치 및 실행하기 위해서는 mysql 계정이 필요합니다.

 

4. MySQL 설치

# mkdir -p /usr/local/src/APM_Setup

# cd /usr/local/src/APM_Setup

# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.40.tar.gz

# tar zxvf mysql-5.7.40.tar.gz

# mkdir -p /usr/local/src/APM_Setup/mysql-5.7.40/build

# cd mysql-5.7.40/build

# cmake ../ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DSYSCONFDIR=/etc \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_TCP_PORT=3306 \
-DTMPDIR=/usr/local/mysql/tmp \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_ZLIB=system \
-DWITH_SSL=system \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/include/boost

# make -j쓰레드 갯수

# make install

※ 언어셋을 euckr로 설치를 원할 경우, -DDEFAULT_CHARSET=euckr -DDEFAULT_COLLATION=euckr_korean_ci로 변경해줍니다.

 

5. my.cnf 파일 설정

# mv /etc/my.cnf /etc/my.cnf_source_beforce

# echo "####### Tin light and shade

[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock

[mysqld]
#default-character-set = utf8
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/data
basedir = /usr/local/mysql
user = mysql
bind-address = 0.0.0.0
skip-external-locking

server-id=1
log-bin=mysql-bin

#skip-grant-tables

key_buffer_size = 384M
max_allowed_packet = 16M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
#myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M

#dns query
skip-name-resolve
#connection

max_connections = 1000
max_connect_errors = 1000
wait_timeout= 60

### Slow Query Options

#slow-queries
#slow_query_log = /usr/local/mysql/logs/slow-queries.log
#long_query_time = 3
#log-slow-queries = /usr/local/mysql/logs/mysql-slow-queries.log


### TimeStamp Options

explicit_defaults_for_timestamp
symbolic-links=0

### Log Options

#log-error = /usr/local/mysql/logs/mysqld.log
#pid-file = /usr/local/mysql/tmp/mysqld.pid

### Chracter Options

character-set-client-handshake = FALSE
init_connect = SET NAMES utf8
character-set-server = utf8
#collation-server = utf8_general_ci
symbolic-links=0


##Password Policy
#validate_password_policy=LOW
#validate_password_policy=MEDIUM

### MyISAM Spectific options
#default-storage-engine = myisam
key_buffer_size = 32M
bulk_insert_buffer_size = 64M

###MyISAM Spectific options

#myisam_sort_buffer_size = 128M
#myisam_max_sort_file_size = 10G
#myisam_repair_threads = 1

### INNODB Spectific options

default-storage-engine = InnoDB
#skip-innodb
#innodb_additional_mem_pool_size = 16M
#innodb_buffer_pool_size = 1024MB
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_write_io_threads = 8
#innodb_read_io_threads = 8
#innodb_thread_concurrency = 16
#innodb_flush_log_at_trx_commit = 1
#innodb_log_buffer_size = 8M
#innodb_log_file_size = 128M
#innodb_log_files_in_group = 3
#innodb_max_dirty_pages_pct = 90
#innodb_lock_wait_timeout = 120

[mysqldump]
default-character-set = utf8
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default-character-set = utf8

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M" > /etc/my.cnf

 

6. boost 설치

# cd /usr/local/include/boost/boost_1_59_0

# ./bootstrap.sh

# ./b2 install 

* MySQL 5.7 부터는 기하연산에 쓰이는 코드들이 들어있는 라이브러리를 사용합니다. 그렇기 때문에 설치를 해야합니다.

 

7. 데이터베이스 구성 및 권한 설정

# mkdir -p /usr/local/mysql/tmp

# mkdir -p /usr/local/mysql/logs

# chmod 711 /usr/local/mysql

# mkdir /usr/local/mysql/data

# chmod 700 /usr/local/mysql/data

# chmod 751 /usr/local/mysql/bin/

# chmod 750 /usr/local/mysql/bin/*

# chmod 755 /usr/local/mysql/bin/mysql

# chmod 755 /usr/local/mysql/bin/mysqldump

# chown -R mysql:mysql /usr/local/mysql/

 

 

8. MySQL 데이터 실행 초기화 생성

# /usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

* 여기서 --initialize-insecure 해당 옵션이 설치할때 mysql root 비밀번호를 임시 발급받는 패스워드로 설정하지 않겠다는 옵션입니다.

 

9. 자동 실행 설정 및 환경 변수 적용

# \cp -arpf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# chmod 700 /etc/init.d/mysqld

# chkconfig --add mysqld

# chkconfig --level 3 mysqld on

 

10. MySQL root 초기패스워드 설정

# /etc/init.d/mysqld restart

# /usr/local/mysql/bin/mysql -u root -e 'use mysql; update user set authentication_string=password("설정할 패스워드") where user="root"; flush privileges;'

 

11. 소스 설치한 MySQL 환경변수 설정

# echo " " >> /etc/profile

# echo "APACHE_HOME=/usr/local/apache" >> /etc/profile

# echo "MySQL_HOME=/usr/local/mysql" >> /etc/profile

# echo "PHP_HOME=/usr/local/php" >> /etc/profile

# echo " " >> /etc/profile

# echo "export PATH="\$"APACHE_HOME/bin:"\$"MySQL_HOME/bin:"\$"PHP_HOME/bin:"\$"PHP_HOME/sbin"\$"{PATH:+:"\$"{PATH}}" >> /etc/profile

# echo " " >> /etc/profile

# source /etc/profile

 

12. 데몬 구동 확인

# netstat -ntlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q   Local Address    Foreign Address  State          PID/Program name
tcp              0            0   0.0.0.0:3306      0.0.0.0:*            LISTEN      1758/mysqld