根据项目需要,前段时间在搞EMM系统各种安装包的自动化部署工作,主要包括一键安装和一键启动\停止功能。总结记录下来,以供后用。
本文主要是自动安装MySQL5.7.11版,Linux版脚本在CentOS7系统下测试通过。
流程如下:
a. 增加mysql用户和组
b. 检查系统是否安装有老版MySQL,如果有就卸载。
c.  卸载OS预装的Maria DB. 由于MariaDB与MySQL水火不容,须将系统预装的MariaDB卸载后再安装mysql.
b. 安装MySQL, 本次是采用RPM包的方式安装,相对简单些;当然也可以使用源码包编译安装,稍微耗时。
c. 修改配置文件my.ini,添加一条语句,增加UTF8字符支持。
d. 修改root用户密码及权限。先在my.ini文件中添加skip-grant-tables,使其跳过认证,然后无密码登陆数据库,配置密码和权限后,要把配置文件中刚才加入的skip-grant-tables注释掉,否则会报错。
e. 根据需要创建相应emm数据库及用户. 
f.  初始化数据库。
#!/bin/bash

#created by Kevin //, modify //

# -----------------------------------------------------------------------------
# Installation Script for the auto-deployment EMM(Linux edition)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# shell script to install MySQL (default version mysql-community-5.7.) echo "-----------------------start install mysql----------------------" # Add to mysql user and mysql group if [ `grep "mysql" /etc/passwd | wc -l` -eq ];then
echo "adding user mysql"
groupadd mysql
useradd -r -g mysql mysql
else
echo "mysql user is exist"
fi # check installed mysql or not
for i in `rpm -qa | grep "mysql"`
do
rpm -e --allmatches $i --nodeps
done # Remove pre-installed on OS MariaDB if exists for i in $(rpm -qa | grep mariadb | grep -v grep)
do
echo "Deleting rpm --> "$i
rpm -e --nodeps $i
done # Install mysqlserver rpm -ivh mysql-community-server-5.7.-.el7.x86_64.rpm mysql-community-client-5.7.-.el7.x86_64.rpm mysql-community-common-5.7.-.el7.x86_64.rpm mysql-community-libs-5.7.-.el7.x86_64.rpm # check the installtation was successful or not
rpm -qa |grep "mysql"
if [ $? != ];then
echo "mysql install fail"| tee $mysql_instlog
exit
else
echo "mysql isntall success"| tee $mysql_instlog
fi # modify configuration files
cd /etc/
echo "character_set_server=utf8" >> my.cnf # startup the mysql
systemctl start mysqld
systemctl status mysqld
/etc/init.d/mysqld start
/etc/init.d/mysqld stop echo "MySQL Server install successfully!" # configuration
cat /etc/my.cnf
sed -i '/mysqld/a\skip-grant-tables' /etc/my.cnf
systemctl restart mysqld
# mysql -u root mysql
mysql -u root mysql -e "use mysql;"
# use mysql
# update mysql.user set authentication_string=password('root') where user='root' ;
mysql -u root mysql -e "update mysql.user set authentication_string=password('root') where user='root' ;"
mysql -u root mysql -e "flush privileges;" cat /etc/my.cnf
sed -i '/skip-grant-tables/s/^/#/' /etc/my.cnf
# mysql -u root -p
# SET PASSWORD = PASSWORD('root');
mysql -u root -proot --connect-expired-password -e "SET PASSWORD = PASSWORD('root');" # mysql -u root mysql
# use mysql;
mysql -u root -proot -e "use mysql;"
# update user set host = '%' where user ='root';
mysql -u root -proot -e "update user set host = '%' where user ='root';"
# select host, user from user;
mysql -u root -proot -e "select host, user from user;"
# exit mysql -u root -proot -e "source /usr/src/tools/user.sql;"
mysql -u root -proot -e "source /usr/src/tools/emm_saas_base.sql;"
# create a new database, name as "emm_saas_base"
# mysql -u root -p
# create database emm_saas_base;
# mysql -u root -proot -e "create database emm_saas_base;"
# show databases;
# mysql -u root -proot -e "show databases;" # initdb
# for x in find . -name "*.sql"
# do source emm_saas_base.sql
# done # create user & authentication
# mysql -u root -p
# CREATE USER 'emm'@'%' IDENTIFIED BY 'emm';
# GRANT ALL ON *.* TO 'emm'@'%'; # show user in the DB
# select host,user from mysql.user;
mysql -u root -proot -e "select host,user from mysql.user;" echo "The MySQL install and config complete! "
 
Windows .bat版本:
@echo off
:: created by Kevin Ji 2016/04/08,modify 2016/05/18
:: -----------------------------------------------------------------------------
:: Installation Script for the auto-deployment EMM(Windows edition-copy)
:: -----------------------------------------------------------------------------
:: Modify EMM_Install script code for windows edition. Add to automatic configure install directory feature.
:: creat an source package directory,name as "EMM_SRC" and an destination install directory,name as "EMM_DEST". md C:\EMM_SRC
md C:\EMM_DEST :: ------------Install MySQL----------------------------------
C:
cd C:\EMM_SRC
start winrar x -r %cd%\mysql-5.7.11-winx64.zip C:\EMM_DEST
pause :: ------------Config MySQL environment variable---------------
rem set MYSQL_HOME=C:\mysql-5.7.11-winx64
rem set PATH=%PATH%;C:\mysql-5.7.11-winx64\bin
setx /M MYSQL_HOME C:\EMM_DEST\mysql-5.7.11-winx64
setx /M PATH %PATH%;C:\EMM_DEST\mysql-5.7.11-winx64\bin :: ------------MySQL installation and initialization------------
xcopy %cd%\user.sql C:\EMM_DEST\mysql-5.7.11-winx64\bin\
xcopy %cd%\emm_saas_base.sql C:\EMM_DEST\mysql-5.7.11-winx64\bin\
C:
cd C:\EMM_DEST\mysql-5.7.11-winx64\bin
mysqld -install
cd C:\EMM_DEST\mysql-5.7.11-winx64\bin
mysqld --initialize :: ------------modify MySQL configuration file-------------------------
C:
cd C:\EMM_DEST\mysql-5.7.11-winx64\
rename C:\EMM_DEST\mysql-5.7.11-winx64\my-default.ini my.ini
echo character_set_server=utf8 >> my.ini
xcopy %cd%\my.ini C:\ /e /i /y :: ------------modify MySQL-root password------------------------------
net stop mysql
echo skip-grant-tables >> my.ini
ping -n 2 127.0.0.1 >nul
taskkill /F /IM mysqld.exe net start mysql
cd C:\EMM_DEST\mysql-5.7.11-winx64\bin
mysql -e "use mysql"
mysql -e "update mysql.user set authentication_string=password('root') where user='root' ;"
mysql -e "flush privileges;" cd C:\EMM_DEST\mysql-5.7.11-winx64\
rename my.ini myold.ini
cd C:\
xcopy C:\my.ini C:\EMM_DEST\mysql-5.7.11-winx64\ :: ------------restart MySQL service-------------------------------
:: taskkill /F /IM mysqld.exe
net start mysql :: ------------Initialization DB-----------------------------------
cd C:\EMM_DEST\mysql-5.7.11-winx64\
echo [client] >> my.ini
echo user=root >> my.ini
echo password=root >> my.ini
cd C:\EMM_DEST\mysql-5.7.11-winx64\bin
mysql --connect-expired-password -e "SET PASSWORD = PASSWORD('root');"
mysql --connect-expired-password -uroot -proot < C:\EMM_DEST\mysql-5.7.11-winx64\bin\user.sql
mysql --connect-expired-password -e "use emm_saas_base;"
mysql --connect-expired-password -uroot -proot < C:\EMM_DEST\mysql-5.7.11-winx64\bin\emm_saas_base.sql
pause
echo MySQL Install and configuration complete

至此完结。

自动化运维——一键安装MySQL的更多相关文章

  1. 自动化运维Ansible安装篇

    Ansible自动化工具之--部署篇 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了 ...

  2. CentOSLinux系统中Ansible自动化运维的安装以及利用Ansible部署JDK和Hadoop

    Ansible 安装和配置 Ansible 说明 Ansible 官网:https://www.ansible.com/ Ansible 官网 Github:https://github.com/an ...

  3. 【linux】【jenkins】自动化运维二 安装插件

    gitlab安装教程参考:https://www.cnblogs.com/jxd283465/p/11525629.html 1.Maven Integration Plugins Jenkins安装 ...

  4. Ansible自动化运维工具安装与使用实例

    1.准备两台服务器,要确定网络是通的.服务器当然越多越好啦....Ansible的简介和好处我就不多说了,自己看百科去(*╹▽╹*) IP:192.168.139.100 IP:192.168.139 ...

  5. python自动化运维篇

    1-1 Python运维-课程简介及基础 1-2 Python运维-自动化运维脚本编写 2-1 Python自动化运维-Ansible教程-Ansible介绍 2-2 Python自动化运维-Ansi ...

  6. Inception介绍(MySQL自动化运维工具)

    Inception介绍 GitHub:https://github.com/mysql-inception/inception 文档:https://mysql-inception.github.io ...

  7. 部署MySQL自动化运维工具inception+archer

    ***************************************************************************部署MySQL自动化运维工具inception+a ...

  8. 轻量级自动化运维工具Fabric的安装与实践

    一.背景环境 在运维工作中,经常会遇到重复性的劳动,这个时候为了效率就必须要使用自动化运维工具. 这里我给大家介绍轻量级自动化运维工具Fabric,Fabric是基于Python语言开发的,是开发同事 ...

  9. 自动化运维工具之 Ansible 介绍及安装使用

    一.初识Ansible 介绍: Absible 使用 模块(Modules)来定义配置任务.模块可以用标准脚本语言(Python,Bash,Ruby,等等)编写,这是一个很好的做法,使每个模块幂等.A ...

随机推荐

  1. html/css 两个div在同一行

    在界面设计的时候,经常需要将两个div在同一行显示. 但是每次都会忘记怎么做,特此随笔,备忘. 如以下要将“第一个div”和“第二个div”显示在同一行: <div id="id1&q ...

  2. python django第二弹

    每天晚上应该就这样坐着,然后把每天的东西做个总结,或大或小,有的人可能愿意把自己的东西保留在草稿箱,想想我还是把他写出来吧,前几次我发现又遇到了之前遇到的简单的问题,翻看自己之前写的几篇小日记,可以很 ...

  3. LeetCode 61

    Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For exa ...

  4. SharePoint中 服务器发出意外响应。响应状态代码是"500"。

    原因是由于服务器内存不够.  

  5. 微信 redirect_uri参数错误 正确的处理

    如果您若成功将微信搭建了到自己的服务器中的情况下,进行网页授权时出现如下图 解决方案: 开发->接口权限->找到类目为"网页服务->网页账号" 点击修改,注意,此 ...

  6. Https要点

    http和https的区别 1.https协议需要到ca申请证书 2.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议 3.http和https使用的是完全不同 ...

  7. JavaScript面试问题:事件委托和this

            JavaScript不仅门槛低,而且是一门有趣.功能强大和非常重要的语言.各行各业的人发现自己最混乱的选择是JavaSscript编程语言.由 于有着各种各样的背景,所以不是每个人都对 ...

  8. Servlet & JSP - Filter

    过滤器可以对用户的请求拦截,进行预处理操作,接着将请求交给 Servlet 处理并生成响应,最后再对响应拦截,进行后处理操作.过滤器应用的场景有:用户登录.加密解密.会话校验等. Filter API ...

  9. Tomcat - JNDI 配置

    1. Create Your JavaBean Class Create the JavaBean class which will be instantiated each time that th ...

  10. 【程序员的SQL金典】笔记(第1章~第5章)

      第一章数据库入门 1.概念: 数据库 表 列 记录(行) 主键 索引         第二章 数据表的创建和管理 1.数据库系统中的数据类型大致可以分为五类:整数.数值.字符相关.日期时间以及二进 ...