Chef 简明教程
Chef - Chef-Client as Daemon
以守护程序的身份运行 Chef-Client 有助于随时了解所有节点的状态。这有助于随时运行 Chef-Client。
Running Chef-Client as daemon helps in knowing the state of all the nodes at any point of time. This help in running the Chef-Client at any point of time.
Pre-requisites
该节点应向 Chef server 注册,并且应该在不出现任何错误的情况下运行 Chef-Client。
The node should be registered with Chef server and it should be running Chef-Client without any error.
Chef-Client in Daemon Mode
以守护程序模式启动 Chef-Client,每 30 分钟运行一次。
Start Chef-Client in daemon mode, running every 30 minutes.
user@server:~$ sudo chef-client -i 1800
在上面的代码中,– i 使能够在所需节点上以守护程序模式运行 Chef-Client,而 1800 秒定义了 Chef-Client 守护程序应每 30 分钟运行一次。
In the above code, – i enables to run the Chef-Client in daemon mode on the required node and 1800 seconds define that the Chef-Client daemon should run in every 30 minutes.
Validating Daemon Run
对 Chef-Client 作为守护程序运行进行验证。
Validate that the Chef-Client is running as a daemon.
user@server:~$ ps auxw | grep chef-client
上述命令将 grep Chef-Client 守护程序进程。
The above command will grep the running daemon process of Chef-Client.
Other Ways
我们可以将 Chef-Client 作为 cron job 运行,而不作为守护程序运行它。
Instead of running Chef-Client as a daemon, we can run the same as a cron job.
user@server:~$ subl /etc/cron.d/chef_client
PATH=/usr/local/bin:/usr/bin:/bin
# m h dom mon dow user command
*/15 * * * * root chef-client -l warn | grep -v 'retrying [1234]/5 in'
上面的 cron 作业将在每 15 分钟后运行。
The above cron job will run after every 15 minutes.