centos6与centos7自动化安装mariadb脚本

认软件包在当前目录下。执行该脚本即可。


#!/bin/bash
#------------------------------------------
#Filename:mariadb.sh
#Revision:1.0
#Date:2017-10-11
#Author:zhangsan
#Email:798761864@qq.com
#http://www.ardusty.com/
#boke://amelie.blog.51cto.com/
#Description:
#------------------------------------------

#定义版本变量
ver=`cat/etc/redhat-release|grep-o[0-9]|head-n1`

#初始化安装环境
[$ver-eq7]&&{yumremovemariadb-y&>/dev/null;}
[$ver-eq6]&&{yumremoveMysqL-y&>/dev/null;}
pkill-9-UMysqL&>/dev/null
userdel-rMysqL&>/dev/null

#创建系统用户
useradd-d/app/MysqLdb-r-m-s/sbin/nologinMysqL

#解压缩到指定文件夹,创建软链接
file=`cd;lsmariadb-*`
cd;tarxf$file-C/usr/local/&>/dev/null
cd/usr/local
file1=`lsmariadb-*-d`
rm-rfMysqL&>/dev/null
ln-s$file1MysqL

#配置配置文件
mkdir/etc/MysqL&>/dev/null
cp/usr/local/MysqL/support-files/my-huge.cnf/etc/MysqL/my.cnf
sed-r-i"/^\[MysqLd\]/s/.*/[MysqLd]\ndatadir=\/app\/MysqLdb\ninnodb_file_per_table=on\nskip_name_resolve=on\n/"/etc/MysqL/my.cnf
cd/usr/local/MysqL/
./scripts/MysqL_install_db--user=MysqL--datadir=/app/MysqLdb&>/dev/null

#启动服务
cp/usr/local/MysqL/support-files/MysqL.server/etc/init.d/MysqLd
chkconfig--addMysqLd
[$ver-eq7]&&{mkdir/var/log/mariadb&>/dev/null;touch/var/log/mariadb/mariadb.log;chownMysqL/var/log/mariadb/mariadb.log;chownMysqL/var/log/mariadb;}
[$ver-eq6]&&{touch/var/log/MysqLd.log;chownMysqL/var/log/MysqLd.log;}
serviceMysqLdstart&>/dev/null

#PATH变量及安全环境初始化
echo'PATH=/usr/local/MysqL/bin:$PATH'>/etc/profile.d/MysqL.sh
echo-e"\ny\nmagedu\nmagedu\ny\nn\nn\n\y\n"|/usr/local/MysqL/bin/MysqL_secure_installation&>/dev/null

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native