死磕salt系列-salt 故障汇总

这里将salt使用过程中遇到的所有的故障进行一个汇总。

grains 匹配后多了一个列表

salt-master中配置jinja模板来匹配自定义的grins。

vim /etc/salt/minion
grains:
  roles:
    - elastic-minion1
#配置文件中引用
network.host: {{ grains['roles']}}
#匹配后的结果如下:
network.host: ['elastic-minion1']

解决办法

#修改配置文件中的引用
network.host: {{ grains['roles'][0] }}
重新执行salt同步的命令:
结果如下:
network.host: elastic-minion1

报错一:

----------
          ID: limit-conf-config
    Function: file.managed
        Name: /etc/securilty/limits.conf
      Result: False
     Comment: Parent directory not present
     Started: 17:05:44.606040
    Duration: 11.448 ms
     Changes:   

解决办法:

出现这个的原因是Minion上没有name参数定义的目录. 在minion上定义对应的目录就可以了

报错:salt 管理配置文件时,报错。

[root@master files]# salt '*' state.highstate 
agent.niu.com:
    Data failed to compile:
----------
    Rendering SLS init.limit failed, render error: expected '<document start>', but found '<block mapping start>'
  in "<unicode string>", line 2, column 1:
    limit-conf-config:
    ^
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/state.py", line 2509, in render_state
    sls, rendered_sls=mods
  File "/usr/lib/python2.7/site-packages/salt/template.py", line 79, in compile_template
    ret = render(input_data, saltenv, sls, **render_kwargs)
▽ File "/usr/lib/python2.7/site-packages/salt/renderers/yaml.py", line 50, in render
    data = load(yaml_data, Loader=get_yaml_loader(argline))
  File "/usr/lib64/python2.7/site-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/usr/lib64/python2.7/site-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 39, in get_single_node
    if not self.check_event(StreamEndEvent):
  File "/usr/lib64/python2.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/usr/lib64/python2.7/site-packages/yaml/parser.py", line 174, in parse_document_start
    self.peek_token().start_mark)
ParserError: expected '<document start>', but found '<block mapping start>'
  in "<unicode string>", line 2, column 1:
    limit-conf-config:
    ^

解决办法:

配置文件的路径配置错误。导致报错。修改配置文件,问题解决。

报错:saltstack 执行后CPU占用率为百分之百。

[root@10-10-121-200 ~]# salt 'linux-backup-saltminion' test.ping 
Salt request timed out. The master is not responding. If this error persists after verifying the master is up, worker_threads may need to be increased.

解决办法:

使用top 查看CPU占用率为百分之百。
降低salt的线程数。

报错:配置完return后,不能向数据库写入数据:

mysql> select * from salt_returns;
Empty set (0.00 sec)

解决思路:

当遇到问题是可以将log的级别更改为debug模式来调试。

解决办法:

因为是客户端直接返回给数据库,所有客户端需要数据库的连接权限。顾所有数据库都需要添加如下内容:

vim /etc/salt/minion
mysql.host: '192.168.2.150'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
[root@centos6 ~]# /etc/init.d/salt-minion restart 
Stopping salt-minion daemon:                               [  OK  ]
Starting salt-minion daemon:                               [  OK  ]
[root@centos6 ~]# 

报错: 执行state.sls 报错

root@10.10.121.200 files]# salt '*.service' state.sls ssh.config env=prod
chuye.backup1.service:
    Data failed to compile:
----------
    Requisite declaration file.sshd-files in SLS ssh.config is not formed as a single key dictionary
----------
    Requisite declaration file.sshd-files in SLS ssh.config is not formed as a single key dictionary
chuye.logstash1.service:
    Data failed to compile:
----------
    Requisite declaration file.sshd-files in SLS ssh.config is not formed as a single key dictionary
----------
    Requisite declaration file.sshd-files in SLS ssh.config is not formed as a single key dictionary
chuye.logstash2.service:
    Data failed to compile:
----------
    Requisite declaration file.sshd-files in SLS ssh.config is not formed as a single key dictionary
----------
    Requisite declaration file.sshd-files in SLS ssh.config is not formed as a single key dictionary

解决办法:

 - require:
      - file.sshd-files
    - watch:
      - file.sshd-files

上面的值配置错误

    - require:
      - file: sshd-files
    - watch:
      - file: sshd-files

报错:在文件中调用grains报错

----------
          ID: zabbix-agent-install
    Function: file.managed
        Name: /etc/zabbix_agentd.conf.bak
      Result: False
     Comment: Unable to manage file: Jinja variable 'item' is undefined
     Started: 16:12:39.454923
    Duration: 17.407 ms
     Changes:   

解决办法:

Hostname={{ grains[fqdn] }}
没有加引号
Hostname={{ grains['fqdn'] }}

报错:调用jinjia模板的时候多了一对中括号

#!/bin/sh
 -IPADDR=['10.10.86.159']
 +IPADDR=chuye.logstash2.service

解决办法:

Solution:

Address {{ grains['fqdn_ip4'][0] }}
Result:
Address 111.111.111.111

file.recurse 推送文件时,源文件删除后, 报错。

----------
          ID: prometheus_rules
    Function: file.recurse
        Name: /data/app/prometheus/rules
      Result: False
     Comment: #### /data/app/prometheus/rules/custom.rules ####
              Source file salt://prometheus/files/rules/custom.rules?saltenv=prod not found
              
              #### /data/app/prometheus/rules/mysqld.rules ####
              Source file salt://prometheus/files/rules/mysqld.rules?saltenv=prod not found
              
              #### /data/app/prometheus/rules/kubelet.rules ####
              Source file salt://prometheus/files/rules/kubelet.rules?saltenv=prod not found

临时解决办法(清除缓存)

rm -rf /var/cache/salt/master/file_lists/roots/*
posted @ 2018-04-08 11:23  biglittleant  阅读(4340)  评论(0编辑  收藏  举报