美文网首页Java学习资料收集
centos7搭建ElasticSearch环境

centos7搭建ElasticSearch环境

作者: 普度众生的面瘫青年 | 来源:发表于2019-04-10 20:04 被阅读342次

linux环境: centos7
es版本:7.0.0
java版本:1.8
搭建filebeat
安装logstash

安装java环境

安装java环境

单独用户

  • 出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑, 需创建一个单独的用户用来运行ElasticSearch

增加组:groupadd esgroup
在组内增加用户:useradd esuser esgroup
删除组:groupdel 组名
删除用户:userdel 用户名
查看用户所属组:groups

  • 给用户增加sudo权限
    在root用户下

visudo 实际是打开/etc/sudoer文件
找到root ALL(ALL) ALL这行,在下一行增加
用户名 ALL(ALL) ALL

下载es

下载前切回esuser用户

su esuser
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
tar -xvf elasticsearch-7.0.0-linux-x86_64.tar.gz
mv elasticsearch-7.0.0-linux-x86_64 elasticsearch-7.0.0
cd elasticsearch-7.0.0/bin/
./elasticsearch 即可启动

检验

  • curl 127.0.0.1:9200

{
"name" : "DLkUa_D",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "EqkNo-PMTKmTB4gygNW5SQ",
"version" : {
"number" : "5.5.1",
"build_hash" : "19c13d0",
"build_date" : "2017-07-18T20:44:24.823Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},
"tagline" : "You Know, for Search"
}

开放远程访问

默认情况下,Elastic 只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,然后重新启动 Elastic。

安装分词插件(默认是英文分词词,如字段是中文,需为其指定字段的字段文本和搜索词的中文分词器)

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-analysis-ik-7.0.0.zip
重新启动 Elastic,就会自动加载这个新安装的插件。
基本上,凡是需要搜索的中文字段,都要单独设置一下。

安装kibana

Kibana是一个为 ElasticSearch 提供的数据分析的 Web 接口。可使用它对日志进行高效的搜索、可视化、分析等各种操作。(注意kibana与elasticsearch的版本要一致)(暂不安装X-PACK)
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.0.0-linux-x86_64.tar.gz
tar -xzf kibana-7.0.0-linux-x86_64.tar.gz
cd kibana-7.0.0-linux-x86_64/
更改配置文件:vi ./config/kibana.yml

server.port: 5601
server.host: "192.168.242.121"
elasticsearch.hosts: ["http://192.168.242.121:9200"]

运行:./kibana-7.0.0-linux-x86_64/bin/kibana
在后台不输出日志的方式运行:nohup ./kibana-7.0.0-linux-x86_64/bin/kibana > /dev/null 2>&1 &
访问地址:http://localhost:5601

集群搭建

ElasticSearch集群搭建

安装es过程中可能出现的错误

  • 如提示
    AccessDeniedException: /usr/local/es/elasticsearch-7.0.0/config/elasticsearch.yml
    则切到root用户赋予该用户对这个文件的读权限
chown esuser  /usr/local/es/elasticsearch-5.5.1/config/elasticsearch.yml -R
  • 如提示
    AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
    则改变elasticsearch文件夹所有者到当前用户
sudo chown -R esuser:esgroup elasticsearch-7.7.0/
  • 如提示
    max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    sudo vi /etc/sysctl.conf
    添加下面配置:
vm.max_map_count=655360 单个jvm能开启的最大线程数

并执行命令:

sudo sysctl -p
  • 如提示
    the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured(该问题在安装5.5.1时未遇到,7.0.0时遇到了)
vi ./config/elasticsearch.yml

#cluster.initial_master_nodes: ["node-1", "node-2"]

修改为

cluster.initial_master_nodes: ["node-1"] 
  • 如提示
    max number of threads [3795] for user [esuser] is too low, increase to at least [4096]
    linux最大线程数(ulimit -u可以查看)
root用户下进行: cat /etc/security/limits.d/20-nproc.conf
注释这两行:(最前面加#)
* soft nproc 2048
root soft nproc unlimited
在后面加四行:
*  soft nproc 5000
*  hard nproc 5000
root soft nproc 5000
root hard nproc 5000
  • 如提示
    max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
sudo vi /etc/security/limits.conf   用户最大打开文件数(ulimit -n可以查看)

添加如下内容:

soft nofile 65536
hard nofile 131072
soft nproc 2048
hard nproc 4096
sudo vi /etc/pam.d/common-session

添加如下内容:

session required pam_limits.so
sudo vi /etc/pam.d/common-session-noninteractive

添加如下内容:

session required pam_limits.so

修改/etc/profile增加一条

ulimit -n 65536

重启sshd服务

/etc/init.d/sshd restart

重新登陆es用户

  • 本地可以访问外网无法访问
    关闭或配置 selinux和防火墙

相关文章

网友评论

    本文标题:centos7搭建ElasticSearch环境

    本文链接:https://www.haomeiwen.com/subject/axfniqtx.html