$ sed -i '$adeb http://download.virtualbox.org/virtualbox/debian xenial contrib' /etc/apt/sources.list
为apt-secure导入公钥:$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
通过apt安装VirtualBox和dkms,其中dkms包可以确保在下次通过apt upgrade更新内核时,VirtualBox的内核模块也正确地更新:$ sudo apt-get update
$ sudo apt-get install virtualbox-5.1 dkms
安装Oracle VM VirtualBox扩展包$ axel -a -n 16 "http://download.virtualbox.org/virtualbox/5.1.6/Oracle_VM_VirtualBox_Extension_Pack-5.1.6-110634.vbox-extpack"
然后打开VirtualBox,在管理-全局设定-扩展中选择添加新包。[root@mx ~]# curl -h
Usage: curl [options...] <url>
Options: (H) means HTTP/HTTPS only, (F) means FTP only
--anyauth Pick "any" authentication method (H)
-a, --append Append to target file when uploading (F/SFTP)
--basic Use HTTP Basic Authentication (H)
--cacert FILE CA certificate to verify peer against (SSL)
--capath DIR CA directory to verify peer against (SSL)
-E, --cert CERT[:PASSWD] Client certificate file and password (SSL)
--cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL)
--ciphers LIST SSL ciphers to use (SSL)
--compressed Request compressed response (using deflate or gzip)
-K, --config FILE Specify which config file to read
--connect-timeout SECONDS Maximum time allowed for connection
-C, --continue-at OFFSET Resumed transfer offset
-b, --cookie STRING/FILE String or file to read cookies from (H)
-c, --cookie-jar FILE Write cookies to this file after operation (H)
--create-dirs Create necessary local directory hierarchy
--crlf Convert LF to CRLF in upload
--crlfile FILE Get a CRL list in PEM format from the given file
-d, --data DATA HTTP POST data (H)
--data-ascii DATA HTTP POST ASCII data (H)
--data-binary DATA HTTP POST binary data (H)
--data-urlencode DATA HTTP POST data url encoded (H)
--delegation STRING GSS-API delegation permission
--digest Use HTTP Digest Authentication (H)
--disable-eprt Inhibit using EPRT or LPRT (F)
--disable-epsv Inhibit using EPSV (F)
-D, --dump-header FILE Write the headers to this file
--egd-file FILE EGD socket path for random data (SSL)
--engine ENGINGE Crypto engine (SSL). "--engine list" for list
-f, --fail Fail silently (no output at all) on HTTP errors (H)
-F, --form CONTENT Specify HTTP multipart POST data (H)
--form-string STRING Specify HTTP multipart POST data (H)
--ftp-account DATA Account data string (F)
--ftp-alternative-to-user COMMAND String to replace "USER [name]" (F)
--ftp-create-dirs Create the remote dirs if not present (F)
--ftp-method [MULTICWD/NOCWD/SINGLECWD] Control CWD usage (F)
--ftp-pasv Use PASV/EPSV instead of PORT (F)
-P, --ftp-port ADR Use PORT with given address instead of PASV (F)
--ftp-skip-pasv-ip Skip the IP address for PASV (F)
--ftp-pret Send PRET before PASV (for drftpd) (F)
--ftp-ssl-ccc Send CCC after authenticating (F)
--ftp-ssl-ccc-mode ACTIVE/PASSIVE Set CCC mode (F)
--ftp-ssl-control Require SSL/TLS for ftp login, clear for transfer (F)
-G, --get Send the -d data with a HTTP GET (H)
-g, --globoff Disable URL sequences and ranges using {} and []
-H, --header LINE Custom header to pass to server (H)
-I, --head Show document info only
-h, --help This help text
--hostpubmd5 MD5 Hex encoded MD5 string of the host public key. (SSH)
-0, --http1.0 Use HTTP 1.0 (H)
--ignore-content-length Ignore the HTTP Content-Length header
-i, --include Include protocol headers in the output (H/F)
-k, --insecure Allow connections to SSL sites without certs (H)
--interface INTERFACE Specify network interface/address to use
-4, --ipv4 Resolve name to IPv4 address
-6, --ipv6 Resolve name to IPv6 address
-j, --junk-session-cookies Ignore session cookies read from file (H)
--keepalive-time SECONDS Interval between keepalive probes
--key KEY Private key file name (SSL/SSH)
--key-type TYPE Private key file type (DER/PEM/ENG) (SSL)
--krb LEVEL Enable Kerberos with specified security level (F)
--libcurl FILE Dump libcurl equivalent code of this command line
--limit-rate RATE Limit transfer speed to this rate
-l, --list-only List only names of an FTP directory (F)
--local-port RANGE Force use of these local port numbers
-L, --location Follow redirects (H)
--location-trusted like --location and send auth to other hosts (H)
-M, --manual Display the full manual
--mail-from FROM Mail from this address
--mail-rcpt TO Mail to this receiver(s)
--mail-auth AUTH Originator address of the original email
--max-filesize BYTES Maximum file size to download (H/F)
--max-redirs NUM Maximum number of redirects allowed (H)
-m, --max-time SECONDS Maximum time allowed for the transfer
--metalink Process given URLs as metalink XML file
--negotiate Use HTTP Negotiate Authentication (H)
-n, --netrc Must read .netrc for user name and password
--netrc-optional Use either .netrc or URL; overrides -n
--netrc-file FILE Set up the netrc filename to use
-N, --no-buffer Disable buffering of the output stream
--no-keepalive Disable keepalive use on the connection
--no-sessionid Disable SSL session-ID reusing (SSL)
--noproxy List of hosts which do not use proxy
--ntlm Use HTTP NTLM authentication (H)
-o, --output FILE Write output to <file> instead of stdout
--pass PASS Pass phrase for the private key (SSL/SSH)
--post301 Do not switch to GET after following a 301 redirect (H)
--post302 Do not switch to GET after following a 302 redirect (H)
--post303 Do not switch to GET after following a 303 redirect (H)
-#, --progress-bar Display transfer progress as a progress bar
--proto PROTOCOLS Enable/disable specified protocols
--proto-redir PROTOCOLS Enable/disable specified protocols on redirect
-x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port
--proxy-anyauth Pick "any" proxy authentication method (H)
--proxy-basic Use Basic authentication on the proxy (H)
--proxy-digest Use Digest authentication on the proxy (H)
--proxy-negotiate Use Negotiate authentication on the proxy (H)
--proxy-ntlm Use NTLM authentication on the proxy (H)
-U, --proxy-user USER[:PASSWORD] Proxy user and password
--proxy1.0 HOST[:PORT] Use HTTP/1.0 proxy on given port
-p, --proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)
--pubkey KEY Public key file name (SSH)
-Q, --quote CMD Send command(s) to server before transfer (F/SFTP)
--random-file FILE File for reading random data from (SSL)
-r, --range RANGE Retrieve only the bytes within a range
--raw Do HTTP "raw", without any transfer decoding (H)
-e, --referer Referer URL (H)
-J, --remote-header-name Use the header-provided filename (H)
-O, --remote-name Write output to a file named as the remote file
--remote-name-all Use the remote file name for all URLs
-R, --remote-time Set the remote file's time on the local output
-X, --request COMMAND Specify request command to use
--resolve HOST:PORT:ADDRESS Force resolve of HOST:PORT to ADDRESS
--retry NUM Retry request NUM times if transient problems occur
--retry-delay SECONDS When retrying, wait this many seconds between each
--retry-max-time SECONDS Retry only within this period
-S, --show-error Show error. With -s, make curl show errors when they occur
-s, --silent Silent mode. Don't output anything
--socks4 HOST[:PORT] SOCKS4 proxy on given host + port
--socks4a HOST[:PORT] SOCKS4a proxy on given host + port
--socks5 HOST[:PORT] SOCKS5 proxy on given host + port
--socks5-basic Enable username/password auth for SOCKS5 proxies
--socks5-gssapi Enable GSS-API auth for SOCKS5 proxies
--socks5-hostname HOST[:PORT] SOCKS5 proxy, pass host name to proxy
--socks5-gssapi-service NAME SOCKS5 proxy service name for gssapi
--socks5-gssapi-nec Compatibility with NEC SOCKS5 server
-Y, --speed-limit RATE Stop transfers below speed-limit for 'speed-time' secs
-y, --speed-time SECONDS Time for trig speed-limit abort. Defaults to 30
--ssl Try SSL/TLS (FTP, IMAP, POP3, SMTP)
--ssl-reqd Require SSL/TLS (FTP, IMAP, POP3, SMTP)
-2, --sslv2 Use SSLv2 (SSL)
-3, --sslv3 Use SSLv3 (SSL)
--ssl-allow-beast Allow security flaw to improve interop (SSL)
--stderr FILE Where to redirect stderr. - means stdout
--tcp-nodelay Use the TCP_NODELAY option
-t, --telnet-option OPT=VAL Set telnet option
--tftp-blksize VALUE Set TFTP BLKSIZE option (must be >512)
-z, --time-cond TIME Transfer based on a time condition
-1, --tlsv1 Use => TLSv1 (SSL)
--tlsv1.0 Use TLSv1.0 (SSL)
--tlsv1.1 Use TLSv1.1 (SSL)
--tlsv1.2 Use TLSv1.2 (SSL)
--tlsv1.3 Use TLSv1.3 (SSL)
--tls-max VERSION Use TLS up to VERSION (SSL)
--trace FILE Write a debug trace to the given file
--trace-ascii FILE Like --trace but without the hex output
--trace-time Add time stamps to trace/verbose output
--tr-encoding Request compressed transfer encoding (H)
-T, --upload-file FILE Transfer FILE to destination
--url URL URL to work with
-B, --use-ascii Use ASCII/text transfer
-u, --user USER[:PASSWORD] Server user and password
--tlsuser USER TLS username
--tlspassword STRING TLS password
--tlsauthtype STRING TLS authentication type (default SRP)
--unix-socket FILE Connect through this UNIX domain socket
-A, --user-agent STRING User-Agent to send to server (H)
-v, --verbose Make the operation more talkative
-V, --version Show version number and quit
-w, --write-out FORMAT What to output after completion
--xattr Store metadata in extended file attributes
-q If used as the first parameter disables .curlrc
[root@mx ~]#
curl在Mac和Linux下是自带的命令行工具,如果你也想在Windows上使用,这里推荐使用"git for windows"这个工具,你可以使用此关键字在网络上检索下载。[root@mx ~]# curl www.baidu.com
[root@mx ~]# curl -s https://www.baidu.com -o 1.txt
# 不使用-s时,显示进度信息
[root@mx ~]# curl https://www.baidu.com -o 2.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2443 100 2443 0 0 14183 0 --:--:-- --:--:-- --:--:-- 14203
[root@mx ~]# cat 1.txt
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head
......
[root@mx ~]#
$ curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com
下面命令会移除User-Agent标头。$ curl -A '' https://google.com
也可以通过-H参数直接指定标头,更改User-Agent。$ curl -H 'User-Agent: php/1.0' https://google.com
-b 选项:$ curl -b 'foo=bar' https://google.com
上面命令会生成一个标头Cookie: foo=bar,向服务器发送一个名为foo、值为bar的 Cookie。$ curl -b 'foo1=bar;foo2=bar2' https://google.com
上面命令发送两个 Cookie。$ curl -b cookies.txt https://www.google.com
上面命令读取本地文件cookies.txt,里面是服务器设置的 Cookie(参见-c参数),将其发送到服务器。$ curl -c cookies.txt https://www.google.com
上面命令将服务器的 HTTP 回应所设置 Cookie 写入文本文件cookies.txt。$ curl -d'login=emma&password=123'-X POST https://google.com/login
#或者
$ curl -d 'login=emma' -d 'password=123' -X POST https://google.com/login
使用-d参数以后,HTTP 请求会自动加上标头Content-Type : application/x-www-form-urlencoded。并且会自动将请求转为 POST 方法,因此可以省略-X POST。$ curl -d '@data.txt' https://google.com/login
上面命令读取data.txt文件的内容,作为数据体向服务器发送。$ curl --data-urlencode 'comment=hello world' https://google.com/login
上面代码中,发送的数据hello world之间有一个空格,需要进行 URL 编码。curl -e 'https://google.com?q=example' https://www.example.com
上面命令将Referer标头设为https://google.com?q=example。引用curl -H 'Referer: https://google.com?q=example' https://www.example.com-F 参数:
$ curl -F 'file=@photo.png' https://google.com/profile
上面命令会给 HTTP 请求加上标头Content-Type: multipart/form-data,然后将文件photo.png作为file字段上传。$ curl -F 'file=@photo.png;type=image/png' https://google.com/profile
上面命令指定 MIME 类型为image/png,否则 curl 会把 MIME 类型设为application/octet-stream。$ curl -F 'file=@photo.png;filename=me.png' https://google.com/profile
上面命令中,原始文件名为photo.png,但是服务器接收到的文件名为me.png。$ curl -G -d 'q=kitties' -d 'count=20' https://google.com/search
上面命令会发出一个 GET 请求,实际请求的 URL 为https://google.com/search?q=kitties&count=20。如果省略--G,会发出一个 POST 请求。$ curl -G --data-urlencode 'comment=hello world' https://www.example.com
-H 选项:$ curl -H 'Accept-Language: en-US' https://google.com
上面命令添加 HTTP 标头Accept-Language: en-US。$ curl -H 'Accept-Language: en-US' -H 'Secret-Message: xyzzy' https://google.com
上面命令添加两个 HTTP 标头。$ curl -d '{"login": "emma", "pass": "123"}' -H 'Content-Type: application/json' https://google.com/login
$ curl -i https://www.example.com
上面命令收到服务器回应后,先输出服务器回应的标头,然后空一行,再输出网页的源码。$ curl -I https://www.example.com
上面命令输出服务器对 HEAD 请求的回应。$ curl --head https://www.example.com
-k 参数:$ curl -k https://www.example.com
上面命令不会检查服务器的 SSL 证书是否正确。$ curl -L -d 'tweet=hi' https://api.twitter.com/tweet
--limit-rate 选项:$ curl --limit-rate 200k https://google.com
上面命令将带宽限制在每秒 200K 字节。$ curl -o example.html https://www.example.com
上面命令将www.example.com保存成example.html。$ curl -O https://www.example.com/foo/bar.html
上面命令将服务器回应保存成文件,文件名为bar.html。$ curl -s https://www.example.com
上面命令一旦发生错误,不会显示错误信息。不发生错误的话,会正常显示运行结果。$ curl -s -o /dev/null https://google.com
-S 选项:$ curl -s -o /dev/null https://google.com
上面命令没有任何输出,除非发生错误。$ curl -u 'bob:12345' https://google.com/login
上面命令设置用户名为bob,密码为12345,然后将其转为 HTTP 标头Authorization: Basic Ym9iOjEyMzQ1。$ curl https://bob:12345@google.com/login
上面命令能够识别 URL 里面的用户名和密码,将其转为上个例子里面的 HTTP 标头。$ curl -u 'bob' https://google.com/login
上面命令只设置了用户名,执行后,curl 会提示用户输入密码。$ curl -v https://www.example.com
--trace参数也可以用于调试,还会输出原始的二进制数据。$ curl --trace - https://www.example.com
-x 选项:$ curl -x socks5://james:cats@myproxy.com:8080 https://www.example.com
上面命令指定 HTTP 请求通过myproxy.com:8080的 socks5 代理发出。$ curl -x james:cats@myproxy.com:8080 https://www.example.com
上面命令中,请求的代理使用 HTTP 协议。$ curl -X POST https://www.example.com
上面命令对https://www.example.com发出 POST 请求。$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); //限制响应时间200毫秒
$data = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); //限制响应时间200毫秒
$data = curl_exec($ch);
if($data === false){ //抓取错误信息
print_r('---------------------start------------------------'.PHP_EOL);
var_dump(curl_errno($ch));
var_dump(curl_error($ch));
print_r('---------------------end------------------------');
exit();
}
curl_close($ch);
然后我们发现它告诉我们errno:28 超时了!!!curl_setopt($ch, CURLOPT_TIMEOUT_MS, 600); //限制响应时间600毫秒
还是超时!curl_setopt($ch, CURLOPT_TIMEOUT, 1); //限制响应时间1秒
成功了!那么问题就出在CURLOPT_TIMEOUT_MS上面了! curl_setopt($ch, CURLOPT_NOSIGNAL, true);//libcurl支持毫秒
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
use yii\httpclient\Client;
$client = new Client([
'formatters' => [
'myformat' => 'app\components\http\MyFormatter', // add new formatter
Client::FORMAT_XML => 'app\components\http\MyXMLFormatter', // override default XML formatter
],
]);
在创建自定义的解析器时,应该实现 yii\httpclient\ParserInterface ,同时创建formatter - yii\httpclient\FormatterInterface。 例如:use yii\httpclient\FormatterInterface;
use yii\httpclient\ParserInterface;
use yii\httpclient\Response;
class ParserIni implements ParserInterface
{
public function parse(Response $response)
{
return parse_ini_string($response->content);
}
}
class FormatterIni implements FormatterInterface
{
public function format(Request $request)
{
$request->getHeaders()->set('Content-Type', 'text/ini ; charset=UTF-8');
$pairs = []
foreach ($request->data as $name => $value) {
$pairs[] = "$name=$value";
}
$request->setContent(implode("\n", $pairs));
return $request;
}
}
use yii\httpclient\Client;
$client = new Client();
$requests = [
$client->get('http://domain.com/keep-alive'),
$client->post('http://domain.com/notify', ['userId' => 12]),
];
$responses = $client->batchSend($requests);
可使用特定的 传输方式 提升其性能。 在内置传输中,只有 yii\httpclient\CurlTransport 允许并行发送请求,从而减少程序执行时间。use yii\httpclient\Client;
$client = new Client();
$requests = [
'news' => $client->get('http://domain.com/news'),
'friends' => $client->get('http://domain.com/user/friends', ['userId' => 12]),
'newComment' => $client->post('http://domain.com/user/comments', ['userId' => 12, 'content' => 'New comment']),
];
$responses = $client->batchSend($requests);
// result of `GET http://domain.com/news` :
if ($responses['news']->isOk) {
echo $responses['news']->content;
}
// result of `GET http://domain.com/user/friends` :
if ($responses['friends']->isOk) {
echo $responses['friends']->content;
}
// result of `POST http://domain.com/user/comments` :
if ($responses['newComment']->isOk) {
echo "Comment has been added successfully";
}
use yii\httpclient\Client;
$client = new Client();
$response = $client->createRequest()
->setMethod('POST')
->setUrl('http://domain.com/api/1.0/users')
->setData(['name' => 'John Doe', 'email' => 'johndoe@domain.com'])
->setOptions([
'proxy' => 'tcp://proxy.example.com:5100', // use a Proxy
'timeout' => 5, // set timeout to 5 seconds for the case server is not responding
])
->send();
提示:可以通过 yii\httpclient\Client::$requestConfig 对默认请求进行设置。 可以使用 yii\httpclient\Request::addOptions() 在添加其他设置的同时保留原始的其他参数。use yii\httpclient\Client;
$client = new Client([
'transport' => 'yii\httpclient\CurlTransport' // only cURL supports the options we need
]);
$response = $client->createRequest()
->setMethod('POST')
->setUrl('http://domain.com/api/1.0/users')
->setData(['name' => 'John Doe', 'email' => 'johndoe@domain.com'])
->setOptions([
CURLOPT_CONNECTTIMEOUT => 5, // connection timeout
CURLOPT_TIMEOUT => 10, // data receiving timeout
])
->send();
有关特定参数支持的详细信息,请参阅特定的传输类文档。<?php
//要访问的目标页面
$page_url = "http://dev.kdlapi.com/testproxy";
//代理ip,由快代理提供
$proxy = "47.115.5.19";
$prod = 16816;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $page_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//设置代理
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $prod);
//自定义header
$headers = array();
$headers[] = 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0);';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//自定义cookie
curl_setopt($ch, CURLOPT_COOKIE,'');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); //使用gzip压缩传输数据让访问更快
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $result;
echo "\n\nfetch ".$info['url']."\ntimeuse: ".$info['total_time']."s\n\n";
?>
运行下php curl.php
yum install supervisor
Debian/Ubuntu可通过apt安装apt-get install supervisor
pip安装pip install supervisor
easy_install安装easy_install supervisor
三、supervisor使用[unix_http_server]
file=/tmp/supervisor.sock ;UNIX socket 文件,supervisorctl 会使用
;chmod=0700 ;socket文件的mode,默认是0700
;chown=nobody:nogroup ;socket文件的owner,格式:uid:gid
;[inet_http_server] ;HTTP服务器,提供web管理界面
;port=127.0.0.1:9001 ;Web管理后台运行的IP和端口,如果开放到公网,需要注意安全性
;username=user ;登录管理后台的用户名
;password=123 ;登录管理后台的密码
[supervisord]
logfile=/tmp/supervisord.log ;日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB ;日志文件大小,超出会rotate,默认 50MB,如果设成0,表示不限制大小
logfile_backups=10 ;日志文件保留备份数量默认10,设为0表示不备份
loglevel=info ;日志级别,默认info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ;pid 文件
nodaemon=false ;是否在前台启动,默认是false,即以 daemon 的方式启动
minfds=1024 ;可以打开的文件描述符的最小值,默认 1024
minprocs=200 ;可以打开的进程数的最小值,默认 200
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ;通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
;serverurl=http://127.0.0.1:9001 ; 通过HTTP的方式连接supervisord
; [program:xx]是被管理的进程配置参数,xx是进程的名称
[program:xx]
command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run ; 程序启动命令
autostart=true ; 在supervisord启动的时候也自动启动
startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=3 ; 启动失败自动重试次数,默认是3
user=tomcat ; 用哪个用户启动进程,默认是root
priority=999 ; 进程启动优先级,默认999,值小的优先启动
redirect_stderr=true ; 把stderr重定向到stdout,默认false
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
stdout_logfile_backups = 20 ; stdout 日志文件备份数,默认是10
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
;包含其它配置文件
[include]
files = relative/directory/*.ini ;可以指定一个或多个以.ini结束的配置文件
子进程配置文件说明:#项目名
[program:blog]
#脚本目录
directory=/opt/bin
#脚本执行命令
command=/usr/bin/python /opt/bin/test.py
#supervisor启动的时候是否随着同时启动,默认True
autostart=true
#当程序exit的时候,这个program不会自动重启,默认unexpected,设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected和true。如果为false的时候,无论什么情况下,都不会被重新启动,如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的
autorestart=false
#这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启动成功了。默认值为1
startsecs=1
#脚本运行的用户身份
user = test
#日志输出
stderr_logfile=/tmp/blog_stderr.log
stdout_logfile=/tmp/blog_stdout.log
#把stderr重定向到stdout,默认 false
redirect_stderr = true
#stdout日志文件大小,默认 50MB
stdout_logfile_maxbytes = 20MB
#stdout日志文件备份数
stdout_logfile_backups = 20
子进程配置示例:#说明同上
[program:test]
directory=/opt/bin
command=/opt/bin/test
autostart=true
autorestart=false
stderr_logfile=/tmp/test_stderr.log
stdout_logfile=/tmp/test_stdout.log
#user = test
五、supervisor命令说明supervisorctl status //查看所有进程的状态
supervisorctl stop es //停止es
supervisorctl start es //启动es
supervisorctl restart //重启es
supervisorctl update //配置文件修改后使用该命令加载新的配置
supervisorctl reload //重新启动配置中的所有程序
注:把es换成all可以管理配置中的所有进程。直接输入supervisorctl进入supervisorctl的shell交互界面,此时上面的命令不带supervisorctl可直接使用。systemctl start supervisord.service //启动supervisor并加载默认配置文件
systemctl enable supervisord.service //将supervisor加入开机启动项
常见问题[root@test-huanqiu ~]# visudo
.....
# User privilege specification
pang ALL=(ALL) ALL
[root@test-huanqiu ~]# visudo
.......
# User privilege specification
pang localhost=(root) /bin/chown,/bin/chmod
#这里的NOPASSWD就是配置支持免密执行的字段
pang ALL=(root) NOPASSWD:/usr/bin/vim
# 切换至root用户
sudo su - root
# 修改/etc/sudoers文件权限
chmod 744 /etc/sudoers
# 修改/etc/sudoers文件,添加如下内容,ubuntu为当前用户
ubuntu ALL=(ALL:ALL) NOPASSWD:ALL
# 保存,并恢复权限
chmod 440 /etc/sudoers
# 重启系统
reboot
新启动一个terminal, 测试没有生效。# User privilege specification
root ALL=(ALL:ALL) ALL
pang ALL=(ALL:ALL) NOPASSWD:ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
pang ALL=(ALL:ALL) NOPASSWD:ALL
[root@test-huanqiu ~]# visudo
.....
# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move it further down)
%sudo ALL=(ALL) ALL
和授权给单个用户类似,只不过将用户名在这里换成%组名,所有在该组中的用户都按照此规则进行授权。[pang@localhost ~]$ cat test
cat: test: Permission denied
[pang@localhost ~]$ sudo !!
sudo cat test
lala
xiixixi'
nihao
[pang@localhost ~]$ sudo cd /sys/kernel/debug/
sudo: cd: command not found
[pang@localhost ~]$ sudo bash //或者sudo su - 或者 sudo -s,其实就使用sudo命令从当前用户切换到root用户
[root@localhost debug]# cd /sys/kernel/debug/
[root@localhost debug]#
4.3 sudo操作记入日志[pang@localhost ~]$ sudo touch /var/log/sudo.log
修改/etc/rsyslog.conf配置文件(有些版本系统的这个文件名为/etc/syslog.conf),在该文件加入下面一行[pang@localhost ~]$ sudo vim /etc/rsyslog.conf
.........
local2.debug /var/log/sudo.log //空白不能用空格,必须用tab
[pang@localhost ~]$ sudo vim /etc/sudoers
........
Defaults logfile=/var/log/sudo.log
重启 syslog 服务[pang@localhost ~]$ sudo service rsyslog restart
验证groupadd sudo #因为没有指定gid,所以就按着文件中的gid往后推的
sudo:x:504: #添加完之后在该文件中就出现了这条字段。
sudo:x:504:batman,test #此时,用户batman和test的附属组就是sudo了
此时再visudo%sudo ALL=(root) NOPASSWD:/usr/bin/vim
%sudo ALL=(root) NOPASSWD:/bin/cat
-rw-------. 1 root root 1595 Jul 24 05:00 rsyncd.conf
-rw-------. 1 root root 8 Jul 24 05:00 rsyncd.pass
-rw-------. 1 root root 14 Jul 24 05:00 rsyncd.pwd
[pang@localhost]$ sudo vim rsyncd.conf
发现也是ok的。(1) 重启电脑,进入ubuntu 恢复模式Grub(一直按esc或shift)
(2) 在Grub的菜单中选择root
(3) 重新输入命令 chown root /etc/sudoers
(4) reboot
command sudo visudo
2、在文件末尾,增加如下内容www-data ALL=NOPASSWD: /sbin/iptables, /usr/bin/du
假设你希望使用超级用户(root)权限运行iptables和du命令。但是,如果你想使用超级用户权限运行每一个应用,添加以下命令来代替上面的命令。 www-data ALL=NOPASSWD: ALL
3、就是这样,现在像下面这种方式在你的php脚本中使用exec()函数