centos7 下Mariadb10.3 多实例安装
一,yum安装mariadb
yum -y install mariadb-server
1 ### yum源配置 2 [root@test72 /etc/yum.repos.d] # cat mariadb.repo CentOS-Base.repo 3 [mariadb] 4 name = MariaDB 5 baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.3.14/yum/centos7-amd64/ 6 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 7 gpgcheck= 0 8 enabled=1 9 10 [base] 11 name=CentOS-$releasever - Base 12 baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/ 13 gpgcheck=1 14 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
二,多实例安装
1,准备实例路径并修改权限
1 mkdir /data/mysql/3306/{data,etc,socket,log,bin,pid} -pv 2 chown -R mysql.mysql /data/mysql
2,初始化实例的数据库文件
1 mysql_install_db --datadir=/data/mysql/3306/data/ --user=mysql
1 Installing MariaDB/MySQL system tables in '/data/mysql/3306/data' ... 2 OK 3 4 To start mysqld at boot time you have to copy 5 support-files/mysql.server to the right place for your system 6 7 8 PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! 9 To do so, start the server, then issue the following commands: 10 11 '/usr/bin/mysqladmin' -u root password 'new-password' 12 '/usr/bin/mysqladmin' -u root -h test72.example.com password 'new-password' 13 14 Alternatively you can run: 15 '/usr/bin/mysql_secure_installation' 16 17 which will also give you the option of removing the test 18 databases and anonymous user created by default. This is 19 strongly recommended for production servers. 20 21 See the MariaDB Knowledgebase at http://mariadb.com/kb or the 22 MySQL manual for more instructions. 23 24 You can start the MariaDB daemon with: 25 cd '/usr' ; /usr/bin/mysqld_safe --datadir='/data/mysql/3306/data' 26 27 You can test the MariaDB daemon with mysql-test-run.pl 28 cd '/usr/mysql-test' ; perl mysql-test-run.pl 29 30 Please report any problems at http://mariadb.org/jira 31 32 The latest information about MariaDB is available at http://mariadb.org/. 33 You can find additional information about the MySQL part at: 34 http://dev.mysql.com 35 Consider joining MariaDB's strong and vibrant community: 36 https://mariadb.org/get-involved/
3,创建并修改实例的配置文件
1 cp -a /etc/my.cnf mysql/3306/etc/ 2 3 #修改配置文件,添加如下信息 4 [mysqld] 5 port=3306 6 datadir=/data/mysql/3306/data 7 socket=/data/mysql/3306/socket/mysql.sock 8 9 [mysqld_safe] 10 log-error=/data/mysql/3306/log/mariadb.log 11 pid-file=/data/mysql/3306/pid/mariadb.pid
4,准备实例的启动脚本,并为脚本增加执行权限
1 vi /data/mysql/3306/bin/mysqld 2 3 chmod +x /data/mysql/3306/bin/mysqld
启动脚本如下:
1 #!/bin/bash 2 port=3306 3 mysql_user="root" 4 mysql_pwd="" 5 cmd_path="/usr/bin" 6 mysql_basedir="/data/mysql" 7 mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock" 8 9 function_start_mysql() 10 { 11 if [ ! -e "$mysql_sock" ];then 12 printf "Starting MySQL...\n" 13 ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null & 14 else 15 printf "MySQL is running...\n" 16 exit 17 fi 18 } 19 20 21 function_stop_mysql() 22 { 23 if [ ! -e "$mysql_sock" ];then 24 printf "MySQL is stopped...\n" 25 exit 26 else 27 printf "Stoping MySQL...\n" 28 ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown 29 fi 30 } 31 32 function_restart_mysql() 33 { 34 printf "Restarting MySQL...\n" 35 function_stop_mysql 36 sleep 2 37 function_start_mysql 38 } 39 40 case $1 in 41 start) 42 function_start_mysql 43 ;; 44 stop) 45 function_stop_mysql 46 ;; 47 restart) 48 function_restart_mysql 49 ;; 50 *) 51 printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n" 52 esac
5,启动并连接数据库
/data/mysql/3306/bin/mysqld start mysql -S /data/mysql/3306/socket/mysql.sock
6,安全加固
进入后修改密码并在/data/mysql/3306/bin/mysqld 中添加相应密码
7,关闭程序后发现PID和SOCKET文件都会消失,日志文件也会重写改变(?)。
├── log
│ └── mariadb.log
├── pid
└── socket
8,同一版本多实例依据以上流程操做。

浙公网安备 33010602011771号