Compile and install MariaDB-10.1.30

Posted by geus on Tue, 05 May 2020 08:37:43 +0200

Environment related:
OS: CentOS release 6.9
IP: 192.168.1.10
CPU: 4 cores
MEM: 2G
DISK: 50G

1. Experiment host clone

Refer to "CentOS6 experimental machine template building and deployment"
Clone an experimental machine, adjust the memory to 2G and the CPU to 4 cores, and further configure the host name and hosts file:

hostname mariadb
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ifconfig eth0|grep inet|awk -F'[ :]' '{print $13}') $(hostname)">>/etc/hosts
sed -i "s/^HOSTNAME.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network
ping -c 3 $(hostname)

2. Environmental preparation

Delete the pre installed apache and mysql, and install the system support package required for compilation:

for i in $(rpm -qa|grep -Ei 'http|mysql'|grep -v 'mysql-libs');do yum remove $i;done
# If MySQL LIBS is uninstalled, crontab will be uninstalled. However, the package itself does not affect the compilation and installation of MariaDB, so it will not be processed.
yum -y install gcc gcc-c++ cmake ncurses-devel \
       bison libxml2-devel boost libevent boost-devel \
       Judy Judy-devel openssl-devel
yum -y install libevent-devel
# If you use the system to install the local yum source configured by centos-6.x-x86_-bin-dvd1.iso
# Then the package libevent devel is on the DVD 2. You need to uninstall the DVD1, mount the DVD2 installation, install and then switch back to the DVD1
# If the network yum source is configured, there is no problem
# The document "CentOS6 experimental machine template building deployment" has the yum source for deploying Alibaba cloud

2. Compile and install

Package download: https://downloads.mariadb.org/mariadb/+releases/
If you need to compile and install version 10.2 and later, you need to test, and you may need to compile and install other component support of higher version.

Add users, delete the configuration files that come with the system preinstallation, and compile and install:

groupadd mariadb
useradd -s /sbin/nologin -M -g mariadb mariadb
# The parameter - s specifies the login shell of the user, / sbin/nologin indicates that the user cannot log in
# Parameter - M indicates that the user's home directory will not be created
rm -f /etc/my.cnf
# Because mysql related packages are pre installed in the system, there are pre installed configuration files. Delete them
cd /tmp
tar -xf /tmp/mariadb-10.1.30.tar.gz
cd /tmp/mariadb-10.1.30
# Unzip, enter the directory and start compiling and installing
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DSYSCONFDIR=/etc \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1
# Specify the installation directory, configuration file directory, compilation and installation engine, set the default character set, readline, ssl, zlib, etc
make -j 4 && make install
# The experimental machine is 4-core, so adjust the parameter to - j 4 to speed up compilation
# As for whether the - j parameter is the number of CPU cores or the number of CPU cores + 1, no discussion will be made
# The compilation and installation process will be long, depending on the disk performance and the number of CPU s of the virtual machine
cd /usr/local/mariadb/bin
./mysql --version
# View the version and verify that the compilation and installation are successful

3. Configure my.cnf file

port=3306
# Set the service port to 3306, or other ports
cat > /etc/my.cnf << EOF
[mysqld_safe]
pid-file=/usr/local/mariadb/run/mysqld.pid
[mysql]
port=$port
prompt=\\\u@\\\d \\\r:\\\m:\\\s>
default-character-set=utf8
[client]
port=$port
socket=/usr/local/mariadb/run/mysql.sock
[mysqld]
#######dir#######
basedir=/usr/local/mariadb
datadir=/usr/local/mariadb/data
tmpdir=/usr/local/mariadb/tmp
lc_messages_dir=/usr/local/mariadb/share
log-error=/usr/local/mariadb/log/alert.log
slow_query_log_file=/usr/local/mariadb/log/slow.log
socket=/usr/local/mariadb/run/mysql.sock
#######innodb#######
innodb_data_home_dir=/usr/local/mariadb/data
innodb_log_group_home_dir=/usr/local/mariadb/log/iblog
innodb_buffer_pool_size=1680M
#Set InnoDB buffer pool size to 80% of server memory
#This setting cannot have decimal point, 1.5G is wrong, use 1500M or 1G
innodb_log_files_in_group=4
innodb_log_file_size=500M
innodb_log_buffer_size=256M
innodb_flush_log_at_trx_commit=2
innodb_io_capacity=10000
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_file_per_table=1
innodb_flush_method=O_DIRECT
innodb_page_size=8k
transaction-isolation=READ-COMMITTED
#######replication#######
master-info-file=/usr/local/mariadb/log/master.info
relay-log=/usr/local/mariadb/log/relaylog
relay_log_info_file=/usr/local/mariadb/log/relay-log.info
skip-slave-start
#######binlog#######
log-bin=/usr/local/mariadb/log/binlog
server_id=383306
binlog_cache_size=32K
max_binlog_cache_size=600M
max_binlog_size=500M
binlog-format=ROW
sync_binlog=0
log-slave-updates
expire_logs_days=7
#######MyISAM Specific options#######
key_buffer_size = 8M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
#######not innodb options (fixed)#######
back_log = 50
max_connections = 400
table_cache = 2048
max_allowed_packet = 16M
max_heap_table_size = 64M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 400
query_cache_size = 0
query_cache_type = 0
tmp_table_size = 64M
gdb
#######Maria-5.5
thread_handling=pool-of-threads
thread_pool_size=16
#######server
default-storage-engine=INNODB
lower_case_table_names=1
performance_schema=0
long_query_time=1
slow_query_log=1
port=$port
skip-name-resolve
skip-ssl
max_user_connections=8000
max_connect_errors=65535
EOF
# The relevant parameters of the configuration file will not be explained in detail any more. You can query the official website for confirmation and further configuration

4. Add system library file directory and set environment variables

cat > /etc/ld.so.conf.d/mariadb.conf<<EOF
/usr/local/mariadb/lib
/usr/local/lib
EOF
/sbin/ldconfig -v
# After the software is compiled and installed, the directory where the compiled lib is located is generally not in the default lib directory of the system. Add the directory to prevent problems
echo 'export PATH=$PATH:/usr/local/mariadb/bin'>>/root/.bash_profile 
export PATH=$PATH:/usr/local/mariadb/bin
# Set the environment variable of root to load the bin directory generated by compilation into the default PATH
mysql --version
# test

5. Create directory and initialize Library

To create a directory, if it is a production machine, you need to mount the corresponding storage device on the created directory to ensure data security

mkdir -v  /usr/local/mariadb/data
mkdir -pv /usr/local/mariadb/log/iblog
mkdir -v  /usr/local/mariadb/run
mkdir -v  /usr/local/mariadb/tmp
# One command is done: mkdir -pv /usr/local/mariadb/{data,log/iblog,run,tmp}
chown -R mariadb: /usr/local/mariadb
# Pay attention to the authority!!!

Building database

/usr/local/mariadb/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mariadb \
--datadir=/usr/local/mariadb/data \
--user=mariadb
# Create a database, specify the main directory and data directory of the configuration file and database, and the OS system user to which the database belongs
/usr/local/mariadb/bin/mysqld_safe --user=mariadb &
# Try to start, test
netstat -tupln|grep 3306
echo 'show databases;'|mysql
# Test port and default library
mysqladmin shutdown
# Guan Chu

6. Set startup and initialize root password

echo '/usr/local/mariadb/bin/mysqld_safe --user=mariadb &'>>/etc/rc.local
reboot
# You can start the test after the last restart
PASS=vincent
# Temporarily set the root password to vincent
/usr/local/mariadb/bin/mysqladmin -u root password "$PASS"
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' \
    IDENTIFIED BY '$PASS' WITH GRANT OPTION;"|\
    mysql -uroot -p"$PASS" -Dmysql
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' \
    IDENTIFIED BY '$PASS' WITH GRANT OPTION;"|\
    mysql -uroot -p"$PASS" -Dmysql
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' \
    IDENTIFIED BY '$PASS' WITH GRANT OPTION;"|\
    mysql -uroot -p"$PASS" -Dmysql
echo "update user set password=password('$PASS') where user='root';"|\
    mysql -uroot -p"$PASS" -Dmysql
# Set the root password for localhost and 127 and other IP linked to the library
echo "delete from user where not (user='root') ;"|\
    mysql -uroot -p"$PASS" -Dmysql
# Delete non root users
echo "delete from user where user='root' and password=''; "|\
    mysql -uroot -p"$PASS" -Dmysql
# Delete the permission record with blank root password
echo "drop database test;"| mysql -uroot -p"$PASS" -Dmysql
# Delete the default test library and optimize the items
echo "DROP USER ''@'%';"| mysql -uroot -p"$PASS" -Dmysql
# Delete the blank password login permission
echo "flush privileges;"| mysql -uroot -p"$PASS" -Dmysql
# Refresh the permission table and make the configuration effective

[TOC]

Topics: MariaDB MySQL yum Database