标签:saltstack
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: ‘L@minion_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个文件,
my.cnf是配置文件,参考标准的
mysql-5.5.33.tar.gz是源文件
mysqld是服务脚本文件,参考标准的。
最后在salt-master执行命令,可在minion完成自动安装mysql,耗时10分钟左右;如中间有错误,修改后再次执行,原先执行过的没变的步骤不会再执行。
salt -N ‘mysqldb‘state.highstate
源码安装是最麻烦的,如果通过yum安装会更加简单。
本文出自 “8399200” 博客,请务必保留此出处http://8409200.blog.51cto.com/8399200/1683754
标签:saltstack
原文地址:http://8409200.blog.51cto.com/8399200/1683754