设为首页 收藏本站
查看: 1328|回复: 0

[经验分享] CentOS6.7部署MySQL多实例

[复制链接]

尚未签到

发表于 2018-4-27 12:43:26 | 显示全部楼层 |阅读模式
MySQL多实例介绍
一般大企业使用多实例安装方式
什么是多实例
简单的说,MySQL多实例就是在一台服务器上同时开启多个不同的服务端口(如:33063307),同时运行多个MySQL服务进程,这些服务进程通过不同的socket监听不同的服务端口来提供服务。
这些MySQL多实例共用一套mysql安装程序,使用不同的my.cnf(也可以相同)配置文件、启动程序(也可以相同)和数据文件。
MySQL多实例的作用
1.有效利用服务器资源
可以实现资源的逻辑上的隔离
2.
节约服务器资源
需要主从复制等技术时,多实例就再好不过。
MySQL多实例有它的好处,但也有弊端,比如:会存在资源互相抢占的问题。
MySQL多实例的生产应用场景
1.公司资金紧张
2.
并发访问部署特别大的业务
公司业务访问量部署很大的时候。
3.
门户网站应用MySQL多实例场景
门户网站通常都会使用多实例,因为配置硬件好的服务器,可节省IDC机柜空间,用时,跑多实例也会减少硬件资源跑不满的浪费。
安装MySQL多实例
安装数据库依赖包
rpm -qa ncurses-devel libaio-devel
yum install ncurses-devel libaio-devel -y
安装编译安装工具cmake
yum install cmake -y
创建mysql服务用户
[root@db02 ~]# useradd mysql -s /sbin/nologin -M
[root@db02 ~]# id mysql
uid=513(mysql) gid=513(mysql)
=513(mysql)
下载mysql安装包
cd /home/oldboy/tools
rz
上传mysql-5.5.32.tar.gz软件包
tar xf mysql-5.5.32.tar.gz
cd mysql-5.5.32

开始编译安装

cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
1.-- Running cmake version 2.8.12.2
2.-- MySQL 5.5.32
3.-- Packaging as: mysql-5.5.32-Linux-x86_64
4.-- Configuring done
5.CMake Warning (dev) in sql/CMakeLists.txt:
6.  Policy CMP0022 is not set:INTERFACE_LINK_LIBRARIES defines the link
7.  interface.  Run "cmake --help-policy CMP0022"for policy details.  Use the
8.  cmake_policy command to set thepolicy and suppress this warning.
9.
10.  Target "mysqld" has anINTERFACE_LINK_LIBRARIES property which differs from
11.  its LINK_INTERFACE_LIBRARIESproperties.
12.
13.  INTERFACE_LINK_LIBRARIES:
14.
15.    -lpthread;sql;mysys
16.
17.  LINK_INTERFACE_LIBRARIES:
18.
19.    rt
20.
21.This warning is for project developers. Use -Wno-dev to suppress it.
22.
23.-- Generating done
#出现上述表述cmake成功!
make && make install



[root@db01 ~]# ll /application/mysql-5.5.32/
total 76
drwxr-xr-x 2 root root 4096 Dec 15 14:16 bin
-rw-r–r– 1 root root 17987 Jul 2 2013 COPYING
drwxr-xr-x 3 root root 4096 Dec 15 14:16 data
drwxr-xr-x 2 root root 4096 Dec 15 14:16 docs
drwxr-xr-x 3 root root 4096 Dec 15 14:16 include
-rw-r–r– 1 root root 7470 Jul 2 2013 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 Dec 15 14:16 lib
drwxr-xr-x 4 root root 4096 Dec 15 14:16 man
drwxr-xr-x 10 root root 4096 Dec 15 14:16 mysql-test
-rw-r–r– 1 root root 2496 Jul 2 2013 README
drwxr-xr-x 2 root root 4096 Dec 15 14:16 scripts
drwxr-xr-x 27 root root 4096 Dec 15 14:16 share
drwxr-xr-x 4 root root 4096 Dec 15 14:16 sql-bench
drwxr-xr-x 3 root root 4096 Dec 15 14:16 support-files

做个软连接
ln -s /application/mysql-5.5.32/ /application/mysql
mkdir -p /data/{3306,3307}/data
[root@db01 ~]# tree /data/
/data/
├── 3306
│ └── data
└── 3307
└── data

4 directories, 0 files
上传mysql配置文件、启动脚本
rz 上传data.zip压缩包到/
unzip data.zip
解包

[root@web02 /]# tree /data

  /data
  ├── 3306
  │   ├── data
  │   ├── my.cnf
  │   └── mysql
  └── 3307
  ├── data
  ├── my.cnf
  └── mysql
  

  4 directories, 4 files
[root@web02 /]# cat /data/3306/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/mysql
  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@web02 /]#




[root@web02 /]# cat /data/3306/mysql

  #!/bin/sh
  ################################################
  #this scripts is created by oldboy at 2007-06-09
  #oldboy QQ:31333741
  #site:http://www.etiantian.org
  #blog:http://oldboy.blog.51cto.com
  #oldboy trainning QQ group: 208160987 226199307  44246017
  ################################################
  

  #init
  port=3306
  mysql_user="root"
  mysql_pwd="oldboy"
  CmdPath="/application/mysql/bin"
  mysql_sock="/data/${port}/mysql.sock"
  #startup function
  function_start_mysql()
  {
  if [ ! -e "$mysql_sock" ];then
  printf "Starting MySQL...\n"
  /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
  else
  printf "MySQL is running...\n"
  exit
  fi
  }
  

  #stop function
  function_stop_mysql()
  {
  if [ ! -e "$mysql_sock" ];then
  printf "MySQL is stopped...\n"
  exit
  else
  printf "Stoping MySQL...\n"
  ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
  fi
  }
  

  #restart function
  function_restart_mysql()
  {
  printf "Restarting MySQL...\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
[root@web02 /]#


[root@web02 /]# cat /data/3307/my.cnf

[client]

  port            = 3307
  socket          = /data/3307/mysql.sock
  

[mysql]

  no-auto-rehash
  

[mysqld]

  user    = mysql
  port    = 3307
  socket  = /data/3307/mysql.sock
  basedir = /application/mysql
  datadir = /data/3307/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/3307/error.log
  #log-slow-queries = /data/3307/slow.log
  pid-file = /data/3307/mysql.pid
  #log-bin = /data/3307/mysql-bin
  relay-log = /data/3307/relay-bin
  relay-log-info-file = /data/3307/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 = 3
  

  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/3307/mysql_oldboy3307.err
  pid-file=/data/3307/mysqld.pid

mysql启动脚本添加执行权限
[root@db01 3306]# find /data -type f -name "mysql" |xargs chmod +x  


-rw-r–r– 1 root root 1307 Jul 15 2013 /data/3306/mysql
-rw-r–r– 1 root root 1307 Jul 21 2013 /data/3307/mysql


授权
chown -R mysql.mysql /data/
初始化数据库
cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3306/data/--user=mysql
.
OK
Filling help tables...
OK
$表述初始化正常

./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3307/data/--user=mysql

OK
Filling help tables...
OK
$表述初始化正常

[root@db02 scripts]# /data/3306/mysql start
Starting MySQL…
[root@db02 scripts]# /data/3307/mysql start
Starting MySQL…
[root@db02 scripts]# netstat -lntup|grep 330
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 20669/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 21387/mysqld

进入数据库
mysql -S /data/3306/mysql.sock
mysql -S /data/3307/mysql.sock
登录3306实例:
mysql -uroot -poldboy123 -S /data/3306/mysql.sock
登录3307实例:
mysql -uroot -poldboy123 -S /data/3307/mysql.sock

辅助查看系统日志/var/log/messsages
启动停止mysql服务
/data/3306/mysql stop
/data/3306/mysql start
添加开机自启动服务
echo “#mysql multi instances” >>/etc/rc.loca
l
echo “/data/3306/mysql start” >>/etc/rc.local
echo “/data/3307/mysql start” >>/etc/rc.local

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-452742-1-1.html 上篇帖子: grub救援修复详解(CentOS 5/6) 下篇帖子: Centos 6.5上安装配置KVM
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表