检查进程是否在Linux上运行的最佳实践?
我用下面的脚本安装了厨师服务器。我是linux新手,我正在尝试学习如何设置厨师服务器。我运行了chef.io提供的命令并且脚本成功了。我真的不知道如何检查,或者我应该做些什么来检查流程是否正在运行。有关如何查看进程是否正在运行的Linux的最佳做法是什么?我能做些什么来找出我需要知道的事情?检查进程是否在Linux上运行的最佳实践?
#!/bin/bash \
echo "Do your provisioning here" \
sudo wget https://packages.chef.io/files/stable/chef-server/12.14.0/el/7/chef-server-core-12.14.0-1.el7.x86_64.rpm \
sudo chmod a+x chef-server-core-12.14.0-1.el7.x86_64.rpm
sudo rpm -Uvh ./chef-server-core-12.14.0-1.el7.x86_64.rpm
sudo chef-server-ctl reconfigure \
sudo openssl rsa -in private.pem -outform PEM -pubout -out ~/.ssh/chef-server.pem \
sudo chef-server-ctl user-create admin 'admin' 'email' 'password' --filename ~/.ssh/chef-server.pem \
sudo openssl rsa -in private.pem -outform PEM -pubout -out ~/.ssh/chef-server-validator.pem \
sudo chef-server-ctl org-create short_name 'idevops' --association_user admin --filename ~/.ssh/chef-server-validator.pem \
sudo openssl rsa -in private.pem -outform PEM -pubout -out ~/.ssh/chef-coffee-server-validator.pem \
sudo chef-server-ctl org-create 4thcoffee 'iDevops 4th Coffee' --association_user admin --filename ~/.ssh/chef-coffee-server-validator.pem \
sudo chef-server-ctl install chef-manage \
sudo chef-server-ctl reconfigure \
sudo chef-manage-ctl reconfigure \
sudo chef-server-ctl install opscode-push-jobs-server \
sudo chef-server-ctl reconfigure \
sudo opscode-push-jobs-server-ctl reconfigure \
sudo chef-server-ctl install opscode-reporting \
sudo chef-server-ctl reconfigure \
sudo opscode-reporting-ctl reconfigure \
sudo chef-server-ctl install PACKAGE_NAME --path /path/to/package/directory \
sudo chef-server-ctl install chef-manage --path /root/packages \
sudo mkdir /etc/opscode && sudo touch /etc/opscode/chef-server.rb \
sudo echo "license['nodes'] = 0" >> /etc/opscode/chef-server.rb \
sudo chef-server-ctl reconfigure
有一个在您发布的输出比较大的提示(如chef-server-ctl status
),
The status subcommand is used to show the status of all services available to the Chef server. The results will vary based on the configuration of a given server.
,或者chef-server-ctl status SERVICE_NAME
where SERVICE_NAME represents the name of any service that is listed after running the service-list subcommand.
请参见在chef-server-ctl (executable)的start
子(朝页面的底部)
好,有你可以在网上找到他们几个地方,你想要做的第一件事是检查是否正在运行的进程。
ps aux | grep process_name
然后如果它正在运行,但仍然无法访问它。您需要使用netstat命令和grep作为端口。
net stat -anp | grep portnumber
你看看服务是否在它应该是的端口上运行。它会说它的倾听。聆听意味着该端口正在该端口上寻找通信。这将意味着应用程序已启动并正在寻找端口上的通信,或者该端口正在被另一个应用程序使用,这就是为什么它没有启动。
通常你会再看看在lgos尾-f -n 100 /路径/到/日志/文件
-n是行数 -f是一个持续的后续所以它怎么你看文件。如果你不指定它,它只会在屏幕上占用100行。
如果你只是想手动检查,登录到服务器并运行:
ps auxw | grep YOUR_PROCESS_NAME
首先,我不从脚本运行的命令,直到我知道他们的工作。 您可能没有运行该服务:
sudo service chef-server status #would be a good place to start
要检查进程运行在Linux上,我建议先从以下内容:
ps aux | grep <part of the process name>
ps aux | grep chef
如果你不喜欢辅助输出你也可以使用像-ef:
ps -ef | grep <part of the process name>
ps -ef | grep chef
如果你知道什么端口的进程应该是开放的,你可以使用netstat的:
netstat -anp | grep <port number>
例如:nginx的或Apache服务器是运行:
netstat -anp | grep 80
观看日志我喜欢使用tail命令:
tail -f /var/log/<name of application folder/<name of log>
实施例:看nginx的日志:
tail -f /var/log/nginx/nginx.log
有时候也可以看系统日志:
tail -f -n 100 /var/log/syslog
如果寻找其他机器的入站连接:
sudo tcpdump -vvv -i any port <port number>
我不熟悉的厨师,但是对于大多数的服务器,你应该能够以某种请求来查询它们。 –
大概停止在bash脚本中执行此操作,并改用厨师成分食谱。 – coderanger