Centos7的安装系列

参考系列

安装ElasticSearch6.2.4

  1. 配置JDK环境

配置环境变量

export JAVA_HOME="/opt/jdk1.8.0_144"
export PATH="$JAVA_HOME/bin:$PATH"
export CLASSPATH=".:$JAVA_HOME/lib"

2.安装ElasticSearch6.2.4

下载地址:https://www.elastic.co/cn/downloads/elasticsearch

启动报错:


image.png

解决方式:

bin/elasticsearch -Des.insecure.allow.root=true

或者修改bin/elasticsearch,加上ES_JAVA_OPTS属性:

ES_JAVA_OPTS="-Des.insecure.allow.root=true"

再次启动:


image.png

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

创建用户组和用户:

groupadd esgroup

useradd esuser -g esgroup -p espassword

更改elasticsearch文件夹及内部文件的所属用户及组:

cd /opt

chown -R esuser:esgroup elasticsearch-6.2.4

切换用户并运行:

su esuser

./bin/elasticsearch

再次启动显示已杀死:


image.png

需要调整JVM的内存大小:

vi bin/elasticsearch

ES_JAVA_OPTS="-Xms512m -Xmx512m"

再次启动:启动成功

如果显示如下类似信息:

[INFO ][o.e.c.r.a.DiskThresholdMonitor] [ZAds5FP] low disk watermark [85%] exceeded on [ZAds5FPeTY-ZUKjXd7HJKA][ZAds5FP][/opt/elasticsearch-6.2.4/data/nodes/0] free: 1.2gb[14.2%], replicas will not be assigned to this node

需要清理磁盘空间。

后台运行:./bin/elasticsearch -d

测试连接:

curl 127.0.0.1:9200

会看到一下JSON数据:

 [root@localhost ~]# curl 127.0.0.1:9200
  {
  "name" : "rBrMTNx",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "-noR5DxFRsyvAFvAzxl07g",
  "version" : {
    "number" : "5.1.1",
    "build_hash" : "5395e21",
    "build_date" : "2016-12-06T12:36:15.409Z",
    "build_snapshot" : false,
    "lucene_version" : "6.3.0"
  },
  "tagline" : "You Know, for Search"
 }

实现远程访问:
需要对config/elasticsearch.yml进行 配置:

    network.host: 192.168.25.131

再次启动报错:


image.png

处理第一个错误:

vim /etc/security/limits.conf       //文件最后加入

esuser soft nofile 65536

esuser hard nofile 65536

esuser soft nproc 4096

esuser hard nproc 4096

处理第二个错误:

进入limits.d目录下修改配置文件。

vim /etc/security/limits.d/20-nproc.conf 

修改为 esuser soft nproc 4096

处理第三个错误:

vim /etc/sysctl.conf

vm.max_map_count=655360

执行以下命令生效:

sysctl -p

关闭防火墙:

systemctl stop firewalld.service

再次启动成功!

安装Head插件

Head是elasticsearch的集群管理工具,可以用于数据的浏览和查询

  1. elasticsearch-head是一款开源软件,被托管在github上面,所以如果我们要使用它,必须先安装git,通过git获取elasticsearch-head

  2. 运行elasticsearch-head会用到grunt,而grunt需要npm包管理器,所以nodejs是必须要安装的

  3. elasticsearch5.0之后,elasticsearch-head不做为插件放在其plugins目录下了。
    使用git拷贝elasticsearch-head到本地

cd /usr/local/
git clone git://github.com/mobz/elasticsearch-head.git
  1. 安装elasticsearch-head依赖包
[root@localhost local]# npm install -g grunt-cli

[root@localhost _site]# cd /usr/local/elasticsearch-head/

[root@localhost elasticsearch-head]# cnpm install
  1. 修改Gruntfile.js
[root@localhost _site]# cd /usr/local/elasticsearch-head/

[root@localhost elasticsearch-head]# vi Gruntfile.js

在connect-->server-->options下面添加:hostname:’*’,允许所有IP可以访问

  1. 修改elasticsearch-head默认连接地址
[root@localhost elasticsearch-head]# cd /usr/local/elasticsearch-head/_site/

[root@localhost _site]# vi app.js

将this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";中的localhost修改成你es的服务器地址

  1. 配置elasticsearch允许跨域访问

打开elasticsearch的配置文件elasticsearch.yml,在文件末尾追加下面两行代码即可:

http.cors.enabled: true

http.cors.allow-origin: "*"
  1. 打开9100端口
[root@localhost elasticsearch-head]# firewall-cmd --zone=public --add-port=9100/tcp --permanent

重启防火墙

[root@localhost elasticsearch-head]# firewall-cmd --reload
  1. 启动elasticsearch

  2. 启动elasticsearch-head

[root@localhost _site]# cd /usr/local/elasticsearch-head/

[root@localhost elasticsearch-head]# node_modules/grunt/bin/grunt server
  1. 访问elasticsearch-head

关闭防火墙:

systemctl stop firewalld.service

浏览器输入网址:http://192.168.25.131:9100/

安装Kibana

Kibana是一个针对Elasticsearch的开源分析及可视化平台,使用Kibana可以查询、查看并与存储在ES索引的数据进行交互操作,使用Kibana能执行高级的数据分析,并能以图表、表格和地图的形式查看数据

  1. 下载Kibana
    https://www.elastic.co/downloads/kibana

  2. 把下载好的压缩包拷贝到/soft目录下

  3. 解压缩,并把解压后的目录移动到/user/local/kibana

  4. 编辑kibana配置文件

[root@localhost /]# vi /usr/local/kibana/config/kibana.yml
image.png

将server.host,elasticsearch.url修改成所在服务器的ip地址

  1. 开启5601端口

Kibana的默认端口是5601

开启防火墙: systemctl start firewalld.service

开启5601端口: firewall-cmd --permanent --zone=public --add-port=5601/tcp

重启防火墙:firewall-cmd –reload

  1. 启动Kibana
[root@localhost /]# /usr/local/kibana/bin/kibana

浏览器访问:http://192.168.25.131:5601

安装中文分词器

  1. 下载中文分词器
    https://github.com/medcl/elasticsearch-analysis-ik

    下载elasticsearch-analysis-ik-master.zip

  2. 解压elasticsearch-analysis-ik-master.zip

    unzip elasticsearch-analysis-ik-master.zip

  3. 进入elasticsearch-analysis-ik-master,编译源码

mvn clean install -Dmaven.test.skip=true 
  1. 在es的plugins文件夹下创建目录ik

  2. 将编译后生成的elasticsearch-analysis-ik-版本.zip移动到ik下,并解压

  3. 解压后的内容移动到ik目录下

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容