Last active
October 16, 2019 04:15
-
-
Save kenshin17/67343789f1b0bf9f6372bd574ee73034 to your computer and use it in GitHub Desktop.
compile-mariadb-10.3-ubuntu16-04.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# File : compile-mariadb-10.3.sh | |
# OS : Ubuntu 16.04.6 LTS | |
# LastUpdate : 16:55 2019.10.08 | |
# Description : Compile MariaDB Server StandAlone / MariaDB Galera Cluster 10.3 | |
########################################### | |
MARIADB_VERSION=10.3.18 | |
MARIADB_HOME=/mariadb | |
DATA_DIR=$MARIADB_HOME/data | |
CONFIG_DIR=$MARIADB_HOME/etc | |
CONFIG_FILE=$MARIADB_HOME/my.cnf | |
LOG_DIR=/opt/log/mysql | |
SETUP_DIR=/opt/setup/ | |
MARIADB_SETUP_DIR=/opt/setup/mariadb-$MARIADB_VERSION | |
wsrep_node_address="$1" | |
# wsrep_node_name="galera-db-01" | |
wsrep_node_name="$2" | |
wsrep_cluster_address="gcomm://" | |
# wsrep_cluster_address="gcomm://192.168.100.145,192.168.100.154" | |
### Check argv | |
if [ $# -eq 0 ] | |
then | |
echo "Usage: $0 192.168.100.154 galera-db-02" | |
exit 1 | |
fi | |
# Executing add-apt-repository MariaDB 10.3 | |
echo -e "\n########## Executing add-apt-repository MariaDB 10.3 ##########" | |
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash | |
/bin/rm -rf /etc/apt/sources.list.d/mariadb.list.* | |
echo '# MariaDB 10.3 repository list - created 2019-01-27 09:50 UTC' > /etc/apt/sources.list.d/mariadb.list | |
echo '# http://downloads.mariadb.org/mariadb/repositories/' > /etc/apt/sources.list.d/mariadb.list | |
echo 'deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main' > /etc/apt/sources.list.d/mariadb.list | |
echo 'deb-src http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main' > /etc/apt/sources.list.d/mariadb.list | |
# Update the package cache | |
echo -e "\n########## Update the package cache ##########" | |
sudo /usr/bin/apt-get update | |
echo -e "\n########## Install requiment package ##########" | |
# RPM-based: | |
# yum-builddep MariaDB-server | |
# Debian-based: | |
/usr/bin/apt-get build-dep mariadb-server | |
/usr/bin/apt-get install -y pkg-config gnutls-dev | |
# for Galera: | |
/usr/bin/apt-get install -y scons check cmake libncurses5-dev | |
# Source: https://mariadb.com/kb/en/library/installing-mariadb-deb-files/ | |
# echo -e "\n########## Git clone source code mariadb-$MARIADB_VERSION ##########" | |
# cd $SETUP_DIR | |
# # rm -rf $SETUP_DIR/mariadb-$MARIADB_VERSION | |
# git clone https://github.com/mariadb/server mariadb-$MARIADB_VERSION | |
# cd mariadb-$MARIADB_VERSION | |
# git checkout 10.3 | |
echo -e "\n########## Setup param and environment mariadb-$MARIADB_VERSION ##########" | |
# Setup param and environment. | |
cd $MARIADB_SETUP_DIR/BUILD | |
cmake .. \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DWITH_WSREP=ON \ | |
-DWITH_INNODB_DISALLOW_WRITES=ON \ | |
-DWITH_READLINE=1 \ | |
-DWITH_SSL=bundled \ | |
-DWITH_ZLIB=system \ | |
-DDEFAULT_CHARSET=utf8 \ | |
-DDEFAULT_COLLATION=utf8_general_ci \ | |
-DWITH_EXTRA_CHARSETS=all \ | |
-DENABLED_LOCAL_INFILE=1 \ | |
-DWITH_EXTRA_CHARSETS=all \ | |
-DWITH_ARIA_STORAGE_ENGINE=1 \ | |
-DWITH_XTRADB_STORAGE_ENGINE=1 \ | |
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ | |
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ | |
-DWITH_PARTITION_STORAGE_ENGINE=1 \ | |
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ | |
-DWITH_FEDERATEDX_STORAGE_ENGINE=1 \ | |
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ | |
-DWITH_XTRADB_STORAGE_ENGINE=1 \ | |
-DWITH_EMBEDDED_SERVER=ON \ | |
-DTOKUDB_OK=0 \ | |
-DCMAKE_INSTALL_PREFIX=$MARIADB_HOME \ | |
-DMYSQL_DATADIR=$DATA_DIR \ | |
-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock \ | |
-DWITH_WSREP=ON \ | |
-DWITH_INNODB_DISALLOW_WRITES=ON | |
# Compile | |
make | |
make install | |
echo -e "\n########## Add user MySQL ##########" | |
groupadd -g 118 -o -r mysql | |
useradd -M -g mysql -o -r -d $DATA_DIR -s /bin/false -c "MariaDB" -u 118 mysql | |
echo -e "\n########## Symlink lib64 ##########" | |
cd $MARIADB_HOME | |
#Create lib64 | |
ln -s lib lib64 | |
echo -e "\n########## MKdir Log folder ##########" | |
mkdir -p $LOG_DIR | |
chown -R mysql:mysql $LOG_DIR | |
# Building the wsrep Provider | |
echo -e "\n########## Building the wsrep Provider ##########" | |
apt-get install libboost-all-dev libboost-program-options-dev -y | |
# The Galera Replication Plugin both implements the wsrep API and operates as the database server's wsrep Provider. To build, cd into the galera/ directory and do: | |
# ################## 1 or ################## | |
cd $SETUP_DIR | |
rm -rf galera | |
git clone https://github.com/codership/galera.git | |
cd galera | |
git submodule init | |
git submodule update | |
./scripts/build.sh | |
cp libgalera_smm.so $MARIADB_HOME/lib64 | |
# Source: https://mariadb.com/kb/en/library/installing-galera-from-source/ | |
# ################## 2 or ################## | |
# git clone https://github.com/codership/galera.git | |
# cd galera | |
# scons | |
# pkg install galera | |
# Source: https://galeracluster.com/library/documentation/install-mariadb-src.html | |
echo -e "\n########## Configuare file $CONFIG_FILE ##########" | |
cd $MARIADB_HOME/support-files | |
mkdir -p $MARIADB_HOME/etc | |
# cp my-huge.cnf $CONFIG_FILE | |
# sed -i 's/#innodb_log_file_size=100M/innodb_log_file_size=100/g' $CONFIG_FILE | |
# sed -i 's/#innodb_log_buffer_size = 8M/innodb_log_buffer_size=8M/g' $CONFIG_FILE | |
# sed -i 's/#innodb_flush_log_at_trx_commit = 1/innodb_flush_log_at_trx_commit=1/g' $CONFIG_FILE | |
# sed -i 's/#innodb_lock_wait_timeout = 50/innodb_lock_wait_timeout=60/g' $CONFIG_FILE | |
# sed -i '/innodb_lock_wait_timeout=60/ a innodb_file_per_table=1' $CONFIG_FILE | |
# sed -i '/query_cache_size = 32M/ a max_connect_errors=100000000' $CONFIG_FILE | |
# sed -i '/query_cache_size = 32M/ a wait_timeout=60' $CONFIG_FILE | |
# sed -i "|^log-bin=mysql-bin|log-bin=$LOG_DIR/mariadb-bin" $CONFIG_FILE | |
# sed -i "|^log-bin=mysql-bin| a log_error=$LOG_DIR/mysql_error.log" $CONFIG_FILE | |
# #sed -i '/^log-bin=mysql-bin/ a log_error=/var/log/mysql/mysql_error.log' $CONFIG_FILE | |
# sed -i "|^log-bin=mysql-bin| a general_log_file = $LOG_DIR/mysql.log" $CONFIG_FILE | |
# sed -i '/^log-bin=mysql-bin/ a general_log = 1' $CONFIG_FILE | |
cat <<EOF > $CONFIG_FILE | |
# Example mysql config file for very large systems. | |
# | |
# This is for large system with memory of 1G-2G where the system runs mainly | |
# MySQL. | |
# | |
# You can copy this file to | |
# /etc/my.cnf to set global options, | |
# mysql-data-dir/my.cnf to set server-specific options (in this | |
# installation this directory is /var/lib/mysql) or | |
# ~/.my.cnf to set user-specific options. | |
# | |
# One can in this file use all long options that the program supports. | |
# If you want to know which options a program support, run the program | |
# with --help option. | |
# The following options will be passed to all MySQL clients | |
[mysqld] | |
bind-address = 0.0.0.0 | |
default_storage_engine = InnoDB | |
binlog_format = row | |
innodb_autoinc_lock_mode= 2 | |
log-bin = mysql-bin | |
server-id = 1 | |
skip-external-locking | |
max_binlog_size = 256M #max size for binlog before rolling | |
expire_logs_days = 1 #binlog files older than this will be purged | |
## Per-Thread Buffers * (max_connections) = total per-thread mem usage | |
key_buffer_size = 384M | |
max_allowed_packet = 1M | |
table_open_cache = 512 | |
thread_stack = 256K #default: 32bit: 192K, 64bit: 256K | |
sort_buffer_size = 1M #default: 2M, larger may cause perf issues | |
read_buffer_size = 2M #default: 128K, change in increments of 4K | |
read_rnd_buffer_size = 8M #default: 256K | |
join_buffer_size = 1M #default: 128K | |
binlog_cache_size = 64K #default: 32K, size of buffer to hold TX queries | |
## Query Cache | |
query_cache_size = 32M #global buffer | |
query_cache_limit = 512K #max query result size to put in cache | |
## Connections | |
max_connections = 2000 #multiplier for memory usage via per-thread buffers | |
max_connect_errors = 100 #default: 10 | |
concurrent_insert = 2 #default: 1, 2: enable insert for all instances | |
connect_timeout = 30 #default -5.1.22: 5, +5.1.22: 10 | |
## Table and TMP settings | |
max_heap_table_size = 1G #recommend same size as tmp_table_size | |
bulk_insert_buffer_size = 1G #recommend same size as tmp_table_size | |
tmp_table_size = 1G #recommend 1G min | |
# set tmpdir to a ramdisk? | |
#tmpdir = /data/mysql-tmp0:/data/mysql-tmp1 | |
## Thread settings | |
thread_concurrency = 16 #recommend 2x CPU cores [0 create as many as needed] | |
thread_cache_size = 100 #recommend 5% of max_connections | |
## MyISAM Engine | |
key_buffer = 1M #global buffer | |
myisam_sort_buffer_size = 128M #index buffer size for creating/altering indexes | |
myisam_max_sort_file_size = 256M #max file size for tmp table when creating/alering indexes | |
## 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_data_file_path = ibdata1:128M;ibdata2:10M:autoextend | |
innodb_buffer_pool_size = 12G #global buffer | |
# innodb_additional_mem_pool_size = 4M #global buffer | |
innodb_flush_log_at_trx_commit = 0 #2/0 = perf, 1 = ACID | |
innodb_log_file_size = 256M | |
innodb_log_buffer_size = 128M #global buffer | |
innodb_lock_wait_timeout = 300 | |
innodb_thread_concurrency = 16 #recommend 2x core quantity | |
innodb_commit_concurrency = 16 #recommend 4x num disks | |
innodb_flush_method = O_DSYNC #O_DIRECT = local/DAS, O_DSYNC = SAN/iSCSI | |
# innodb_support_xa = 0 #recommend 0, disable xa to negate extra disk flush | |
skip-innodb-doublewrite | |
sync_binlog = 0 | |
# Galera cluster configuration | |
wsrep_on = ON | |
wsrep_provider = /mariadb/lib64/libgalera_smm.so | |
wsrep_cluster_address = "$wsrep_cluster_address" | |
wsrep_cluster_name = "mariadb-galera-cluster" | |
wsrep_sst_method=rsync | |
# Cluster node configuration | |
wsrep_node_address = "$wsrep_node_address" | |
wsrep_node_name = "$wsrep_node_name" | |
wsrep_slave_threads = 16 | |
#gcs.fc_limit = wsrep_slave_threads * 5 | |
#gcs.fc_limit = wsrep_slave_threads * 5 | |
#gcs.fc_factor = 0.8 | |
# [mysqld] | |
# bind-address=0.0.0.0 | |
# default_storage_engine=InnoDB | |
# binlog_format=row | |
# innodb_autoinc_lock_mode=2 | |
# # Galera cluster configuration | |
# wsrep_on=ON | |
# wsrep_provider = /mariadb/lib64/libgalera_smm.so | |
# #wsrep_cluster_address = "gcomm://192.168.100.145,192.168.100.154" | |
# wsrep_cluster_address = "$wsrep_cluster_address" | |
# wsrep_cluster_name = "mariadb-galera-cluster" | |
# wsrep_sst_method = rsync | |
# # Cluster node configuration | |
# wsrep_node_address = "$wsrep_node_address" | |
# wsrep_node_name = "$wsrep_node_name" | |
EOF | |
chown -R mysql:mysql $MARIADB_HOME | |
chown -R mysql:mysql $DATA_DIR | |
echo -e "\n########## Init datadir $DATA_DIR ##########" | |
cd $MARIADB_HOME | |
scripts/mysql_install_db --basedir=$MARIADB_HOME --datadir=$DATA_DIR --defaults-file=$CONFIG_FILE --user=mysql | |
echo -e "\n########## Init.d script ##########" | |
cp $MARIADB_HOME/support-files/mysql.server /etc/init.d/mysqld | |
chmod +x /etc/init.d/mysqld | |
/bin/systemctl daemon-reload | |
echo $MARIADB_HOME/lib > /etc/ld.so.conf.d/mysql.conf | |
update-rc.d mysqld defaults | |
update-rc.d mysqld enable | |
#update-rc.d -f <service> remove | |
ln -s /mariadb/bin/mysql /usr/local/bin/mysql | |
ln -s /mariadb/bin/mysqladmin /usr/local/bin/mysqladmin | |
ln -s /mariadb/bin/mysqldump /usr/local/bin/mysqldump | |
#Restart MySQL | |
#/etc/init.d/mysqld restart | |
#/mariadb/bin/mysqladmin -u root password 'abc@123' | |
#/mariadb/bin/mysql_secure_installation | |
#/etc/init.d/mysqld stop | |
#/etc/init.d/mysqld start --wsrep-new-cluster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment