[[email protected] ~]# cd /srv/salt/base/  [[email protected] base]# ll  总用量 12  -rw-r--r-- 1 root root 172 11月 14 21:26 apache.sls  -rw-r--r-- 1 root root 128 11月 16 00:12 dns.sls  drwxr-xr-x 2 root root  25 11月 16 00:23 files  -rw-r--r-- 1 root root  28 11月 16 00:22 top.sls  [[email protected] base]# vim dns.sls  [[email protected] base]# cat dns.sls  /etc/resolv.conf:    file.managed:       - source: salt://files/resolv.conf       - user: root       - group: root       - mode: 777       - template: jinja       - defaults:    #定义变量         DNS_SERVER: 192.168.43.118    [[email protected] base]# vim files/resolv.conf  [[email protected] base]# cat files/resolv.conf  #jjjjjjjjjjjjjjjjjj  nameserver {{ DNS_SERVER }}   #2个大括号表示变量    [[email protected] base]# salt '*'  state.highstate  192.168.43.118:  ----------            ID: /etc/resolv.conf      Function: file.managed        Result: True       Comment: File /etc/resolv.conf updated       Started: 00:43:27.222821      Duration: 21.809 ms       Changes:                ----------                diff:                    ---                    +++                    @@ -1,2 +1,3 @@                     #jjjjjjjjjjjjjjjjjj                    -nameserver 192.168.43.1                    +nameserver 192.168.43.118                    +    Summary  ------------  Succeeded: 1 (changed=1)  Failed:    0    [[email protected] base]# vim files/resolv.conf  [[email protected] base]# cat files/resolv.conf  #jjjjjjjjjjjjjjjjjj  #  {{ grains['fqdn_ip4'] }}  nameserver {{ DNS_SERVER }}  [[email protected] base]# salt '*'  state.highstate  192.168.43.118:  ----------            ID: /etc/resolv.conf      Function: file.managed        Result: True       Comment: File /etc/resolv.conf updated       Started: 00:47:03.799795      Duration: 32.514 ms       Changes:                ----------                diff:                    ---                    +++                    @@ -1,3 +1,3 @@                     #jjjjjjjjjjjjjjjjjj                    +#  ['192.168.43.118']                     nameserver 192.168.43.118                    -    Summary  ------------  Succeeded: 1 (changed=1)  Failed:    0  

系统初始化配置:

[[email protected] base]# pwd  /srv/salt/base  [[email protected] base]# mkdir init  [[email protected] base]# mv apache.sls dns.sls files/ /tmp/  [[email protected] base]# tree  .  ├── init  └── top.sls    1 directory, 1 file    [[email protected] base]# cp /tmp/dns.sls init/  [[email protected] base]# ll  总用量 4  drwxr-xr-x 2 root root 21 11月 16 00:55 init  -rw-r--r-- 1 root root 28 11月 16 00:22 top.sls  [[email protected] base]# cd init/  [[email protected] init]# ls  dns.sls    [[email protected] init]# vim dns.sls  [[email protected] init]# cat dns.sls  /etc/resolv.conf:    file.managed:       - source: salt://init/files/resolv.conf       - user: root       - group: root       - mode: 777    [[email protected] init]# mkdir files  [[email protected] init]# cp /etc/resolv.conf files/  [[email protected] init]# cp /etc/resolv.conf files/  [[email protected] init]# vim history.sls  [[email protected] init]# cat history.sls  /etc/profile:    file.append:  #file模块的追加方法      - text:        - export HISTTIMEFORMAT="%F %T 'whoami'"    [[email protected] init]# export  PROMPT_COMMAND=' { msg=$(history 1 | { read x y; echo $y; });logger "[eu:$(who am i):['pwd']"$msg";} '  [[email protected] init]# who  root     pts/0        2018-11-16 00:29 (desktop-4a0ohej)  root     pts/1        2018-11-16 00:38 (desktop-4a0ohej)  [[email protected] init]# tail -f /var/log/messages  Nov 16 01:01:01 master systemd: Starting Session 34 of user root.  Nov 16 01:10:01 master systemd: Started Session 35 of user root.  Nov 16 01:10:01 master systemd: Starting Session 35 of user root.  Nov 16 01:14:00 master root: [eu { msg=$(history 1 | { read x y; echo $y; });logger "[eu:$(who am i):['pwd']"$msg";} '  Nov 16 01:14:04 master root: [eu { msg=$(history 1 | { read x y; echo $y; });logger "[eu:$(who am i):['pwd']"$msg";} '    [[email protected] init]# cat sysctl.sls  vm.swappinese:   #尽量不适用swap分区    sysctl.present:      - value: 0    net.ipv4.ip_local_port_range:    sysctl.present:      - value: 10000 65000    fs.file-max:    #最大打开文件数    sysctl.present:      - value: 100000    [[email protected] init]# vim env_init.sls  [[email protected] init]# cat env_init.sls  include:    - init.dns    - init.history    - init.audit    - init.sysctl    [[email protected] init]# cd ..  [[email protected] base]# ls  init  top.sls  [[email protected] base]# vim top.sls  [[email protected] base]# cat top.sls  base:    '*':      - init.env_init  #在base路径下去init目录找env_init文件并执行    [[email protected] base]# salt '*' state.highstate test=True  测试不执行  [[email protected] base]# salt '*' state.highstate  

原文出处:51cto -> http://blog.51cto.com/13399294/2324553

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。