DB/MySQL

CentOS 7 MySQL 5.7.41 소스 컴파일 설치

서버엔지니어 2023. 3. 11.
728x90

## MySQL 설치전 선행 작업

cd /usr/local/src/
yum install -y wget vim epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update -y

## CentOS 7 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

## 소스설치를 위한 패키지 환경 설치

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

## CentOS 6 이하 관련 라이브러리 설정

mkdir /usr/kerberos
ln -s /usr/lib64 /usr/kerberos/lib

## PHP 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/innodb_flush_method
ln -s /usr/lib64/libXpm.so.4.11.0 /usr/lib/

## PHP 이미지모듈 64비트 32비트 라이브러리 호환설정

ln -s /usr/lib64/libjpeg.so /usr/lib
ln -s /usr/lib64/libpng.so /usr/lib

## MySQL 계정 생성

groupadd -g 400 mysql
useradd -u400 -g400 -d /usr/local/mysql -s /bin/false mysql

## MySQL 다운로드 및 배포

mkdir /usr/local/src/APM_Setup
cd /usr/local/src/APM_Setup
wget https://fossies.org/linux/misc/mysql-5.7.41.tar.gz
또는
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.41.tar.gz
tar zxvf mysql-5.7.41.tar.gz
mkdir /usr/local/src/APM_Setup/mysql-5.7.41/build
cd /usr/local/src/APM_Setup/mysql-5.7.41/build

 

## MySQL 컴파일 설정 및 설치

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 \
-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

 

## MySQL 시작 스크립트 생성

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

## MySQL 설정파일 생성

\mv -f /etc/my.cnf /etc/my.cnf_source_before

 

## MySQL logrotate 설정

mkdir /root/bin
cp-arp ./support-files/mysql-log-rotate /root/bin/

echo " " >> /etc/crontab

echo "0 0 * * * root /root/bin/mysql-log-rotate" >> /etc/crontab

 

## MySQL 설정파일 설정

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

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

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

key_buffer_size = 384M
max_allowed_packet = 1M
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 = 10000
max_connect_errors = 10000
wait_timeout= 60

### Slow Query Options
slow-query_log = 1
slow_query_log_file = /usr/local/mysql/logs/slow-query_log
long_query_time = 5

### TimeStamp Options
explicit_defaults_for_timestamp
symbolic-links=0

### Log Options
log-error = /usr/local/mysql/logs/mysqld.log

### 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
server-id = 1
log-bin = mysql-bin
default-storage-engine = InnoDB
max_binlog_size = 256M
expire_logs_days = 7

## Per-Thread Buffers * (max_connections) = total per-thread mem usage
#default: 32bit: 192K, 64bit: 256K
thread_stack = 256K
# sort_buffer_size default: 2M, larger may cause perf issues
sort_buffer_size = 1M
# read_buffer_size default: 128K, change in increments of 4K
read_buffer_size = 1M
# read_rnd_buffer_size default: 256K
read_rnd_buffer_size = 1M
# join_buffer_size default: 128K
join_buffer_size = 1M
# binlog_cache_size default: 32K, size of buffer to hold TX queries
binlog_cache_size = 64K

## Query Cache
# query_cache_size global buffer
query_cache_size = 32M
# query_cache_limit max query result size to put in cache
query_cache_limit = 512K

## Connections
#multiplier for memory usage via per-thread buffers
max_connections = 5000
# max_connect_errors default: 10
max_connect_errors = 100
# concurrent_insert default: 1, 2: enable insert for all instances
concurrent_insert = 2
# connect_timeout default -5.1.22: 5, +5.1.22: 10
connect_timeout = 30

## Table and TMP settings
# max_heap_table_size recommend same size as tmp_table_size
max_heap_table_size = 1G
# bulk_insert_buffer_size recommend same size as tmp_table_size
bulk_insert_buffer_size = 1G
# tmp_table_size recommend 1G min
tmp_table_size = 1G    

# set tmpdir to a ramdisk?
### tmpdir = /data/mysql-tmp0:/data/mysql-tmp1

## Thread settings
# thread_concurrency recommend 2x CPU cores [0 create as many as needed]
# thread_concurrency = 0
# thread_cache_size recommend 5% of max_connections
thread_cache_size = 100

## MyISAM Engine  
# myisam_sort_buffer_size  index buffer size for creating/altering indexes
myisam_sort_buffer_size = 128M
# myisam_max_sort_file_size max file size for tmp table when creating/alering indexes
myisam_max_sort_file_size = 256M  

## InnoDB IO settings -  5.5.x and greater
innodb_write_io_threads = 16
innodb_read_io_threads = 16

## InnoDB Plugin Independent Settings
# innodb_file_per_table enable always
innodb_file_per_table
# innodb_data_file_path ibdata1:128M;ibdata2:10M:autoextend
# innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend
# innodb_buffer_pool_size global buffer, server 16GB 50%
innodb_buffer_pool_size = 8G
# innodb_flush_log_at_trx_commi 2/0 = perf, 1 = ACID
innodb_flush_log_at_trx_commit = 0
innodb_log_file_size = 256M
# global buffer
innodb_log_buffer_size = 128M
innodb_lock_wait_timeout = 300
skip-innodb-doublewrite
sync_binlog = 0

[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

## DB 디렉토리 생성 및 퍼미션 소유 설정

mkdir -p /usr/local/mysql/tmp

mkdir -p /usr/local/mysql/logs
chown -R mysql:mysql /usr/local/mysql
chmod 700 /etc/init.d/mysqld
chmod 711 /usr/local/mysql
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
ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib64

## boost 설치

cd /usr/local/include/boost/boost_1_59_0
./bootstrap.sh
./b2 install

## DB 초기화

/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf  --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

## MySQL 비밀번호 설정

/etc/init.d/mysqld restart
/usr/local/mysql/bin/mysqladmin -u root password "설정할 비밀번호"

## MySQL logrotate 설정

mkdir /root/bin
\cp -arpf ./support-files/mysql-log-rotate /root/bin/
echo " " >> /etc/crontab

echo "0 0 * * * root /usr/sbin/logrotate -f /root/bin/mysql-log-rotate" >> /etc/crontab

 

## MySQL 환경변수 설정

아래 설정은 Apache, MySQL, PHP 부분이 모두 포함되어있습니다.
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
source /etc/profile

만약 DB만 운영하실것이라면 위의 명령어가 아닌 아래 명령어를 입력해주세요.
echo " " >> /etc/profile
echo "MySQL_HOME=/usr/local/mysql" >> /etc/profile
echo "export PATH="\$"MySQL_HOME/bin:"\$"{PATH:+:"\$"{PATH}}" >> /etc/profile
echo " " >> /etc/profile
source /etc/profile

 

댓글