标签:socket centos scripts har c11 mysql启动 app libaio down
准备环境:CentOS7.6
mariadb-10.2.23.tar.gz源码包
多实例目录结构:
yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
useradd –r –s /sbin/nologin –d /data/mysql/ mysql
mkdir /data/mysql
chown mysql.mysql /data/mysql
tar xvf mariadb-10.2.18.tar.gz
cd mariadb-10.2.23/
cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \ 指定安装目录
-DMYSQL_DATADIR=/data/mysql/ \ 指定mysql数据目录
-DSYSCONFDIR=/etc/mysql \ 指定配置文件的目录
-DMYSQL_USER=mysql \ 制动用户
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITHOUT_MROONGA_STORAGE_ENGINE=1 -DWITH_DEBUG=0 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ 指定socket文件
-DDEFAULT_CHARSET=utf8 \ 指定字符集类型
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
提示:如果出错,执行rm -f CMakeCache.txt
mkdir mysql/{9527,9528,9529}/{etc,bin,socket,data,log,pid} -pv
chown -R mysql.mysql /opt/mysql/
cd /app/mysql
./scripts/mysql_install_db --user=mysql --datadir=/opt/mysql/9527/data/
./scripts/mysql_install_db --user=mysql --datadir=/opt/mysql/9528/data/
./scripts/mysql_install_db --user=mysql --datadir=/opt/mysql/9529/data/
将生成的数据库文件存放到指定的位置
cp /etc/my.cnf /opt/mysql/9527/etc/
cp /etc/my.cnf /opt/mysql/9528/etc/
cp /etc/my.cnf /opt/mysql/9529/etc/
[mysqld]
port=9527 指定端口号
datadir=/opt/mysql/9527/data 指定本端口号的数据库文件
socket=/opt/mysql/9527/socket/mysql.sock 指定本端口号的socket套接字
#Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#Settings user and group are ignored when systemd is used.
#If you need to run mysqld under a different user or group,
#customize your systemd unit file for mariadb according to the
#instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/opt/mysql/9527/log/mariadb.log 将日志文件存放到指定目录
pid-file=/opt/mysql/9527/pid/mariadb.pid 将pid文件存放到指定目录
#include all files from the config directory
#!includedir /etc/my.cnf.d 原本是没有注释的,现在加上注释,因为他包含的是/etc/my.cnf.d目录下的文件,我们不需要
将三个实例只要稍微修改即可
#!/bin/bash
#chkconfig: 345 80 2
port=9527 端口号
mysql_user="root" 指定数据库用户
mysql_pwd="" 指定数据库的密码
cmd_path="/app/mysql/bin" 指定命令路径
mysql_basedir="/opt/mysql" 指定数据库基本目录
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock" 指定本端口启动的socket文件
function_start_mysql() 启动函数
{
if [ ! -e "$mysql_sock" ];then 检查socket文件
printf "Starting MySQL...\n"
${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null & mysql启动服务用的是mysqld_safe命令
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
/opt/mysql/9527/bin/mysqld start 可以考虑定义为别名
echo ‘PATH=/app/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh 添加PATH路径
. /etc/profile.d/mysql.sh 生效PATH
mysql -uroot -P9527 -S /opt/mysql/9527/socket/mysql.sock 进入mysql数据库,需要指定socket路径
标签:socket centos scripts har c11 mysql启动 app libaio down
原文地址:https://blog.51cto.com/14116879/2388853