curl其实是一种用URL语法,它是一种传输数据工具,是通过命令来进行工作的。Curl在很多的操作系统中被使用,其中包括Unix、和Linux,除此之外,也有DOS和Win64等的版本。curl 命令是利用 url 在命令行下进行工作的传输工具,它支持包括 file、ftp、ftps、http、https、imap、imaps、ldap、ldaps、mqtt、pop、pop3s、rtmp、rtmps、rtsp、scp、sftp、smb、smbs、smtp、smtps、telnet 和 tftp 等协议。
基本语法:curl [option] [url]
option的参数使用我们可以使用 curl -h 命令查看帮助
-o, --output <file> 写入到文件,而不是输出到stdout
-O 写入到文件,文件名和远程文件一样
-L 跟随网站的跳转
-x, --proxy [protocol://][user:pwd@]host[:port] 使用代理
-v 打印过程
--trace <file> debug写入到文件,很详细包括二进制数据交换,file使用 - 表示打印到stdout
-c <file> 将服务器设置的cookie写入到文件
-b <data> 发送cookie,从 string/file 获取
-A <name> 发送 User-Agent <name> 到服务器
-e <url> 指定 Referer : <url> , 仿造referer,服务器会以为你是从 url 点击某个链接过来的
-H <header/@file> 将自定义标头传递到服务器
-X <command> 指定请求方法,不带任何参数的请求默认get方法
-s Silent mode 无声模式
-S Show error even when -s is used 即使使用 -s 也打印错误
-i 打印服务器回应的http标头
-I 只打印标头
-k 使用ssl时,允许不安全的服务器连接。跳过ssl检测
-d <data> http post data,使用post方法发送表单,自动添加标头Content-Type : application/x-www-form-urlencoded
-F <name=content> 指定 multipart MIME data , 可以上传二进制文件,自动添加Content-Type: multipart/form-data
-G 把 post data 放进 url 并使用 get 请求,与-d配合
-u <user:password> 指定服务器用户和密码
-T <file> 上传文件,使用 put 请求
使用curl请求elasticsearch查询信息格式如下:
curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'
VERB
适当的 HTTP 方法 或 谓词 : GET、POST、PUT、HEAD 或者 DELETE。
PROTOCOL
http 或者 https(如果你在 Elasticsearch 前面有一个https 代理)
HOST
Elasticsearch 集群中任意节点的主机名,或者用 localhost 代表本地机器上的节点。
PORT
运行 Elasticsearch HTTP 服务的端口号,默认是 9200 。
PATH
API 的终端路径(例如 _count 将返回集群中文档数量)。Path 可能包含多个组件,例如:_cluster/stats 和 _nodes/stats/jvm 。
QUERY_STRING
任意可选的查询字符串参数 (例如 ?pretty 将格式化地输出 JSON 返回值,使其更容易阅读)
BODY
一个 JSON 格式的请求体 (如果请求需要的话)
检查ES是否启动成功
curl http://localhost:9200
{
"name" : "Myhost",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "abtEL4GKRfulSwTfJ0wX5Q",
"version" : {
"number" : "7.2.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "508c38a",
"build_date" : "2019-06-20T15:54:18.811730Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
命令帮助
curl 'localhost:9200/_cat'
查看所有的 Index (v是用来要求结果返回表头)
curl 'localhost:9200/_cat/indices?v'
关闭索引库(支持批量)
curl 'localhost:9200/my-index*/_close'
打开索引库(支持批量)
curl 'localhost:9200/my-index*/_open'
检查集群状态
curl 'localhost:9200/_cat/health?v'
查看es集群配置
curl -X GET "localhost:9200/_cluster/settings?pretty"
查看指定索引库下文档数量
curl 'localhost:9200/_cat/count/my_book?v'
通配符查询某类索引库
curl 'localhost:9200/_cat/indices/my_*?v'
查看索引库的别名配置
curl 'localhost:9200/_aliases'
查看索引库的mapping配置
curl 'localhost:9200/my_book/_mapping'
查看索引库的mapping配置(格式化展示,pretty参数表示让结果以json格式输出展示)
curl 'localhost:9200/my_book/_mapping?pretty'
查看索引库的全量数据
curl 'localhost:9200/my_book/_search?pretty'
查看索引库的某一条文档数据
curl 'localhost:9200/my_book/1001?pretty'
根据条件搜索文档
curl -X POST "localhost:9200/alert*/_search?pretty" -H 'Content-Type:application/json' -d '{"query":{"match":{"_id":"66616090260607"}}}'
修改ES最大分片数
curl -XPUT -H "Content-Type:application/json" http://localhost:9200/_cluster/settings -d '{"transient":{"cluster":{"max_shards_per_node":10000}}}'
删除索引库
curl -X DELETE "localhost:9200/my_test_index01"
根据条件删除文索引库数据,以下以id为例
curl -X POST "localhost:9200/my_test_index01/_delete_by_query?pretty" -H 'Content-Type:application/json' -d '{"query":{"match":{"_id":"1001"}}}'
清空索引库
curl -X POST "localhost:9200/my_test_index01/_delete_by_query?pretty" -H 'Content-Type:application/json' -d '{"query":{"match_all":{}}}'
修改索引库字段内容
`curl -X POST "localhost:9200/my_test_index01/_update/1001?pretty" -H 'Content-Type:application/json' -d '{"doc":{"name":"蓝闪"}'
`
查看当前es线程组状态
curl -XGET "localhost:9200/_nodes/stats?pretty"
列出集群范围的设置(明确定义)
curl "localhost:9200/_cluster/settings"
以平面格式列出集群范围的设置(明确定义)
curl "localhost:9200/_cluster/settings?flat_settings&pretty"
列出集群范围的设置(包括默认值)
curl "localhost:9200/_cluster/settings?include_defaults&pretty"
以平面格式列出集群范围的设置(包括默认值)
curl "localhost:9200/_cluster/settings?include_defaults&flat_settings&pretty"
对熔断器状态进行监控
curl -XGET "localhost:9200/_nodes/stats/breaker?pretty&pretty"
查看每个数据节点上的分片数(shards),以及每个数据节点磁盘剩余
curl -XGET "localhost:9200/_cat/allocation?v"
获得每个节点的当前堆内存使用率
curl -XGET "localhost:9200/_cat/nodes?v=true&h=name,node*,heap*"
查看每个数据节点上被 fielddata 所使用的堆内存大小API
curl -XGET "localhost:9200/_cat/fielddata?v"
fielddata-按索引级别使用
curl -XGET "localhost:9200/_stats/fielddata?fields=* "
fielddata-按节点级别使用
curl -XGET "localhost:9200/_nodes/stats/indices/fielddata?fields=*"
fielddata-按索引节点级别使用
curl -XGET "localhost:9200/_nodes/stats/indices/fielddata?level=indices&fields=* "
查看segment数量
curl -XGET "localhost:9200/_cat/segments/test_segment?v&h=shard,segment,size,size.memory
查看一个node上所有segment占用的memory总和
curl -XGET "localhost:9200/_cat/nodes?v&h=name,port,sm&pretty"
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
ES一、简介1、ElasticStackES技术栈:ElasticSearch:存数据+搜索;QL;Kibana:Web可视化平台,分析。LogStash:日志收集,Log4j:产生日志;log.info(xxx)。。。。使用场景:metrics:指标监控…2、基本概念Index(索引)动词:保存(插入)名词:类似MySQL数据库,给数据Type(类型)已废弃,以前类似MySQL的表现在用索引对数据分类Document(文档)真正要保存的一个JSON数据{name:"tcx"}二、入门实战{"name":"DESKTOP-1TSVGKG","cluster_name":"elasticsear
我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption
我正在我的Rails项目中安装Grape以构建RESTfulAPI。现在一些端点的操作需要身份验证,而另一些则不需要身份验证。例如,我有users端点,看起来像这样:moduleBackendmoduleV1classUsers现在如您所见,除了password/forget之外的所有操作都需要用户登录/验证。创建一个新的端点也没有意义,比如passwords并且只是删除password/forget从逻辑上讲,这个端点应该与用户资源。问题是Grapebefore过滤器没有像except,only这样的选项,我可以在其中说对某些操作应用过滤器。您通常如何干净利落地处理这种情况?
在我做的一些网络开发中,我有多个操作开始,比如对外部API的GET请求,我希望它们同时开始,因为一个不依赖另一个的结果。我希望事情能够在后台运行。我找到了concurrent-rubylibrary这似乎运作良好。通过将其混合到您创建的类中,该类的方法具有在后台线程上运行的异步版本。这导致我编写如下代码,其中FirstAsyncWorker和SecondAsyncWorker是我编写的类,我在其中混合了Concurrent::Async模块,并编写了一个名为“work”的方法来发送HTTP请求:defindexop1_result=FirstAsyncWorker.new.async.
我有一个问题。我想从另一个ruby脚本运行一个ruby脚本并捕获它的输出信息,同时让它也输出到屏幕。亚军#!/usr/bin/envrubyprint"Enteryourpassword:"password=gets.chompputs"Hereisyourpassword:#{password}"我运行的脚本文件:开始.rboutput=`runner`putsoutput.match(/Hereisyour(password:.*)/).captures[0].to_s正如您在此处看到的那样,存在问题。在start.rb的第一行,屏幕是空的。我在运行程序中看不到“输入您的密
有这样的事吗?我想在Ruby程序中使用它。 最佳答案 试试这个http://csl.sublevel3.org/jp2a/此外,Imagemagick可能还有一些东西 关于ruby-是否有将图像文件转换为ASCII艺术的命令行程序或库?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6510445/
a=[3,4,7,8,3]b=[5,3,6,8,3]假设数组长度相同,是否有办法使用each或其他一些惯用方法从两个数组的每个元素中获取结果?不使用计数器?例如获取每个元素的乘积:[15,12,42,64,9](0..a.count-1).eachdo|i|太丑了...ruby1.9.3 最佳答案 使用Array.zip怎么样?:>>a=[3,4,7,8,3]=>[3,4,7,8,3]>>b=[5,3,6,8,3]=>[5,3,6,8,3]>>c=[]=>[]>>a.zip(b)do|i,j|c[[3,5],[4,3],[7,6],