一、服务端和客户端安装

1、下载epel源

http://mirrors.zju.edu.cn/epel/6/

#wget http://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm

# rpm -ivh epel-release-6-8.noarch.rpm

2、查看epel是否安装成功

# yum repolist

Loaded plugins: fastestmirror, security

Loading mirror speeds from cached hostfile

 * base: ftp.sjtu.edu.cn

 * epel: mirrors.ustc.edu.cn

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

repo id                   repo name                                                        status

base                      CentOS-6 - Base                                                   6,518

epel                      Extra Packages for Enterprise Linux 6 - x86_64                   11,364

extras                    CentOS-6 - Extras                                                    37

updates                   CentOS-6 - Updates                                                  947

repolist: 18,866

3、安装服务端

# yum -y install salt-master

4、客户端安装

# yum -y install salt-minion

5、配置服务端

# vim /etc/salt/master

log_level:  debug      ; 将日志格式改为Debug,可查看服务端的启动过程。默认warning

提示:日志文件在/var/log/salt/master

6、配置minion客户端

# vim /etc/salt/minion

master: 192.168.1.11

id: minion-client-01           ; 标记客户端名称

###loop_interval: 60

schedule:

  highstate:

    function: state.highstate

    seconds: 30             ; 配置客户端每隔30s去服务器同步资源。

7、分别启动服务端和客户端

# /etc/init.d/salt-master start

# /etc/init.d/salt-minion start

提示:服务端监听4505和4506两个端口,客户端无端口。

8、服务端验证是否有客户端证书过来

[root@CentOS_11 tool]# salt-key -L

Accepted Keys:

Unaccepted Keys:

minion-client-01

Rejected Keys:

9、接受客户端的证书,也可在服务端配置里配置自动接受。

1)服务端自动接受客户端证书参数

# vim /etc/salt/master

auto_accept: True

2)手动(两个参数)

-a ACCEPT, --accept=ACCEPT

                        Accept the specified public key (use --include-all to

                        match rejected keys in addition to pending keys).

                        Globs are supported.

-A, --accept-all    Accept all pending keys

[root@CentOS_11 tool]# salt-key -a minion-client-01

The following keys are going to be accepted:

Unaccepted Keys:

minion-client-01

Proceed? [n/Y] y

Key for minion minion-client-01 accepted.

 

==================到此服务端和客户端的安装结束=========================

 

二、配置及使用

1、salt命令参数举例

Usage: salt [options] '<target>' <function> [arguments]

用法:salt 参数 对象 函数(模块)  参数

1) -E参数

# salt -E 'minion-client-0*' test.ping        ;-E参数对象可以使用正则

2)-G参数

-G   这个参数很强大 会根据默认的grain的结果来 指定最新  grain这个东西就像puppet里面的facter这个东西

用这个可以查看下 某台设备当前可用的grains     salt  ‘CMN-NC-3-3O1′  grains.ls    要值的话 改成 grains.items 就行

[root@CentOS_11 tool]# salt '*' grains.ls

minion-client-01:

    - SSDs

    - cpu_flags

    - cpu_model

    - cpuarch

    - domain

    - host

    - hwaddr_interfaces

    - id

    - ip4_interfaces

    - ip6_interfaces

    - ip_interfaces

    - ipv4

    - ipv6

    - kernel

    - kernelrelease

    - locale_info

    - localhost

    - machine_id

    - manufacturer

    - master

    - mem_total

    - nodename

    - num_cpus

    - num_gpus

    - os

    - os_family

    - osarch

    - oscodename

     。。。。

# salt -G 'mem_total:852' test.ping

minion-client-01:

    True

3)-N 参数

-N   这个参数是基于组来弄的  前提是你得先分好组,在配置文件里添加分组。

# vim /etc/salt/mast

nodegroups:

   salt-client: 'minion-client-01'

[root@CentOS_11 tool]# salt -N 'salt-client' test.ping

minion-client-01:

    True

2、salt命令模块举例

命令的话  这块就比较多了   这个真没法讲 一堆东西   salt ‘对象’  sys.doc  用这个命令 自己看吧 很多的

可以再细化点  这样吧   salt ‘对象’  sys.doc service  #意思是只看 service 模板的用法(好像是叫模板)

[root@CentOS_11 tool]# salt -N 'salt-client' cmd.run 'ifconfig eth0'

      

                                      待续  。。。

 posted on 2015-04-08 16:30  阿~贵  阅读(236)  评论(0编辑  收藏  举报