环境:
1
2
|
salt_master:192.168.100.228
salt_client1:192.168.100.245
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
master client 版本一致
[root@salt_server base]
# salt --versions-report
Salt: 0.17.5
Python: 2.6.6 (r266:84292, Jun 18 2012, 14:18:47)
Jinja2: unknown
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 2.2.0.1
ZMQ: 3.2.3
[root@salt_server base]
#
|
开始安装部署文件:
1
2
3
4
5
6
|
top
.sls文件
[root@salt_server base]
# cat top.sls
base:
'salt_client*'
:
- mysql
[root@salt_server base]
#
|
目录结构:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@salt_server base]
# tree mysql/
mysql/
├── conf.sls
├── files
│ ├── conf.sh
│ ├── my.cnf
│ ├── mysql-5.5.22.
tar
.gz
│ ├── mysqld
│ └── mysqllns.sh
├── init.sls
└──
install
.sls
1 directory, 8 files
[root@salt_server base]
#
[root@salt_server mysql]
# cat init.sls
include:
- mysql.
install
- mysql.conf
[root@salt_server mysql]
#
|
安装mysql的主配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
[root@salt_server mysql]
# cat install.sls
#install source mysql
mysql_source:
file
.managed:
- name:
/home/mysql-5
.5.22.
tar
.gz
- unless:
test
-e
/home/mysql-5
.5.22.
tar
.gz
-
source
: salt:
//mysql/files/mysql-5
.5.22.
tar
.gz
#tar source mysql
extract_mysql:
cmd.run:
- cwd:
/home
- names:
-
tar
xf mysql-5.5.22.
tar
.gz
-
chown
root:root
/home/mysql-5
.5.22 -R
- unless:
test
-d
/home/mysql-5
.5.22
- require:
-
file
: mysql_source
#useradd for mysql
mysql_user:
user.present:
- name: mysql
- uid: 1024
- createhome: False
- 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.22
- 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.run: extract_mysql
- pkg: mysql_pkg
- unless:
test
-d
/usr/local/mysql
[root@salt_server mysql]
#
|
mysql config 文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
[root@salt_server mysql]
# cat 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.run: 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
--add mysqld
-
/sbin/chkconfig
--level 35 mysqld on
- unless:
/sbin/chkconfig
--list mysqld
service.running:
- name: mysqld
-
enable
: True
- reload: True
[root@salt_server mysql]
#
|
配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@salt_server mysql]
# tree files/
files/
├── conf.sh初始化文件
├── my.cnf配置文件
├── mysql-5.5.22.
tar
.gz安装包
├── mysqld启动脚本
└── mysqllns.sh软连接
0 directories, 5 files
[root@salt_server mysql]
#
[root@salt_server mysql]
# cat files/conf.sh
#!/bin/bash
/usr/local/mysql/scripts/mysql_install_db
--user=mysql --basedir=
/usr/local/mysql/
--datadir=
/usr/local/mysql/data/
[root@salt_server mysql]
# cat 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/
#mysq competence
/bin/chown
-R mysql.mysql
/usr/local/mysql/
&&
/bin/chown
-R mysql.mysql
/usr/local/mysql/data/
[root@salt_server mysql]
#
|
本文转自devilangel 51CTO博客,原文链接:http://blog.51cto.com/devliangel/1547824,如需转载请自行联系原作者