Tree/srv/salt
/srv/salt
|--MySQL
| |--Conf.sls
| |--files
| | |--conf.sh
| | |--my.cnf
| | |--mysql-5.5.33.tar.gz
| | |--mysqld
| | '--mysqllns.sh
| |--Init.sls
| '--Install.sls
'--Top.sls
Cat/srv/salt/top.sls
Base
‘*‘:
-Tree
MYSQLDB:
-Match:nodegroup
-MySQL
Cat/etc/salt/master |grep-v "^$" |grep-v "#"
Auto_accept:true
File_roots:
Base
-/srv/salt
Nodegroups:
MYSQLDB: ' [email protected]_server_name '
Cat/srv/salt/mysql/init.sls
Include
-Mysql.install
-Mysql.conf
Cat/srv/salt/mysql/init.sls
Include
-Mysql.install
-Mysql.conf
Cat/srv/salt/mysql/install.sls
#install source MySQL
Mysql_source:
File.managed:
-Name:/home/mysql-5.5.33.tar.gz
-Unless:test-e/home/mysql-5.5.33.tar.gz
-Source:salt://mysql/files/mysql-5.5.33.tar.gz
#tar source MySQL
Extract_mysql:
Cmd.run:
-CWD:/Home
-Names:
-Tar xfmysql-5.5.33.tar.gz
-Chown Root:root/home/mysql-5.5.33-r
-unless:test-d/home/mysql-5.5.33
-Require:
-File:mysql_source
#useradd for MySQL
Mysql_user:
User.present:
-Name:mysql
-uid:1024
-Createhome:true
-Gid_from_name:true
-Shell:/sbin/nologin
#mysql Pkg.install
MYSQL_PKG:
Pkg.installed:
-pkgs:
-GCC
-Gcc-c++
-Autoconf
-Automake
-OpenSSL
-Openssl-devel
-Zlib
-Zlib-devel
-Ncurses-devel
-Libtool-ltdl-devel
-CMake
#mysql Source Install
Mysql_commpile:
Cmd.run:
-CWD:/home/mysql-5.5.33
-Names:
-Cmake-dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/usr/local/mysql/data-ddefault_charset=utf8- Ddefault_collatton=utf8_cuicode_ci-dwith_readline=1-dwith_ssl=system-dwith_embedded_server=1-denabled_local_ Infile=1-ddefault_collation=utf8_general_ci-dwith_myisam_storage_engine=1-dwith_innobase_storage_engine=1- Dwith_debug=0
-Make
-Make Install
-Require:
-Cmd:extract_mysql
-Pkg:mysql_pkg
-Unless:test-d/usr/local/mysql
Cat/srv/salt/mysql/conf.sls
#include:
#-Mysql.install
# MySQL for config
MYSQL_CNF:
File.managed:
-Name:/ETC/MY.CNF
-User:root
-mode:755
-SOURCE:SALT://MYSQL/FILES/MY.CNF
# mysql Init
Salt://mysql/files/conf.sh:
Cmd.script:
-ENV:
-BATCH: ' Yes '
-Require:
-Cmd:mysql_commpile
-Pkg:mysql_pkg
Salt://mysql/files/mysqllns.sh:
Cmd.script:
-ENV:
-BATCH: ' Yes '
-Require:
-Cmd:mysql_commpile
-Pkg:mysql_pkg
# MySQL Server
Mysql_service:
File.managed:
-Name:/etc/init.d/mysqld
-User:root
-mode:755
-Source:salt://mysql/files/mysqld
Cmd.run:
-Names:
-/sbin/chkconfig--addmysqld
-/sbin/chkconfig--level235 mysqld on
-Unless:/sbin/chkconfig--list mysqld
Service.running:
-Name:mysqld
-Enable:true
-Reload:true
cat/srv/salt/mysql/files/conf.sh
#!/bin/bash
/usr/local/mysql/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql/--datadir=/usr/local/mysql/ data/
cat/srv/salt/mysql/files/mysqllns.sh
#!/bin/bash
#lns
Ln-sv/usr/local/mysql/bin/mysql/usr/bin
ln-sv/usr/local/mysql/bin/mysqladmin/usr/bin/
ln-sv/usr/local/mysql/bin/mysqldump/usr/bin/
Ln-sv/var/lib/mysql/mysql.sock/tmp/mysql.sock
#mysq Competence
/bin/chown-r mysql.mysql/usr/local/mysql/&&/bin/chown-rmysql.mysql/usr/local/mysql/data/
3 Additional documents,
my.cnf is a configuration file, refer to the standard
mysql-5.5.33.tar.gz is the source file
mysqld is the service script file, reference standard.
Finally executes the command in the Salt-master, can complete the automatic installation MySQL in the Minion, takes about 10 minutes, if has the error in the middle, the change executes again, the original execution the unchanged step no longer executes.
Salt-n ' MySQLdb ' state.highstate
Source installation is the most troublesome, if it is easier to install through Yum.
This article is from the "8399200" blog, please be sure to keep this source http://8409200.blog.51cto.com/8399200/1683754
Install MySQL via saltstack source