DB/MariaDB

CentOS 7 MariaDB 10.1.48 소스 컴파일 설치

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

## MariaDB 설치전 선행 작업

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

 

## MariaDB 추가 패키지 설치

yum install -y libtermcap-devel gdbm-devel zlib* libxml* freetype* libpng* libjpeg* iconv flex gmp ncurses-devel make gcc* cmake expat* bzip2 openssl-* lz4* msgpack* libxml2* java-1.8.0* zeromq zeromq-devel jemalloc* boost boost-devel bzip2-devel zstd snappy snappy-devel Judy Judy-devel libzstd* perl-Judy bison bison* libcurl* curl* git

 

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

## MariaDB 계정 생성

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

 

## MariaDB 다운로드 및 배포

구글링에서 mariadb-10.1.48.tar.gz 검색어로 검색해서 무료로 제공하는 웹FTP 사이트에서 오른쪽 마우스 클릭해서  "링크 주소 복사" 터미널에 붙여넣기 하시길 바랍니다.

 

mkdir /usr/local/src/APM_Setup
cd /usr/local/src/APM_Setup
wget https://archive.mariadb.org/mariadb-10.1.48/source/mariadb-10.1.48.tar.gz
wget https://mirror.sobukus.de/files/src/mariadb/mariadb-10.1.48.tar.gz
wget https://www.mirrorservice.org/sites/distfiles.macports.org/mariadb-10.1/mariadb-10.1.48.tar.gz
wget https://distfiles.macports.org/mariadb-10.1/mariadb-10.1.48.tar.gz
tar zxvf mariadb-10.1.48.tar.gz
mkdir /usr/local/src/APM_Setup/mariadb-10.1.48/build
cd /usr/local/src/APM_Setup/mariadb-10.1.48/build

## MariaDB 컴파일 설정 및 설치

cmake ../ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DINSTALL_SYSCONFDIR=/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_FEDERATEDX_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_CONNECT_STORAGE_ENGINE=1 \
-DWITH_SEQUENCE_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_LOCALES=1 \
-DWITH_ZLIB=auto \
-DWITH_READLINE=1 \
-DWITH_PCRE=auto \
-DWITH_SSL=system
make -j && make install

## MariaDB 시작 스크립트 생성

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

## MariaDB 설정파일 생성

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

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

## MariaDB 설정파일 설정

\cp -arpf ./support-files/my-innodb-heavy-4G.cnf /etc/my.cnf

## MariaDB 기본 엔진 변경

# default-storage-engine = MYISAM
-> 주석처리

default-storage-engine = InnoDB
-> 추가

 

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

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
echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
rm -rf /usr/local/mysql/bin/rcmysql
rm -rf /etc/init.d/mysql
ln -s /etc/init.d/mysqld /usr/local/mysql/bin/rcmysql

## DB 초기화

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
chown mysql:mysql -R /usr/local/mysql/data

## MariaDB 비밀번호 설정

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

## MariaDB 환경변수 설정

아래 설정은 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

댓글