Linux MySQL5.7.18自动化安装脚本1

###### 自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可###############
######数据库目录/data/mysql############
######数据目录/data/mysql############
######慢日志目录/data/slowlog############
######端口号默认3306其余参数按需自行修改############
##################
##################
#!/bin/bash
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit 1
fi
clear
echo "========================================================================="
echo "A tool to auto-compile & install MySQL 5.7.18 on Redhat/CentOS Linux "
echo "========================================================================="
cur_dir=$(pwd)
#set mysql root password
echo "==========================="
mysqlrootpwd="MANAGER"
echo -e "Please input the root password of mysql:"
read -p "(Default password: MANAGER):" mysqlrootpwd
if [ "$mysqlrootpwd" = "" ]; then
mysqlrootpwd="MANAGER"
fi
echo "==========================="
echo "MySQL root password:$mysqlrootpwd"
echo "==========================="
#which MySQL Version do you want to install?
echo "==========================="
isinstallmysql57="n"
echo "Install MySQL 5.7.18,Please input y"
read -p "(Please input y , n):" isinstallmysql57
case "$isinstallmysql57" in
y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)
echo "You will install MySQL 5.7.18"
isinstallmysql57="y"
;;
*)
echo "INPUT error,You will exit install MySQL 5.7.18"
isinstallmysql57="n"
exit
esac
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
#dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start...or Press Ctrl+c to cancel"
char=`get_char`
# Initialize the installation related content.
function InitInstall()
{
cat /etc/issue
uname -a
MemTotal=`free -m | grep Mem | awk ‘{print $2}‘`
echo -e "\n Memory is: ${MemTotal} MB "
#Set timezone
#rm -rf /etc/localtime
#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#Delete Old mariadb program
MARIA=`rpm -qa|grep mariadb`
yum remove $MARIA
#Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config
fi
setenforce 0
}

#Installation of depend on and optimization options.
function InstallDependsAndOpt()
{
cd $cur_dir
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
echo "fs.file-max=65535" >> /etc/sysctl.conf
}
#Install MySQL
function InstallMySQL57()
{
echo "============================Install MySQL 5.7.18=================================="
cd $cur_dir
#Backup old my.cnf
#rm -f /etc/my.cnf
if [ -s /etc/my.cnf ]; then
mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak
fi
echo "============================MySQL 5.7.18 installing…………========================="
#mysql directory configuration
mkdir -p /data/
tar xvf /root/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
mv /root/mysql-5.7.18-linux-glibc2.5-x86_64 /data/mysql
groupadd mysql -g 512
useradd -u 512 -g mysql -s /sbin/nologin -d /home/mysql mysql
touch /data/mysql/error.log
mkdir -p /data/slowlog
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /data/slowlog
#edit /etc/my.cnf
SERVERID=`ifconfig eno1 | grep "inet " | awk ‘{ print $2}‘| awk -F. ‘{ print $3$4}‘`
cat >>/etc/my.cnf<<EOF
[client]
port=3306
socket=/tmp/mysql.sock
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
federated
default-storage-engine=INNODB
port=3306
character-set-server=utf8
socket=/tmp/mysql.sock
basedir=/data/mysql
datadir=/data/mysql/data
explicit_defaults_for_timestamp=true
long_query_time=1
slow_query_log =1
slow_query_log_file=/data/slowlog/slow.log
log-bin=mysql-bin
server-id=109236
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
log-bin-trust-function-creators=1
[mysqld_safe]
log-error=/data/mysql/error.log
EOF
/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql/data --basedir=/data/mysql --initialize-insecure
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
cat >> /etc/ld.so.conf.d/mysql-x86_64.conf<<EOF
/usr/local/mysql/lib
EOF
ldconfig
if [ -d "/proc/vz" ];then
ulimit -s unlimited
fi
/etc/init.d/mysqld start
/data/mysql/bin/mysqladmin -u root password $mysqlrootpwd
cat > /tmp/mysql_sec_script<<EOF
use mysql;
delete from mysql.user where user!=‘root‘ or host!=‘localhost‘;
grant all privileges on *.* to ‘vvnt‘@‘192.168.%‘ identified by ‘[email protected]‘;
flush privileges;
EOF
/data/mysql/bin/mysql -u root -p$mysqlrootpwd -h localhost < /tmp/mysql_sec_script
rm -f /tmp/mysql_sec_script
#/etc/init.d/mysqld restart
echo ‘PATH=/data/mysql/bin/:$PATH‘ >>/etc/profile
source /etc/profile
echo "============================MySQL 5.7.18 install completed========================="
}
function CheckInstall()
{
echo "===================================== Check install ==================================="
clear
ismysql=""
echo "Checking..."
if [ -s /data/mysql/bin/mysql ] && [ -s /data/mysql/bin/mysqld_safe ] && [ -s /etc/my.cnf ]; then
echo "MySQL: OK"
ismysql="ok"
else
echo "Error: /data/mysql not found!!!MySQL install failed."
fi
if [ "$ismysql" = "ok" ]; then
echo "Install MySQL 5.7.18 completed! enjoy it."
echo "========================================================================="
netstat -ntl
else
echo "Sorry,Failed to install MySQL!"
echo "You can tail /root/mysql-install.log from your server."
fi
}
#The installation log
InitInstall 2>&1 | tee /root/mysql-install.log
InstallDependsAndOpt 2>&1 | tee -a /root/mysql-install.log
InstallMySQL57 > /dev/null
CheckInstall 2>&1 | tee -a /root/mysql-install.log

#deletion of installation packages and script files
find /root -type f -name ‘mysql*‘ -exec rm -rf {} \;

原文地址:https://www.cnblogs.com/qiming0322/p/10135935.html

时间: 2024-10-12 12:59:47

Linux MySQL5.7.18自动化安装脚本1的相关文章

Linux MySQL5.7.18自动化安装脚本

###### 自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可#####################数据库目录/data/mysql##################数据目录/data/mysql##################慢日志目录/data/slowlog##################端口号默认3306其余参数按需自行修改############ #####################################!/bin/bash

mysql自动化安装脚本

学习了两周linux shell脚本,终于写出一个mysql自动化安装脚本.加上今天一整天的测试,可以正常执行安装mysql 5.5.40. 其他版本还没有测试.现分享一下.也请高手指点一下.执行该脚本的前提是: 环境介绍: 1.redhat 6.3 x64,最小化安装 2.RAM: 2G,HD:30G 3.关闭selinux 4.配置好yum源(我使用自己配置的源) 5.打开ssh,病配置好iptables,允许远程登录访问. 6.所需软件和文件: cmake-2.8.10.1.tar.gz

Centos7 下Mysql5.7.18的安装和简单主从

Mysql5.7.18的安装 #下载解压tar包 wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ cd /usr/local/ && mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql c

自动化安装脚本

Nginx自动化安装脚本: #!/bin/bash #install nginx-1.10.2 #installation directory INSTALL_DIR=/usr/local SRC_DIR=/usr/local/src [ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR} [ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR} # Check if user is root if

windows10下 MySQL5.7.18版本安装过程及遇到的问题

windows10下 MySQL5.7.18版本安装过程及遇到的问题           mysql-5.7.18-winx64 安装           1.解压 此次将MySQL装在H盘,依个人喜好也可以装在D:/E:/F:盘.           2.在解压目录下创建data空文件夹           3. 将下面信息放到新建文本文件my.ini里                   新建文本文件my.ini,并填入信息: #代码开始                   [Client]

mysql自动化安装脚本开发

最近正好有空闲时间进行mysql自动安装脚本开发,预计先用shell实现一个版本,后续继续用python改造开发,最终实现python版本的开发. 2019-3-18,完成shell脚本的mysql自动化安装脚本的开发与调试.信息如下:mysql版本为5.6.43,通过shell函数的方式实现数据安装的3个阶段,再加上一个全局阶段,共4个阶段 1.全局阶段通过if [ $(id -u) != "0" ]判断当前操作用户是否为root,如不等0,则提示用户使用root用户执行该脚本,实现

红帽系Linux系统安装流程及自动化安装

本文以Centos6.9系统为例,讲解红帽系linux系统启动流程.以便于理解系统安装原理并能自定义系统安装配置完成自动安装. 目录: 一.系统启动基本流程 二.光盘镜像方式安装(U盘同理) 1.配置文件概述 2.光盘安装系统过程 三.自动化安装 1.anaconda配置方式 2.kickstart配置文件格式 3.自动化安装示例 四.网络自动化安装 一.系统启动的基本流程 系统安装与平时系统的启动流程相似,首先让我们简要了解下: 1.BIOS程序 ①POST开机自检 ②列出可以启动的设备顺序,

mysql5.7.18的安装与主从复制

CentOS6.7安装mysql5.7.18 1.  解压到/usr/local目录 # tar -zxvf mysql-5.7.18-linux-glibc2.5-i686.tar.gz -C /usr/local 2.  mysql-5.7.18-linux-glibc2.5-i686文件夹重命名为mysql # cd /usr/local # mv mysql-5.7.18-linux-glibc2.5-i686/ mysql 3.  新建mysql用户组和mysql用户 # groupa

nagios监控端自动化安装脚本

背景:公司需求,部署nagios监控系统,多台服务器部署时,会有重复工作,干脆写成脚本,自动化安装,希望能帮到大家. 脚本内容: #!/bin/bash #Filename:nagios.sh setenforce 0  #需要关闭selinux, yum install -y http php php-mysql mysql mysql-devel mysql-server   #安装http.php和mysql,如果已安装,也无妨 cd /tmp   #我的软件包安装在了tmp目录下,这个可