实验:基于YUM安装的多实例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验:基于YUM安装的多实例相关的知识,希望对你有一定的参考价值。

实验:基于YUM安装的多实例

1.安装mariadb

yum install mariadb

2.创建多实例对应的目录结构

mkdir /mysql/{3306,3307,3308}/{data,,socket,log,bin,pid} -pv
技术图片
技术图片
chown -R mysql.mysql /mysql
技术图片

3.创建多实例的数据库文件

mysql_install_db --datadir=/mysql/3306/data/ --user=mysql
技术图片
mysql_install_db --datadir=/mysql/3307/data/ --user=mysql
mysql_install_db --datadir=/mysql/3308/data/ --user=mysql

4.创建对应配置文件

cp /etc/my.cnf /mysql/3306/etc
vim /mysql/3306/etc/my.cnf
[mysqld]
port=3306 加一行
datadir=/mysql/3306/data
socket=/mysql/3306/socket/mysql.sock
[mysqld_safe]
log-error=/mysql/3306/log/mariadb.log
pid-file=/mysql/3306/pid/mariadb.pid
技术图片

cp /mysql/3306/etc/my.cnf /mysql/3307/etc/my.cnf
/mysql/3307/etc/my.cnf
技术图片
技术图片
cp /mysql/3306/etc/my.cnf /mysql/3308/etc/my.cnf
/mysql/3308/etc/my.cnf
技术图片

5.准备各实例的启动脚本

vim /mysql/{3306,3307,3308}/bin/mysqld
cat /mysq/3306/bin/mysqld

#!/bin/bash  
port=3306  
mysql_user="root"  
mysql_pwd=" "  
cmd_path="/usr/bin"  
mysql_basedir="/mysql"  
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"  

function_start_mysql()
{
    if [ ! -e "$mysql_sock" ];then
      printf "Starting MySQL...\n"
      ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf  &> /dev/null  &
    else
      printf "MySQL is running...\n"
      exit
    fi
}

function_stop_mysql()
{
    if [ ! -e "$mysql_sock" ];then
       printf "MySQL is stopped...\n"
       exit
    else
       printf "Stoping MySQL...\n"
       ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
   fi
}

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: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
esac

chmod +x /mysql/{3306,3307,3308}/bin/mysqld
技术图片

6.启动和关闭实例

/mysql/{3306,3307,3308}/bin/mysqld start
/mysql/{3306,3307,3308}/bin/mysqld stop
技术图片
记得更改脚本端口号

7.测试连接

mysql -S /mysql/{3306,3307,3308}/socket/mysql.sock
技术图片

8.安全加固

mysqladmin -S /mysql/{3306,3307,3308}/socket/mysql.sock password ‘centos‘
vim /mysql/{3306,3307,3308}/bin/mysqld 加上对应centos口令

以上是关于实验:基于YUM安装的多实例的主要内容,如果未能解决你的问题,请参考以下文章

cpp►多线程

搭建基于 Anaconda 管理的多用户 JupyterHub 平台

Linux安装Nignx基于域名的多虚拟主机实战

一套基于docker的多实例部署测试脚手架

jenkins 实验 yum安装

Mysql多实例安装