linux下一鍵編譯安裝MariaDB10.0.12

來源:互聯網
上載者:User

標籤:linux下指令碼一鍵安裝mariadb

雖然網上有很多的lnmp一鍵安裝包,可以直接安裝Integration Environment。

但是有時候我們需要單獨的安裝mariadb,則可以使用下面的指令碼來安裝。


# 一鍵CMAKE編譯安裝mariadb-10.0.12 

# 安裝到/usr/local/mariadb

# 資料目錄為/data/mysql

# my.cnf檔案是我自己修改的



一鍵安裝包的檔案目錄結構如下:

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M01/85/5C/wKiom1eheojACHjLAAAT5CgkRdU117.png-wh_500x0-wm_3-wmp_4-s_557438182.png" title="222.png" alt="wKiom1eheojACHjLAAAT5CgkRdU117.png-wh_50" />

我們只要自己將下面的檔案組合成的結構,執行sh install.sh指令碼即可完成安裝。




install.sh指令碼內容如下:

#!/bin/bash

# Date: 2016/08/03

# Author: Lee


# 一鍵CMAKE編譯安裝mariadb-10.0.12 

# 安裝到/usr/local/mariadb

# 資料目錄為/data/mysql

# my.cnf檔案是我自己修改的


echo -e "\033[32m即將安裝MariaDB到 /usr/local \033[0m"

echo -e "\033[32m資料目錄為/data/mysql,請確保有足夠的空間存放資料\033[0m"

echo -e "\033[31m你有10秒鐘的時間取消該操作(按ctrl+c取消)\033[0m"

echo

sleep 10


if [ ! -f src/mariadb-10.0.12.tar.gz ];then

echo -e "\033[31m不存在mariadb-10.0.12包.Quit\033[0m" 

exit

fi


tar xf src/mariadb-10.0.12.tar.gz -C src/

cd src/mariadb-10.0.12 


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 


make && make install


groupadd mariadb

useradd -r -s /sbin/nologin -g mariadb mariadb

chown mariadb.mariadb /usr/local/mariadb -R


cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb

chmod +x /etc/init.d/mariadb

\cp ../../my.cnf /etc/my.cnf


mkdir /data/mysql -p

chown mariadb.mariadb /data/mysql -R

/usr/local/mariadb/scripts/mysql_install_db --user=mariadb --basedir=/usr/local/mariadb --datadir=/data/mysql

/etc/init.d/mariadb start


if ss -lnt|grep 3306 --color=auto ;then

echo -e "\033[32mMariaDB已啟動.\n預設server-id為1. \033[0m"

echo -e "\033[31m在主從或主主複製環境下請修改server-id並重啟MariaDB!!\033[0m"

fi



最佳化後的my.cnf設定檔:

[client]

user = root

#password   = your_password

port        = 3306

socket      = /tmp/mysql.sock


[mysql]

default_character_set = utf8

prompt = [\d] >


[mysqld]

####basic####

user = mariadb

port  = 3306

socket  = /tmp/mysql.sock

datadir = /data/mysql/

basedir = /usr/local/mariadb/

pid_file = /var/run/mysql.pid

default_storage_engine = InnoDB


wait_timeout = 28800

interactive_timeout = 28800


# others setting

skip_name_resolve = ON

skip_external_locking

character-set-server = utf8


# Timeout

connect_timeout = 20

wait_timeout = 14400

interactive_timeout = 14400


back_log = 500


myisam_recover

event_scheduler = ON


# Query Cache Setting

query_cache_type = OFF

query_cache_size = 0


# LOG Settings

server-id = 1

log-bin = mysql.bin

binlog_format = mixed

max_binlog_size = 1G

expire_logs_days = 10


binlog_cache_size = 8M


slow_query_log = ON

slow_query_log_file = /data/mysql/localhost_slow.log

long_query_time = 5

log_error = /data/mysql/localhost.error

log_warnings = 2


tmp_table_size = 32M

max_heap_table_size = 32M

max_connections = 1000

max_allowed_packet = 50M

thread_cache_size = 300

open_files_limit = 65535


# 建議設定的比Open_tables大一倍

table_open_cache = 4096


# InnoDB Optimize

innodb_file_per_table = ON

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 32M

# innodb_buffer_pool_size官方建議設定為記憶體大小的50%~80%

innodb_buffer_pool_size = 4G


# 交易記錄檔的大小

innodb_log_file_size = 512M

# Innodb共用資料表空間的大小

innodb_data_file_path = ibdata1:1G:autoextend:max:2G


innodb_buffer_pool_instances = 8


innodb_write_io_threads = 8

innodb_read_io_threads = 8


innodb_buffer_pool_dump_at_shutdown = ON

innodb_buffer_pool_load_at_startup = ON


[mysqldump]

quick

max_allowed_packet = 48M 


[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates


[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M


[mysqlhotcopy]

interactive-timeout


linux下一鍵編譯安裝MariaDB10.0.12

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.