自动化运维-003 启动saltstack服务

本文详细介绍了如何配置SaltStack服务端与客户端,包括在服务端和客户端上编辑配置文件,配置主机名和服务端主机名,启动服务端和客户端的过程,以及遇到的错误和解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 192.168.77.130 服务端192.168.106.129 server panyu002
  • 192.168.77.128 客户端192.168.106.128 client panyu001

[root@server ~]# vim /etc/salt/minion  #安装完成后需要先在服务端编辑配置文件:
master: server  # 在文件中找到master,然后配置主机名

[root@client ~]# vim /etc/salt/minion   #同样的客户端也需要进行这个操作:
master: server  # 在文件中找到master,然后配置服务端的主机名 master: panyu002

[root@client ~]# systemctl start salt-minion   #然后启动客户端,客户端不会监听端口:
[root@client ~]# ps aux |grep salt
root       5593  0.5  0.5 285476 19536 ?        Ss   12:13   0:00 /usr/bin/python /usr/bin/salt-minion
root       5603  2.3  0.9 560680 36624 ?        Sl   12:13   0:00 /usr/bin/python /usr/bin/salt-minion
root       5611  0.0  0.4 401568 19104 ?        S    12:13   0:00 /usr/bin/python /usr/bin/salt-minion
root       5680  0.0  0.0 112660   964 pts/0    S+   12:13   0:00 grep --color=auto salt

[root@server ~]# systemctl start salt-master  #接着启动服务端,不过我这里启动时报错了,master和minion都启动不了:
Job for salt-master.service failed because the control process exited with error code. See "systemctl status salt-master.service" and "journalctl -xe" for details.
[root@server ~]# systemctl status salt-master.service
● salt-master.service - The Salt Master Server
   Loaded: loaded (/usr/lib/systemd/system/salt-master.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-01-23 20:07:41 CST; 1min 26s ago
     Docs: man:salt-master(1)
           file:///usr/share/doc/salt/html/contents.html
           https://docs.saltstack.com/en/latest/contents.html
  Process: 3903 ExecStart=/usr/bin/salt-master (code=exited, status=1/FAILURE)
 Main PID: 3903 (code=exited, status=1/FAILURE)
Jan 23 20:07:41 server salt-master[3903]: import salt.config as config
Jan 23 20:07:41 server salt-master[3903]: File "/usr/lib/python2.7/site-packages/salt/config/__init__.py", line 45...odule>
Jan 23 20:07:41 server salt-master[3903]: import psutil
Jan 23 20:07:41 server salt-master[3903]: File "/usr/lib64/python2.7/site-packages/psutil/__init__.py", line 89, i...odule>
Jan 23 20:07:41 server salt-master[3903]: import psutil._pslinux as _psplatform
Jan 23 20:07:41 server salt-master[3903]: AttributeError: 'module' object has no attribute '_pslinux'
Jan 23 20:07:41 server systemd[1]: salt-master.service: main process exited, code=exited, status=1/FAILURE
Jan 23 20:07:41 server systemd[1]: Failed to start The Salt Master Server.
Jan 23 20:07:41 server systemd[1]: Unit salt-master.service entered failed state.
Jan 23 20:07:41 server systemd[1]: salt-master.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@server ~]# systemctl start salt-minion
Job for salt-minion.service failed because the control process exited with error code. See "systemctl status salt-minion.service" and "journalctl -xe" for details.

import psutil._pslinux as _psplatform   #解决办法:分析错误信息:从服务的报错信息中可以看到这主要的两句:
AttributeError: 'module' object has no attribute '_pslinux'

这是因为导入了psutil包中的_pslinux,但是_pslinux不存在,所以就报错了。解决的办法也很简单,重新下载安装psutil包即可:
[root@server ~]# wget https://pypi.python.org/packages/source/p/psutil/psutil-3.2.2.tar.gz 
[root@server ~]# tar zxvf psutil-3.2.2.tar.gz  
[root@server ~]# cd psutil-3.2.2/
[root@server ~/psutil-3.2.2]# python setup.py install  #可能需要一些环境gcc、python3-dev、libevent-dev等
[root@server ~/psutil-3.2.2]# echo $?
0

[root@server ~/psutil-3.2.2]# systemctl start salt-master   #这时启动服务就正常了:
[root@server ~/psutil-3.2.2]# systemctl start salt-minion
[root@server ~/psutil-3.2.2]# ps aux |grep salt
root       4220  0.0  1.9 387532 37120 ?        Ss   20:25   0:00 /usr/bin/python /usr/bin/salt-master
root       4229  0.0  1.0 315048 19816 ?        S    20:25   0:00 /usr/bin/python /usr/bin/salt-master
root       4235  0.0  1.6 468824 31252 ?        Sl   20:25   0:00 /usr/bin/python /usr/bin/salt-master
root       4236  0.0  1.8 392560 35228 ?        S    20:25   0:00 /usr/bin/python /usr/bin/salt-master
root       4239  0.3  2.7 415004 51016 ?        S    20:25   0:07 /usr/bin/python /usr/bin/salt-master
root       4240  0.0  1.6 387532 31200 ?        S    20:25   0:00 /usr/bin/python /usr/bin/salt-master
root       4241  0.0  1.7 764388 31956 ?        Sl   20:25   0:00 /usr/bin/python /usr/bin/salt-master
root       4248  0.0  2.2 482512 41836 ?        Sl   20:25   0:01 /usr/bin/python /usr/bin/salt-master
root       4249  0.0  2.2 482516 41828 ?        Sl   20:25   0:01 /usr/bin/python /usr/bin/salt-master
root       4250  0.0  2.2 482248 41784 ?        Sl   20:25   0:01 /usr/bin/python /usr/bin/salt-master
root       4251  0.0  2.2 482236 41768 ?        Sl   20:25   0:01 /usr/bin/python /usr/bin/salt-master
root       4252  0.0  2.2 482256 41812 ?        Sl   20:25   0:01 /usr/bin/python /usr/bin/salt-master
root       5428  0.0  1.0 287592 19592 ?        Ss   20:25   0:00 /usr/bin/python /usr/bin/salt-minion
root       5431  0.0  2.0 563292 37424 ?        Sl   20:25   0:00 /usr/bin/python /usr/bin/salt-minion
root       5439  0.0  1.0 406604 19832 ?        S    20:25   0:00 /usr/bin/python /usr/bin/salt-minion
root       9032  0.0  0.0 112652   956 pts/0    S+   21:00   0:00 grep --color=auto salt
[root@server ~/psutil-3.2.2]# netstat -lntp |grep python  #yum install net-tools 4505端口发布消息,4506端口与客户端通信、传输数据
tcp        0      0 0.0.0.0:4505            0.0.0.0:*               LISTEN      4235/python         
tcp        0      0 0.0.0.0:4506            0.0.0.0:*               LISTEN      4241/python         

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值