Linux搭建ES

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/86138441

前期准备:

更新源:

编辑sources.list,将kali更新源加入其中

sudo vim /etc/apt/sources.list

国内更新源
#阿里云

deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib 
deb-src http://mirrors.aliyun.com/kali kali-rolling main non-free contrib

更新源:apt-get update

1、apt-get update失败:
 wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add   

更新系统:apt full-upgrade

解决Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

sudo vim /etc/resolv.conf ,添加:

nameserver 8.8.8.8

然后执行:

sudo /etc/init.d/networking restart

安装vim:

apt-get install vim

安装Java(https://blog.csdn.net/smile_from_2015/article/details/80056297

配置完Java环境,执行: update-alternatives --config java

先看是否有openjdk,有的话卸载:apt-get remove openjdk* 

下载jdk:wget https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz?AuthParam=1547110418_02b2a308d6483a73ebc3d5604347ffff

安装elasticsearch:

1.进入elastic官网下载elasticsearch 点击打开链接,,选择tar,右键复制链接

2.进入命令行输入: wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.tar.gz 下载到当前目录

3.输入命令:tar -vxf elasticsearch-6.2.3.tar.gz 解压,此时会生成 elasticsearch-6.2.3 文件

4.输入:vi elasticsearch-6.2.3/config/jvm.options 修改Xms1g和Xmx1g这两个值,我修改的为 Xms512m和Xmx512m,若果 你内存够大,可以不用修改

进行elasticsearch.yml的配置,该文件位于config目录下,具体配置如下:

以下是配置集群,各属性配置说明,更多属性配置可自行添加
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
#集群名称
cluster.name: elastic_cluster
#
# ------------------------------------ Node ------------------------------------
#
#节点名称
node.name: node1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
#节点数据存放目录地址;默认是在ELASTICSEARCH _HOME/data下面,可自定义
#path.data: /path/to/data
#
#logs日志存放目录地址,可自定义
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#是否锁定内存,以下两个一般设置为false
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#指定本机IP地址,自行修改为本机ip
network.host: 192.168.0.1
#指定本机http访问端口
http.port: 9200
#指定节点是否有资格被选举为主节点;默认true
node.master: true
#指定节点是否存储索引数据;默认true
node.data: true
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#设置集群各节点的初始列表,默认第一个为主节点,如果不是配置集群,而是单机,以下参数可不进行配置
discovery.zen.ping.unicast.hosts: ["192.168.1.1", "192.168.1.2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#设置集群最大主节点数量;默认1,范围值为1-4
discovery.zen.minimum_master_nodes: 1
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#设置9200端口可以对外访问;比如head插件连es
http.cors.enabled: true
http.cors.allow-origin: "*"

5.然后进入bin文件夹输入:./elasticsearch 启动

如果出现上述错误则是说明:不能用root用户启动,这时我们需要换一个普通用户

6.创建一个用户: 输入:adduser elastic

7.输入 su elastic 登录elastic用户

8.进入elasticsearch-6.2.3 bin 目录,输入 ./elasticsearch 启动elastic

如若出现上述错误,则是elastic这个用户权限不足,这时我们可以输入 ls -l查看,会发现elasticsearch的权限为 root root,所以此时我们需要为elastic这个用户添加权限

9.切换为root用户回到elasticsearch-6.2.3文件夹父级目录执行命令: chown -R elastic elasticsearch-6.2.3

chgrp -R elsearch /work/elasticsearch-6.2.3

10.切换为elastic用户进入 elasticsearch-6.2.3 bin目录 输入:./elasticsearch 启动elasticsearch

如图所示:此时我们可以看出elasticSearch已经启动成功,我们可以出浏览器输入 127.0.0.1:9200进行一个验证

如图:启动成功

11. 停掉服务:按 Ctrl+c ;然后刷新浏览器已经不在显示,说明服务已停止

12.后台启动elasticsearch ,输入:./elasticsearch -d 启动elasticsearch; 稍等一会,可以再去浏览器进行验证,也可以输入

    ps aux|grep elasticsearch 命令进行查询

启动成功!
 

报错处理:

https://blog.csdn.net/u012246178/article/details/63253531    (主要问题解决方法)

https://www.cnblogs.com/yuluoxingkong/p/7886622.html

https://blog.csdn.net/u013641234/article/details/80792416

https://www.cnblogs.com/zhi-leaf/p/8484337.html

错误1:E: Sub-process /usr/bin/dpkg returned an error code (1)
https://www.cnblogs.com/nkh222/p/8126455.html


错误2:unable to load JNA native support library, native methods will be disabled.
https://blog.csdn.net/a_flying_bird/article/details/77657803

错误3:org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried
https://blog.csdn.net/u013641234/article/details/80792416

错误4:org.elasticsearch.bootstrap.StartupException: ElasticsearchException[X-Pack is not supported and Machine Learning is not available for [linux-aarch64]; you can use the other X-Pack features (unsupported) by setting xpack.ml.enabled: false in elasticsearch.yml]
https://blog.csdn.net/fanrenxiang/article/details/81358332

猜你喜欢

转载自blog.csdn.net/chaoyu168/article/details/86138441