Elasticsearch 6.x 问题解决和添加验证

一、 为添加Elasticsearch添加账号

adduser elastic
chown -R elastic:elastic /usr/share/elasticsearch/

二、 es启动时可能出现如下问题

原因:linux中elasticsearch最大文件打开数太小,需要我们修改到对应的数值

错误1

max file descriptors [4096] for elasticsearch process is too low, increase to at

解决:
修改/etc/security/limits.conf文件,添加或修改如下行:

*        hard    nofile           65536
*        soft    nofile           65536
错误2

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改 /etc/sysctl.conf 文件,添加如下行:

vm.max_map_count=262144

修改好了以后,运行/sbin/sysctl -p

重启以后,再启动es即可,就可以通过主机ip访问。


三、调整内存大小

编辑elasticsearch/config/jvm.options

-Xms2g
-Xmx2g

四、head插件设置

  1. 不限制访问IP
    编辑head/Gruntfile.js
connect: {
    server: {
        options: {
            port: 9100,
            hostname: '*',  #此处设置
            base: '.',
            keepalive: true
        }
    }
}
  1. 修改head连接es的地址
    编辑head/_site/app.js,修改localhost为es服务器IP
    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";

五、添加认证

  1. 安装x-pack
bin/elasticsearch-plugin install x-pack
  1. 设置验证密码
    进入elasticsearch/bin/x-pack
./setup-passwords interactive

会对elasticsearch、logstash、kibana分别设置登录密码(默认es用户名为elastic,logstash用户名为logstash_system,kibana用户名为kibana)

elasticsearch/bin/x-pack$ ./setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,kibana,logstash_system.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]yes
Did not understand answer 'yes'
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [elastic]
  1. 设置elasticsearch配置文件
    编辑 elasticsearch/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: '*'
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
  1. head访问方式

http://localhost:9100/?base_uri=http://localhost:9200&auth_user=elastic&auth_password=password

  1. 命令行使用

curl -u elastic:blackey -XPUT http://10.2.197.69:9200/baidu -H 'Content-Type: application/json' -d '{}'


六、kibana添加认证

  1. 安装x-pack,文件有200多兆,很慢,耐心等待
./bin/kibana-plugin install x-pack
  1. 配置kibana配置文件
    修改如下配置信息
    注意:用户名和密码必须与之前x-pack设置的kibana账号密码一致
server.host: "0.0.0.0"
elasticsearch.url: "http://10.2.97.169:9200"   #10.2.97.169为es服务器IP地址
elasticsearch.username: "kibana"    # 用户名
elasticsearch.password: "password"   # 密码  
  1. 开启kibana
./bin/kibana     正常启动
./bin/kibana &   后台启动
  1. 登录kibana
    浏览器打开http://10.2.97.169:5601/
    输入步骤2中的账号密码即可
    如果想对之前用elastic账号导入的数据库操作,请使用elastic(用户名)、password(密码)登录
11.png

2.png

设置角色权限与添加用户

curl -u elastic:password -XPOST http://10.2.97.169:9200/_xpack/security/role/events_admin -H 'Content-Type: application/json' -d '{
  "indices" : [
    {
      "names" : [ "events*" ],
      "privileges" : [ "all" ]
    },
    {
      "names" : [ ".kibana*" ],
      "privileges" : [ "manage", "read", "index" ]
    }
  ]
}'

curl -u elastic:password -XPOST http://10.2.97.169:9200/_xpack/security/user/jack -H 'Content-Type: application/json' -d '{
  "password" : "123456",
  "full_name" : "test",
  "email" : "test@163.com",
  "roles" : [ "events_admin" ]
}'

  1. x-pack license过期
    启动ElasticSearch时提示:
[2017-06-20T09:54:43,462][ERROR][o.e.x.s.a.f.SecurityActionFilter] [_gHqs1e] blocking [cluster:monitor/stats] operation due to expired license. Cluster health, cluster stats and indices stats
operations are blocked on license expiration. All data operations (read and write) continue to work.
If you have a new license, please update it. Otherwise, please reach out to your support contact.

直接影响的后果是kibana web页无法�访问

是因为证书过期了,需要注册申请一个license.

申请地址: https://register.elastic.co/marvel_register

注册后将以email的方式发送,通过链接下载license json文件.

根据文档提示请求api并指定新的证书

$ curl -XPUT -u elastic:changeme 'http://192.168.2.110:9200/_xpack/license?acknowledge=true' -H "Content-Type: application/json" -d @hakim-zhao-705a2a54-84d9-4ea8-b4ca-23b9d75b4ead-v5.json
{"acknowledged":true,"license_status":"valid"}

查看最新证书状态:

$ curl --user elastic:changeme 'http://192.168.2.110:9200/_xpack/license'

{
  "license" : {
    "status" : "active",
    "uid" : "5-84d9-4ea8-b4ca-23b9d75b4ead",
    "type" : "basic",
    "issue_date" : "2017-06-20T00:00:00.000Z",
    "issue_date_in_millis" : 1497916800000,
    "expiry_date" : "2018-06-20T23:59:59.999Z",
    "expiry_date_in_millis" : 1529539199999,
    "max_nodes" : 100,
    "issued_to" : "hakim zhao (none)",
    "issuer" : "Web Form",
    "start_date_in_millis" : 1497916800000
  }
}

可以看到证书是自生效起有1年的使用期。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容