There are numerous advantages to run multiple database instances on the save physical server. Here are some reasons that I would like to point out :

1. Utilize existing hardware properly

2. Long lead times to provide physical hardware

3. Reduce Licensing Hardware / OS costs

4. Smaller/manageable data center foot print

5. Reduced overhead

To run multiple instances using MysqL we need to have a couple of things separate from the initial install on MysqL like data directory,init script and config file. It is quite that simple and here is how we do it,I will subscript 2 for all the files/directories that I am going to create to indicate this new second instance:

1. Create a new data directory [/var/lib/MysqL2] and make MysqL user own it.

mkdir /var/lib/MysqL2
chown MysqL.MysqL /var/lib/MysqL2/

2. Create / copy existing MysqL configuration file,call it my2.cnf and update data directory/port values
cp /etc/my.cnf /etc/my2.cnf
vi /etc/my2.cnf
Update the lines as shown in the screenshot above [If you have a custom path,use it]:
datadir=/var/lib/MysqL2
port=3307
3. Create/copy existing MysqL init file to start/stop/reload etc on this new instance

cp /etc/init.d/MysqL /etc/init.d/MysqL2
4. Edit the init file and make some minor changes to make it this instance specific [Four edits required]

vi /etc/init.d/MysqL2

Edit 1 : Add the following line after line 138 for the init script to handle ports
--port=*)     port=`echo "$arg"  sed -e 's/^[^=]*=//'` ;;


Edit 2 : At line 215 update my.cnf to point to the new config file my2.cnf for this instance
conf=/etc/my2.cnf


Edit 3: At line 257 add -c flag to the arguments to read this config file while parsing server arguments
parse_server_arguments `$print_defaults $extra_args MysqLd server MysqL_server MysqL.server -c/etc/my2.cnf`


Edit 4: Add port argument to MysqL_safe command on line 284
$bindir/MysqLd_safe --defaults-file=/etc/my2.cnf --datadir="$datadir" --pid-file="$MysqLd_pid_file_path" --port="$port" --socket="$datadir"/MysqL2.sock $other_args >/dev/null 2>&1 &


You final init script looks like the following:
#!/bin/sh
# copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind

# MysqL daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99MysqL and /etc/rc0.d/K01MysqL.
# When this is done the MysqL server will be started when the machine is
# started and shut down when the systems goes down.

# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable sql database engine.

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: MysqLs
# required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MysqL
# Description: MysqL is a very fast and reliable sql database engine.
### END INIT INFO

# If you change base dir,you must also change datadir. These may get
# overwritten by settings in the MysqL configuration files.

basedir=
datadir=

# Default value,in seconds,afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/MysqL"

# The following variables are only set for letting MysqL.server find things.

# Set some defaults
MysqLd_pid_file_path=
if test -z "$basedir"
then
  basedir=/usr
  bindir=/usr/bin
  if test -z "$datadir"
  then
    datadir=/var/lib/MysqL
  fi
  sbindir=/usr/sbin
  libexecdir=/usr/sbin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="$basedir/data"
  fi
  sbindir="$basedir/sbin"
  libexecdir="$basedir/libexec"
fi

# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=

#
# Use LSB init script functions for printing messages,if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
  . $lsb_functions
else
  log_success_msg()
  {
    echo " SUCCESS! $@"
  }
  log_failure_msg()
  {
    echo " ERROR! $@"
  }
fi

PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
export PATH

mode=$1    # start or stop

[ $# -ge 1 ] && shift

other_args="$*"   # uncommon,but needed when called from an RPM upgrade action
           # Expected: "--skip-networking --skip-grant-tables"
           # They are not checked here,intentionally,as it is the resposibility
           # of the "spec" file author to give correct arguments only.

case `echo "testing\c"`,`echo -n testing` in
    *c*,-n*) echo_n=   echo_c=     ;;
    *c*,*)   echo_n=-n echo_c=     ;;
    *)       echo_n=   echo_c='\c' ;;
esac

parse_server_arguments() {
  for arg do
    case "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
                    bindir="$basedir/bin"
                    if test -z "$datadir_set"; then
                      datadir="$basedir/data"
                    fi
                    sbindir="$basedir/sbin"
                    libexecdir="$basedir/libexec"
        ;;
      --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
                    datadir_set=1
        ;;
      --pid-file=*) MysqLd_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --port=*)     port=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
    esac
  done
}

wait_for_pid () {
  verb="$1"           # created | removed
  pid="$2"            # process ID of the program operating on the pid-file
  pid_file_path="$3" # path to the PID file.

  i=0
  avoid_race_condition="by checking again"

  while test $i -ne $service_startup_timeout ; do

    case "$verb" in
      'created')
        # wait for a PID-file to pop into existence.
        test -s "$pid_file_path" && i='' && break
        ;;
      'removed')
        # wait for this PID-file to disappear
        test ! -s "$pid_file_path" && i='' && break
        ;;
      *)
        echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"
        exit 1
        ;;
    esac

    # if server isn't running,then pid-file will never be updated
    if test -n "$pid"; then
      if kill -0 "$pid" 2>/dev/null; then
        :  # the server still runs
      else
        # The server may have exited between the last pid-file check and Now.
        if test -n "$avoid_race_condition"; then
          avoid_race_condition=""
          continue  # Check again.
        fi

        # there's nothing that will affect the file.
        log_failure_msg "The server quit without updating PID file ($pid_file_path)."
        return 1  # not waiting any more.
      fi
    fi

    echo $echo_n ".$echo_c"
    i=`expr $i + 1`
    sleep 1

  done

  if test -z "$i" ; then
    log_success_msg
    return 0
  else
    log_failure_msg
    return 1
  fi
}

# Get arguments from the my.cnf file,# the only group,which is read from Now on is [MysqLd]
if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x $bindir/my_print_defaults
then
  print_defaults="$bindir/my_print_defaults"
elif test -x $bindir/MysqL_print_defaults
then
  print_defaults="$bindir/MysqL_print_defaults"
else
  # Try to find basedir in /etc/my.cnf
  conf=/etc/my2.cnf
  print_defaults=
  if test -r $conf
  then
    subpat='^[^=]*basedir[^=]*=\(.*\)$'
    dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
    for d in $dirs
    do
      d=`echo $d | sed -e 's/[  ]//g'`
      if test -x "$d/bin/my_print_defaults"
      then
        print_defaults="$d/bin/my_print_defaults"
        break
      fi
      if test -x "$d/bin/MysqL_print_defaults"
      then
        print_defaults="$d/bin/MysqL_print_defaults"
        break
      fi
    done
  fi

  # Hope it's in the PATH ... but I doubt it
  test -z "$print_defaults" && print_defaults="my_print_defaults"
fi

#
# Read defaults file from 'basedir'.   If there is no defaults file there
# check if it's in the old (depricated) place (datadir) and read it from there
#

extra_args=""
if test -r "$basedir/my.cnf"
then
  extra_args="-e $basedir/my.cnf"
else
  if test -r "$datadir/my.cnf"
  then
    extra_args="-e $datadir/my.cnf"
  fi
fi

parse_server_arguments `$print_defaults $extra_args MysqLd server MysqL_server MysqL.server -c/etc/my2.cnf`

#
# Set pid file if not given
#
if test -z "$MysqLd_pid_file_path"
then
  MysqLd_pid_file_path=$datadir/`hostname`.pid
else
  case "$MysqLd_pid_file_path" in
    /* ) ;;
    * )  MysqLd_pid_file_path="$datadir/$MysqLd_pid_file_path" ;;
  esac
fi

case "$mode" in
  'start')
    # Start daemon

    # Safeguard (relative paths,core dumps..)
    cd $basedir

    echo $echo_n "Starting MysqL"
    if test -x $bindir/MysqLd_safe
    then
      # Give extra arguments to MysqLd with the my.cnf file. This script
      # may be overwritten at next upgrade.
      $bindir/MysqLd_safe --defaults-file=/etc/my2.cnf --datadir="$datadir" --pid-file="$MysqLd_pid_file_path" --port="$port" --socket="$datadir"/MysqL2.sock $other_args >/dev/null 2>&1 &
      wait_for_pid created "$!" "$MysqLd_pid_file_path"; return_value=$?

      # Make lock for RedHat / SuSE
      if test -w "$lockdir"
      then
        touch "$lock_file_path"
      fi

      exit $return_value
    else
      log_failure_msg "Couldn't find MysqL server ($bindir/MysqLd_safe)"
    fi
    ;;

  'stop')
    # Stop daemon. We use a signal here to avoid having to kNow the
    # root password.

    if test -s "$MysqLd_pid_file_path"
    then
      MysqLd_pid=`cat "$MysqLd_pid_file_path"`

      if (kill -0 $MysqLd_pid 2>/dev/null)
      then
        echo $echo_n "Shutting down MysqL"
        kill $MysqLd_pid
        # MysqLd should remove the pid file when it exits,so wait for it.
        wait_for_pid removed "$MysqLd_pid" "$MysqLd_pid_file_path"; return_value=$?
      else
        log_failure_msg "MysqL server process #$MysqLd_pid is not running!"
        rm "$MysqLd_pid_file_path"
      fi

      # Delete lock for RedHat / SuSE
      if test -f "$lock_file_path"
      then
        rm -f "$lock_file_path"
      fi
      exit $return_value
    else
      log_failure_msg "MysqL server PID file Could not be found!"
    fi
    ;;

  'restart')
    # Stop the service and regardless of whether it was
    # running or not,start it again.
    if $0 stop  $other_args; then
      $0 start $other_args
    else
      log_failure_msg "Failed to stop running server,so refusing to try to start."
      exit 1
    fi
    ;;

  'reload'|'force-reload')
    if test -s "$MysqLd_pid_file_path" ; then
      read MysqLd_pid < "$MysqLd_pid_file_path"
      kill -HUP $MysqLd_pid && log_success_msg "Reloading service MysqL"
      touch "$MysqLd_pid_file_path"
    else
      log_failure_msg "MysqL PID file Could not be found!"
      exit 1
    fi
    ;;
  'status')
    # First,check to see if pid file exists
    if test -s "$MysqLd_pid_file_path" ; then
      read MysqLd_pid < "$MysqLd_pid_file_path"
      if kill -0 $MysqLd_pid 2>/dev/null ; then
        log_success_msg "MysqL running ($MysqLd_pid)"
        exit 0
      else
        log_failure_msg "MysqL is not running,but PID file exists"
        exit 1
      fi
    else
      # Try to find appropriate MysqLd process
      MysqLd_pid=`pidof $libexecdir/MysqLd`
      if test -z $MysqLd_pid ; then
        if test -f "$lock_file_path" ; then
          log_failure_msg "MysqL is not running,but lock file ($lock_file_path) exists"
          exit 2
        fi
        log_failure_msg "MysqL is not running"
        exit 3
      else
        log_failure_msg "MysqL is running but PID file Could not be found"
        exit 4
      fi
    fi
    ;;
    *)
      # usage
      basename=`basename "$0"`
      echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MysqL server options ]"
      exit 1
    ;;
esac

exit 0


If you plan on deploying more instances you just need to work through edit 2 and 3 mentioned above after you copy the above init file.
5. Install default tables for this new database instance
MysqL_install_db --datadir=/var/lib/MysqL2 --defaults-file=/etc/my2.cnf --user=MysqL

6. Start the new instance
service MysqL2 start

7. Set password for this instance and connect to this new instance
/usr/bin/MysqLadmin -u root -h127.0.0.1 -P3307 password 'opensourcedbmsadmin'
MysqL -uroot -h127.0.0.1 -P3307 -p

8. Finally add it to server start-up list

chkconfig --add MysqL2chkconfig MysqL2 --level 2345 on

If you want to deploy more instances change the subscript and follow above. Make sure that you properly manage memory and processor allocations when running multiple MysqL instances on the same server. Please post any questions below and I will answer as soon as I can.


refer: https://opensourcedbms.com/dbms/running-multiple-mysql-5-6-instances-on-one-server-in-centos-6rhel-6fedora/
https://dev.mysql.com/doc/refman/5.7/en/multiple-unix-servers.html
https://dev.mysql.com/doc/refman/5.7/en/multiple-servers.html

centos环境下运行多实例mysql的更多相关文章

  1. cocoapods – 命令/ bin / sh失败,退出代码23

    适用于所有豆荚,无需豆荚但仍然是同样的错误.有任何想法吗?

  2. 从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像

    我之前已经做了好几次了但是由于某些原因我无法通过这个帖子…我尝试了设置为_POST且没有的变量的PHP脚本……当它们未设置为发布时它工作精细.这是我的iOS代码:这里是PHP的一大块,POST变量不在正确的位置?我想这对于更有经验的开发人员来说是一个相当简单的答案,感谢您的帮助!解决方法$_POST是一个数组,而不是一个函数.您需要使用方括号来访问数组索引:

  3. 当Xcode 4.6打开故事板时,ios – Xcode 5崩溃

    我从2个月前开始使用Xcode4.6的项目,现在我想发送给我的应用程序一切都可以,但是当我尝试在iOS7上运行应用程序时,我看到一些错误;所以我已经下载了新的Xcode5以查看错误在哪里,但是发生了什么事情是当我尝试打开与IBXcode崩溃的故事板.我试图在互联网上看到如何解决这个问题,但我没有找到任何关于这一点.此外,当我尝试使用iOS7在设备上运行应用程序时,Xcode给我的错误是:解决方法问

  4. Xcode 8.2,Swift编译器错误:错误:意外的输入文件

    从Xcode8.1更新到8.2后,我在项目中面临Swift编译器错误.我使用最新的Swift版本和Carthage进行依赖管理.它与Xcode8.1完美搭配,现在我已经尝试了几个小时来修复它,方法是清理DerivedData和Simulator数据,在Xcode中清理并删除Build文件夹,但似乎没有任何帮助.我只安装了一个Xcode版本.我得到以下编译错误:它所指的文件夹如下所示:它实际上在那里,所以我不知道发生了什么……如发现本站有涉嫌侵权/违法违规的内容,请发送邮件至dio@foxmail.com举

  5. phonegap运行android – create命令失败,退出代码8 – linux

    我做了一些googleing但没有发现任何相关内容.任何帮助赞赏.请务必使用裸体vm进行尝试没有nodejs安装或依赖问题.基督教解决方法我刚刚面临同样的问题,问题是没有正确设置sdk工具的路径:请尝试以下方法:

  6. 无法为Android教程构建GStreamer

    我在尝试构建GStreamerAndroid教程时遇到了很多问题.我的环境是:>MacOSX7>AndroidSDK版本17>AndroidNDK8d我能够在Eclipse和命令行中构建和运行NDK示例.我已经下载了http://cdn.gstreamer.com/android/arm/gstreamer-sdk-android-arm-debug-2012.11.tar.bz2并将GSTREA

  7. android – 无法摆脱错误“/usr/bin/ld:找不到-lncurses”

    有人能指出我错过了什么吗?解决方法然后重新运行命令

  8. android – 无法更改默认输出文件夹

    所有我无法在Eclipse中更改默认输出文件夹.当我打开“属性”–>“Java构建路径”–>“Source”,默认输出文件夹是我改成了保存并清理–构建此项目.它变回了这是在我将ADT插件更新到15.0.1之后发生的一些配置:任何建议表示赞赏.谢谢,约翰尼解决方法从AndroidChangesinRevision14开始:Changetothebinoutputfolder.WhiletheAntb

  9. Android – 将SQLite与MySQL同步的最佳方式

    参见英文答案>Synchronizingclient-serverdatabases5个我正在开发一个包含网络应用和移动应用程序的项目,该应用程序记录每日用户的数据.用户可以删除,更新他们的数据,他们可以使用许多设备插入数据.我打算这样开发:用户输入他们的数据然后插入sqlite.服务将定期启动(每5小时或每小时)以使用时间戳与MysqL同步.我确实在互联网上使用服务和时间戳搜索了一个样本,但我一

  10. Android ICS编译问题

    我成功下载了Android4.0.3的源代码.但我无法在我的机器上编译它.我的机器配置是UBUNTU11.1064位,4GBRAM当我运行午餐命令时收到以下错误.JDK已经在路径中.当我运行命令java-version时,我正在关注OutPut任何人都可以帮助继续吗?解决方法如果检查脚本build/core/find-jdk-tools-jar.sh,则可以看到它首先检查名为ANDROID_JAVA_HOME的环境变量.如果将ANDROID_JAVA_HOME环境变量设置为JDK路径,则应修复此错误.

随机推荐

  1. 在airgapped(离线)CentOS 6系统上安装yum软件包

    我有一个CentOS6系统,出于安全考虑,它已经被空气泄漏.它可能从未连接到互联网,如果有,它很长时间没有更新.我想将所有.rpm软件包放在一个驱动器上,这样它们就可以脱机安装而无需查询互联网.但是,我在测试VM上遇到的问题是,即使指定了本地路径,yum仍然会挂起并尝试从在线存储库进行更新.另外,有没有办法使用yum-utils/yumdownloader轻松获取该包的所有依赖项和所有依赖项?目前

  2. centos – 命名在日志旋转后停止记录到rsyslog

    CentOS6.2,绑定9.7.3,rsyslog4.6.2我最近设置了一个服务器,我注意到在日志轮换后,named已停止记录到/var/log/messages.我认为这很奇怪,因为所有日志记录都是通过rsyslog进行的,并且named不会直接写入日志文件.这更奇怪,因为我在更新区域文件后命名了HUPed,但它仍然没有记录.在我停止并重新启动命名后,记录恢复.这里发生了什么?

  3. centos – 显示错误的磁盘大小

    对于其中一个磁盘,Df-h在我的服务器上显示错误的空白区域:Cpanel表明它只有34GB免费,但还有更多.几分钟前,我删除了超过80GB的日志文件.所以,我确信它完全错了.fdisk-l/dev/sda2也显示错误:如果没有格式化,我该怎么做才能解决这个问题?并且打开文件描述符就是它需要使用才能做到这一点.所以…使用“lsof”并查找已删除的文件.重新启动写入日志文件的服务,你很可能会看到空间可用.

  4. 如何在centos 6.9上安装docker-ce 17?

    我目前正在尝试在centOS6.9服务器上安装docker-ce17,但是,当运行yuminstalldocker-ce时,我收到以下错误:如果我用跳过的标志运行它我仍然得到相同的消息,有没有人知道这方面的方法?

  5. centos – 闲置工作站的异常负载平均值

    我有一个新的工作站,具有不寻常的高负载平均值.机器规格是:>至强cpu>256GB的RAM>4x512GBSSD连接到LSI2108RAID控制器我从livecd安装了CentOS6.564位,配置了分区,网络,用户/组,并安装了一些软件,如开发工具和MATLAB.在启动几分钟后,工作站负载平均值的值介于0.5到0.9之间.但它没有做任何事情.因此我无法理解为什么负载平均值如此之高.你能帮我诊断一下这个问题吗?

  6. centos – Cryptsetup luks – 检查内核是否支持aes-xts-plain64密码

    我在CentOS5上使用cryptsetupluks加密加密了一堆硬盘.一切都很好,直到我将系统升级到CentOS6.现在我再也无法安装磁盘了.使用我的关键短语装载:我收到此错误:在/var/log/messages中:有关如何装载的任何想法?找到解决方案问题是驱动器使用大约512个字符长的交互式关键短语加密.出于某种原因,CentOS6中的新内核模块在由旧版本创建时无法正确读取512个字符的加密密钥.似乎只会影响内核或cryptsetup的不同版本,因为在同一系统上创建和打开时,512字符的密钥将起作用

  7. centos – 大量ssh登录尝试

    22个我今天登录CentOS盒找到以下内容这是过去3天内的11次登录尝试.WTF?请注意,这是我从我的提供商处获得的全新IP,该盒子是全新的.我还没有发布任何关于此框的内容.为什么我会进行如此大量的登录尝试?是某种IP/端口扫描?基本上有4名匪徒,其中2名来自中国,1名来自香港,1名来自Verizon.这只发生在SSH上.HTTP上没有问题.我应该将罪魁祸首子网路由吗?你们有什么建议?

  8. centos – kswap使用100%的CPU,即使有100GB的RAM也可用

    >Linux内核是否应该足够智能,只需从内存中清除旧缓存页而不是启动kswap?

  9. centos – Azure将VM从A2 / 3调整为DS2 v2

    我正在尝试调整前一段时间创建的几个AzureVM,从基本的A3和标准A3到标准的DS2v2.我似乎没有能力调整到这个大小的VM.必须从头开始重建服务器会有点痛苦.如果它有所不同我在VM中运行CentOS,每个都有一个带有应用程序和操作系统的磁盘.任何人都可以告诉我是否可以在不删除磁盘的情况下删除VM,创建新VM然后将磁盘附加到新VM?

  10. centos – 广泛使用RAM时服务器计算速度减慢

    我在非常具体的情况下遇到服务器速度下降的问题.事实是:>1)我使用计算应用WRF>2)我使用双XeonE5-2620v3和128GBRAM(NUMA架构–可能与问题有关!

返回
顶部