什么是mariadb?
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。(来自百度百科)
多实例介绍
简单的说,就是在一台机器上开启多个不同的服务端口(如:3306,3307),运行多个mysql服务进程,这些服务进程通过不同的socket监听不同的服务端口来提供各自的服务。
这些mysql多实例公用一套mysql安装程序,使用不同的my.cnf配置文件、启动程序、数据文件。在提供服务时,多实例mysql在逻辑上看来是各自独立的,多个实例之间是根据配置文件的设定值,来取得相关服务器的硬件资源。
作个比喻,mysql多实例相当于房子的多个卧室一样,每个实例可以看作一个卧室,整个服务器就是一套房子,服务器的硬件资源(cpu,mem,disk)可以看作房子的卫生间、厨房、客厅一样,是房子的公用资源。(来自老男孩培训)
wKiom1NrFvWyzgYdAAHhj3VoMV8993.jpg
部署:
####环境####
虚拟机:1台
linux系统及内核版本:
CentOS release 6.4 (Final)
2.6.32-358.el6.x86_64
#下载安装包
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
wget http://dl.mysql.cn/mariadb/5.5/mariadb-5.5.25.tar.gz
#编译安装cmake
tar zxf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./bootstrap
make
make install
cd ..
#编译安装mariadb
useradd mysql -s /sbin/nologin -M
yum install ncurses-devel -y
yum install libaio-devel -y
tar zxf mariadb-5.5.25.tar.gz
cd mariadb-5.5.25
cmake . -LH|more #CMake下查看mariadb的编译配置
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariamysql\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_FEDERATED_STORAGE_ENGINE=1\
-DENABLED_LOCAL_INFILE=1\
-DEXTRA_CHARSETS=all\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DWITH_DEBUG=0\
-DBUILD_CONFIG=mysql_release\
-DFEATURE_SET=community\
-DWITH_EMBEDDED_SERVER=OFF
make -j 4 #-j指定用于编译的CPU核数,可以加快编译速度
make install
#创建多实例的数据目录
#我这边配置了两个实例,如果想3个、4个同理往下增加即可。
[root@mariadb ~]# mkdir -p /data/{3306,3307}/data
[root@mariadb ~]# cd /data/
[root@mariadb data]# tree
.
├── 3306
│ └── data
└── 3307
└── data
[root@mariadb data]# ll
总用量 8
drwxr-xr-x. 3 root root 4096 5月 7 22:41 3306
drwxr-xr-x. 3 root root 4096 5月 7 22:41 3307
[root@mariadb data]# chown -R mysql.mysql *
[root@mariadb data]# ll
总用量 8
drwxr-xr-x. 3 mysql mysql 4096 5月 7 22:41 3306
drwxr-xr-x. 3 mysql mysql 4096 5月 7 22:41 3307
配置第一个实例:
#拷贝配置文件
[root@mariadb 3306]# cp ~/tools/mariadb-5.5.25/support-files/my-small.cnf ./my.cnf
#修改配置文件
[root@mariadb 3306]# cat my.cnf
[client]
port = 3306
socket = /data/3306/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /data/3306/mysql.sock
basedir = /application/mariamysql
datadir = /data/3306/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
#log_long_format
#log-error = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid-file = /data/3306/mysql.pid
log-bin = /data/3306/mysql-bin
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 1
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/data/3306/mysql_oldboy3306.err
pid-file=/data/3306/mysqld.pid
#编写启动脚本
[root@mariadb 3306]# cat mariadb
#!/bin/sh
port=3306
mysql_user="root"
mysql_pwd=""
CmdPath="/application/mariamysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MariaMySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
else
printf "MariaMySQL is running...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MariaMySQL is stopped...\n"
exit
else
printf "Stoping MariaMySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf "Restarting MariaMySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac
#启动脚本更改为700权限
[root@mariadb 3306]# chmod 700 mariadb
#初始化数据库(注意这里的datadir)
[root@mariadb 3306]#/application/mariamysql/scripts/mysql_install_db --basedir=/application/mariamysql/ --datadir=/data/3306/data/ --user=mysql
#启动数据库
[root@mariadb 3306]# /data/3306/mariadb start
Starting MariaMySQL...
#检查
[root@mariadb 3306]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 29380 mysql 15u IPv4 116393 0t0 TCP *:mysql (LISTEN)
#登录数据库(注意登录写法)
[root@mariadb 3306]# /application/mariamysql/bin/mysql -S /data/3306/mysql.sock
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.25-MariaDB-log MariaDB Server
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
配置第二个实例:
\cp /data/3306/my.cnf /data/3307/
\cp /data/3306/mariadb /data/3307/
sed -i 's#3306#3307#g' /data/3307/my.cnf
#注配置文件内的server-id要与上个实例的配置文件不同。我这改成server-id = 2
sed -i 's#3306#3307#g' /data/3307/mariadb
chown -R mysql.mysql /data/3307/
chmod 700 /data/3307/mariadb
/application/mariamysql/scripts/mysql_install_db --basedir=/application/mariamysql/ --datadir=/data/3307/data/ --user=mysql
/data/3307/mariadb start
netstat -lnt |grep 3307
/application/mariamysql/bin/mysql -S /data/3307/mysql.sock
检查:
[root@mariadb 3307]# netstat -lnt |grep 330
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
©著作权归作者所有:来自51CTO博客作者Magicleesir的原创作品,如需转载,请注明出处,否则将追究法律责任
mysql 多实例mariadbmysql
共同学习,写下你的评论
评论加载中...
作者其他优质文章