自动化部署MySQL 5.6 步骤(3)

#!/bin/sh
yum install -y cmake gcc g++ bisonncurses-devel zlib
 
ftp -n<<EOF
open 192.168.0.33
user anonymous dexter
binary
cd pub
prompt
mget *
EOF
 
rpm -ivh mysql-rpm-5.6.21-renfengjun.x86_64.rpm
tar -xvf data.tar -C /u01/mysql/data/
chown -R mysql:mysql /u01/mysql/
 
unique_id=`date "+%Y%m%d%M%S"`
echo 'server_id='$unique_id >> my.cnf
 
cp my.cnf /u01/mysql/

执行远程自动安装命令

执行远程拷贝(dcli命令是我从一体机里面拿出来的脚本,py编写,其实和scp差不多,有需要的可以发邮箱)

如果批量的安装,需要先使用-k选项初始化一下ssh。

将脚本copy到远程

[root@centos511 ~]# ./dcli -l root -c192.168.0.36 -f ./auto_install_mysql.sh

执行远程命令,也可以放在后台

[root@centos511 ~]#./dcli -l root -c192.168.0.36 /root/ auto_install_mysql.sh

输出:

[[root@centos511 ~]# ./dcli -l root -c192.168.0.36 /root/get_rpm.sh
root@192.168.0.36's password:
192.168.0.36: Address 192.168.0.36 maps tolocalhost, but this does not map back to the address - POSSIBLE BREAK-INATTEMPT!
192.168.0.36: Loaded plugins: fastestmirror,security
192.168.0.36: Loading mirror speeds from cachedhostfile
192.168.0.36: * base: mirrors.btte.net
192.168.0.36: * extras: mirrors.btte.net
192.168.0.36: * updates: mirrors.yun-idc.com
192.168.0.36: Setting up Install Process
192.168.0.36: Packagecmake-2.6.4-5.el5.4.x86_64 already installed and latest version
192.168.0.36: Package gcc-4.1.2-55.el5.x86_64already installed and latest version
192.168.0.36: No package g++ available.
192.168.0.36: Package bison-2.3-2.1.x86_64already installed and latest version
192.168.0.36: Packagencurses-devel-5.5-24.20060715.x86_64 already installed and latest version
192.168.0.36: Packagencurses-devel-5.5-24.20060715.i386 already installed and latest version
192.168.0.36: Package zlib-1.2.3-7.el5.x86_64already installed and latest version
192.168.0.36: Package zlib-1.2.3-7.el5.i386already installed and latest version
192.168.0.36: Nothing to do
192.168.0.36: Please login with USER and PASS.
192.168.0.36: Please login with USER and PASS.
192.168.0.36: KERBEROS_V4 rejected as anauthentication type
192.168.0.36: Interactive mode off.
192.168.0.36: Preparing...              ##################################################
192.168.0.36: mysql-rpm                  ##################################################
.......

结束。

验证一下

[root@study2 ~]# service mysql start
Starting MySQL.......................[  OK  ]
 
 
[root@study2 ~]# su - mysql
mys[mysql@study2 ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.21-r5436-log Sourcedistribution
 
Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks oftheir respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
 
root@(none) 12:29:11>show databases ;
+--------------------+
| Database          |
+--------------------+
| information_schema |
| dexdb              |
| mysql              |
| performance_schema |
| test              |
+--------------------+
5 rows in set (0.37 sec)
 
root@(none) 12:29:14>use dexdb ;
Database changed
root@dexdb 12:29:17>select * from t ;
+------+------------+
| id  |name      |
+------+------------+
|    1 |renfengjun |
+------+------------+
1 row in set (0.19 sec)
 
root@dexdb 12:29:19>quit
Bye
 
[root@study2 ~]# service mysql stop
Shutting down MySQL.[  OK  ]

比较粗糙,还有需要改进的地方。慢慢完善吧。

--------------------------------------分割线 --------------------------------------

Ubuntu 14.04下安装MySQL

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主从服务器

Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b8ee1dfe5875f20597ceb3da2c165994.html