Elasticsearch、kibana、elasticsearch-head安装

Linux下安装Elasticsearch

1.下载

官网下载地址: https://www.elastic.co/cn/downloads/elasticsearch
选择合适的版本下载,然后上传到Linux中,这里我选择的是 elasticsearch-7.10.0

也可以在Linux命令行,直接执行以下命令进行下载(下载比较慢):

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-linux-x86_64.tar.gz

执行解压缩命令:

tar -zxvf elasticsearch-7.10.0-linux-x86_64.tar.gz -C /usr/local

2.解决遇到的问题

2.1 es强依赖jdk问题

由于es和jdk是一个强依赖的关系,所以当我们在新版本的ElasticSearch压缩包中包含有自带的jdk,但是当我们的Linux中已经安装了jdk之后,就会发现启动es的时候优先去找的是Linux中已经装好的jdk,此时如果jdk的版本不一致,就会造成jdk不能正常运行,报错如下:

注:如果Linux服务本来没有配置jdk,则会直接使用es目录下默认的jdk,反而不会报错

warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_291/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.

解决方法

  • 进入bin目录
cd /usr/local/elasticsearch-7.10.0/bin
  • 修改elasticsearch配置
vim ./elasticsearch
############## 添加配置解决jdk版本问题 ##############
# 将jdk修改为es中自带jdk的配置目录
export JAVA_HOME=/usr/local/elasticsearch-7.10.0/jdk
export PATH=$JAVA_HOME/bin:$PATH

if [ -x "$JAVA_HOME/bin/java" ]; then
        JAVA="/usr/local/elasticsearch-7.10.0/jdk/bin/java"
else
        JAVA=`which java`
fi

内存不足问题

由于 elasticsearch 默认分配 jvm空间大小为2g,修改 jvm空间,如果Linux服务器本来配置就很高,可以不用修改。

error:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c6a00000, 962592768, 0) failed; error='Not enough space' (errno=12)
        at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
        at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
        at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
        at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:13

进入config文件夹开始配置,编辑jvm.options:

vim /usr/local/elasticsearch-7.10.0/config/jvm.options
默认配置如下:
-Xms2g
-Xmx2g
默认的配置占用内存太多了,调小一些:
-Xms256m
-Xmx256m

2.3 修改ES核心配置信息

  • 执行命令修改elasticsearch.yml文件内容
    vim /usr/local/elasticsearch-7.10.0/config/elasticsearch.yml

  • 修改数据和日志目录
    这里可以不用修改,如果不修改,默认放在elasticsearch根目录下

# 数据目录位置
path.data: /home/新用户名称/elasticsearch/data 
# 日志目录位置
path.logs: /home/新用户名称/elasticsearch/logs 
  • 修改绑定的ip允许远程访问
#默认只允许本机访问,修改为0.0.0.0后则可以远程访问
# 绑定到0.0.0.0,允许任何ip来访问
network.host: 0.0.0.0 
  • 初始化节点名称
cluster.name: elasticsearch 
node.name: es-node0
cluster.initial_master_nodes: ["es-node0"]
  • 修改端口号(非必须)
http.port: 19200
  • 在文件末尾追加,允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

2.4创建专用的用户启动es

root用户不能直接启动Elasticsearch,所以需要创建一个专用用户,来启动ES

java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:101)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:168)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)
        at org.elasticsearch.cli.Command.main(Command.java:79)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81)
  1. 创建用户
    useradd user-es

  2. 创建所属组:
    chown user-es:user-es -R /usr/local/elasticsearch-7.10.0

  3. 切换到user-es用户
    su user-es

  4. 进入bin目录
    cd /usr/local/elasticsearch-7.10.0/bin

  5. 启动elasticsearch
    ./elasticsearch

2.5 vm.max_map_count [65530] is too low问题

上面几个步骤依然没启动成功,继续解决问题:

ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

elasticsearch用户拥有的内存权限太小,至少需要262144,解决办法:
/etc/sysctl.conf文件最后添加如下内容,即可永久修改

  • 切换到root用户
    执行命令:su root

  • 执行命令
    vim /etc/sysctl.conf

  • 添加如下内容
    vm.max_map_count=262144

  • 保存退出,刷新配置文件
    sysctl -p

  • 切换user-es用户,继续启动
    su user-es

  • 启动es服务
    /usr/local/elasticsearch-7.10.0/bin/elasticsearch

启动成功后,可以通过http://127.0.0.1:19200/访问,如果出现以下内容,说明ES安装成功:

2.6 可能遇到的max file descriptors [4096]问题

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

切换到root用户,执行命令:
vi /etc/security/limits.conf

添加如下内容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

2.7ES服务的启动与停止

  • 前台运行,Ctrl + C 则程序终止
    /usr/local/elasticsearch-7.10.0/bin/elasticsearch

  • 后台运行
    /usr/local/elasticsearch-7.10.0/bin/elasticsearch -d
    出现started时启动完成

  • 关闭ES服务
    kill pid

  • 说明:
    Elasticsearch端口9300、9200,其中:
    9300是tcp通讯端口,集群ES节点之间通讯使用,9200是http协议的RESTful接口

2.8为Elasticsearch设置登录密码

ES7.x以后的版本将安全认证功能免费开放了,并将X-pack插件集成了到了开源的ElasticSearch版本中。下面将介绍如何利用X-pack给ElasticSearch相关组件设置用户名和密码。

  • 编辑配置文件
    vim /usr/local/elasticsearch-7.10.0/config/elasticsearch.yml

  • 在 elasticsearch.yml 末尾,加入以下内容:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
  • 编辑内容后重启Elasticsearch服务(必须操作)

  • 设置用户名和密码
    /usr/local/elasticsearch-7.10.0/bin/elasticsearch-setup-passwords interactive
    这里依次设置elastic、kibana、logstash等的访问密码,test123

Linux下安装kibana

Kibana 是 Elasticsearch 可视化工具,为 Elasticsearch 中索引的数据提供搜索和数据可视化功能

1.下载

下载链接 https://www.elastic.co/cn/downloads/past-releases/kibana-7-10-0

将其上传到服务器上,进行解压
tar -xzvf kibana-7.10.0-linux-x86_64.tar.gz

2、编辑配置文件

vi /usr/local/kibana-7.10.0-linux-x86_64/config/kibana.yml

##端口
server.port: 5601
##ip
server.host: "192.169.3.41"
##es服务地址
elasticsearch.hosts: ["http://192.169.3.41:9101","http://192.169.3.41:9102","http://192.169.3.41:9103"]
##索引名
kibana.index: ".kibana"
#连接elasticsearch的用户名和密码
elasticsearch.username: "kibana_system"
elasticsearch.password: "123qwe"
#支持中文
i18n.locale: "zh-CN"

说明: kibana连接elasticsearch的密码是下图这里设置的密码
在这里插入图片描述

3.启动kibana

kibana不能用root用户启动,这里以普通用户es启动

chown -R user-es:user-es /usr/local/kibana-7.10.0-linux-x86_64 //赋权

su user-es -c “/usr/local/kibana-7.10.0-linux-x86_64/bin/kibana &” //启动

Linux安装elasticsearch-head插件

X、安装node

X.1 下载node

首先需要安装node,如果已安装,可以忽略
这里node版本为 14.15.0
下载地址:https://nodejs.org/dist/v14.15.0/

X.2、解压、改目录名字、查看版本

解压tar -xvf node-v14.15.1-linux-x64.tar.xz

改目录名:
mv /usr/local/node-v14.15.1-linux-x64 /usr/local/node
mv命令用来修改名字或移动文件的

查看版本(./代表从当前目录找)
./node -v
./npm -v(需要配环境变量)

配环境变量
vi /etc/profile
最后加上这句话:export PATH=$PATH:/usr/local/node/bin
让新加的配置生效:source /etc/profile

配软连接:
相当于全局变量,在任何文件夹都能查看版本信息
ln -s /usr/local/node/bin/node /usr/local/bin/
ln -s /usr/local/node/bin/npm /usr/local/bin/

查看版本信息:
node -v
npm -v

1、下载

项目地址
https://github.com/mobz/elasticsearch-head
下载项目到本地,解压上传到服务器

2、安装执行

切换到elasticsearch-head(或者elasticsearch-head-master)目录下
cd /home/soft/elasticsearch-head-master/

修改端口
vi Gruntfile.js
在文件中的这个位置添加

 connect: {
                        server: {
                                options: {
                                        port: 9100,
                                        base: '.',
                                        keepalive: true
                                }
                        }
                }

添加后为

connect: {
			server: {
				options: {
					hostname:"*",
					port: 9100,
					base: '.',
					keepalive: true
				}
			}
		}

执行 npm install 命令

执行 npm run start 运行es-head

3、问题

cal/es-head/node_modules/phantomjs-prebuilt/lib/phantom'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'link',
  path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1578587768528/phantomjs-2.1.1-linux-x86_64',
  dest: '/usr/local/es-head/node_modules/phantomjs-prebuilt/lib/phantom'
} Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1578587768528/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/es-head/node_modules/phantomjs-prebuilt/lib/phantom'
npm WARN notsup Unsupported engine for karma@1.3.0: wanted: {"node":"0.10 || 0.12 || 4 || 5 || 6"} (current: {"node":"12.14.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: karma@1.3.0
npm WARN notsup Unsupported engine for http2@3.3.7: wanted: {"node":">=0.12.0 <9.0.0"} (current: {"node":"12.14.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: http2@3.3.7
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
 
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-01-09T16_36_15_862Z-debug.log

解决

 
#下载
wget https://npm.taobao.org/mirrors/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2
#加入环境变量
vim /etc/profile
#末尾加入,注意文件路径
export PATH=$PATH:/usr/local/phantomjs-2.1.1-linux-x86_64/bin
#执行
source /etc/profile

回到项目目录后, rm -rf ./node_modules 后再次执行 npm install --unsafe-perm。
完美解决!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

龘龍龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值