Linux安装elasticsearch6.7.2

Linux安装elasticsearch6.7.2

安装步骤

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

1、下载安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.2.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.2.rpm.sha512
2、比较下载的RPM的SHA

后者应该输出elasticsearch-{version}.RPM:OK。

shasum -a 512 -c elasticsearch-6.7.2.rpm.sha512 
3、使用rpm方式安装
rpm -ivh elasticsearch-6.7.2.rpm
	#RPM 包采用系统默认的安装路径
	#rpm安装不建议自定义路径
	#路径	说明
	#/usr/bin	普通可执行程序文件目录
	#/usr/sbin	服务器执行程序文件和管理程序文件目录
	#/etc	应用程序配置文件(安装目录)
	#/var/log	日志文件目录
	#/usr/share/doc	应用程序文档文件目录
	#/usr/share/man	应用程序手册页文件目录
	#/usr/lib	程序使用的动态函数库目录
4、加入开机自启动
sudo chkconfig --add elasticsearch
5、启动
sudo service elasticsearch start
6、创建日志和数据存放文件夹
mkdir -p /home/es/data
mkdir -p /home/es/log/elasticsearch
7、为elasticsearch用户赋予文件夹权限

(执行rpm安装时,会自动创建elasticsearch用户和组)

sudo chown -R elasticsearch:elasticsearch /home/es/data
sudo chmod -R 777 /home/es/data
sudo chown -R elasticsearch:elasticsearch /home/es/log/elasticsearch
sudo chmod -R 777 /home/es/log/elasticsearch
sudo chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/
sudo chmod -R 777 /usr/share/elasticsearch/
sudo chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
sudo chmod -R 777 /var/lib/elasticsearch
8、编辑ElasticSearch的服务文件
启动之前为elasticsearch配置jdk
vim /etc/sysconfig/elasticsearch 中修改JAVA_HOME路径的路径
指定JAVA_HOME位置
        8 # Elasticsearch Java path
        9 #JAVA_HOME=
        10 JAVA_HOME=/opt/jdk1.8.0_121
9、修改es配置文件
cd  /etc/elasticsearch/
#备份
mv elasticsearch.yml elasticsearch.yml.bak20230530
vim /etc/elasticsearch/elasticsearch.yml

10、修改jvm内存大小
vi ./config/jvm.options
# 内存占用
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

配置文件详解

#集群名称
cluster.name: huaming
#节点名称
node.name: hm-node
# 数据存储位置(单个目录设置)
path.data: /home/es/data
#日志文件的路径
path.logs: /home/es/log/elasticsearch
bootstrap.system_call_filter: false
# ---------------------------------- Network -----------------------------------
# #
# # 设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0 
network.bind_host: 0.0.0.0 #只有本机可以访问http接口
#
# # 设置其它节点和该节点交互的ip地址,如果不设置它会自动设置,值必须是个真实的ip地址 (可以不配)
# # network.publish_host: 
#
# # 同时设置bind_host和publish_host上面两个参数 (当前使用)
network.host: 0.0.0.0 #绑定监听IP
#
# # 设置节点间交互的tcp端口,默认是9300 
transport.tcp.port: 9300 
#
# # 设置是否压缩tcp传输时的数据,默认为false,不压缩
transport.tcp.compress: true 
#
# # 设置对外服务的http端口,默认为9200 
http.port: 9200 
#
# # 设置请求内容的最大容量,默认100mb 
http.max_content_length: 100mb 
#
# # 使用http协议对外提供服务,默认为true,开启 
http.cors.enabled: true

es常用命令

查看状态:service elasticsearch status

重启:service elasticsearch restart

启动:service elasticsearch start

停止:service elasticsearch stop

查看是否启动成功:curl 127.0.0.1:9200

查看集群健康状态:curl -XGET 'http://192.168.1.139:9200/_cat/health?v'

查看集群健康状态:curl -XGET 'http://192.168.1.139:9200/_cat/health?v'
curl -XGET 'http://192.168.1.139:9200/_cat/shards'
curl http://192.168.1.139:9200/_cluster/health\?pretty
curl http://192.168.1.139:9200/_nodes/process?pretty

curl http://192.168.1.139:9200/_cluster/allocation/explain?pretty

卸载elasticsearch

卸载:
# 查询rpm安装的elasticsearch
rpm -qa | grep elasticsearch;
# rpm卸载elasticsearch,elasticsearch-6.7.2-1.noarch名称 需要根据查询上一步查询结果来
rpm -e --nodeps elasticsearch-6.7.2-1.noarch;
# 删除残留文件
rm -rf /etc/elasticsearch;
# 删除elasticsearch自定义文件
rm -rf /usr/share/elasticsearch/



[root@51mm-webserver ~]# rpm -qa |grep elasticsearch
elasticsearch-6.7.2-1.noarch
[root@51mm-webserver ~]# rpm -qa |grep elasticsearch
elasticsearch-6.7.2-1.noarch
[root@51mm-webserver ~]# rpm -e  --nodeps elasticsearch
Stopping elasticsearch service...停止 elasticsearch:[确定]
 OK
warning: /etc/sysconfig/elasticsearch saved as /etc/sysconfig/elasticsearch.rpmsave
warning: /etc/elasticsearch/jvm.options saved as /etc/elasticsearch/jvm.options.rpmsave
warning: /etc/elasticsearch/elasticsearch.yml saved as /etc/elasticsearch/elasticsearch.yml.rpmsave
Deleting log directory... OK
Deleting plugins directory... OK
[root@51mm-webserver ~]# rpm -qa |grep elasticsearch

安装ik分词器

方式1
使用 elasticsearch-plugin 安装
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.2/elasticsearch-analysis-ik-6.7.2.zip

方式2
从此处下载预构建包:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.2/elasticsearch-analysis-ik-6.7.2.zip

创建插件文件夹cd your-es-root/plugins/ && mkdir ik

将插件解压到文件夹your-es-root/plugins/ik

词典配置

IKAnalyzer.cfg.xml可以位于{conf}/analysis-ik/config/IKAnalyzer.cfg.xml 或{plugins}/elasticsearch-analysis-ik-*/config/IKAnalyzer.cfg.xml

安装es时的错误

1、which: no java in (/sbin:/usr/sbin:/bin:/usr/bin) Could not find any executable java binary. Please install java in your PATH or

which: no java in (/sbin:/usr/sbin:/bin:/usr/bin) Could not find any executable java binary. Please install java in your PATH or 

解决:elasticsearch用户没有es安装根路径的权限

2、ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
原因:无法创建本地文件,用户最大可创建文件数不够
解决:vim /etc/security/limits.conf
*                hard    nofile          65536
*                soft    nofile          65536
*                soft    nproc           65536
*                hard    nproc           65536

3、max number of threads [1024] for user [es] is too low, increase to at least [2048]

max number of threads [1024] for user [es] is too low, increase to at least [2048]
原因:无法创建本地线程问题,用户最大可创建线程数太小
解决:vim /etc/security/limits.d/90-nproc.conf
* soft nproc 2048(这边原本是1024)or * soft nproc 4096

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

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:最大虚拟内存太小
解决:vim /etc/sysctl.conf 添加下面这一行
vm.max_map_count=262144
并执行命令:sysctl -p

5、system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
原因:Centos6不支持SecComp
解决:vim elasticsearch.yml  切记在内存锁的下面加
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

6、elasticsearch 已死,但是 subsys 被锁

[root@51mm-webserver elasticsearch]# service elasticsearch status
elasticsearch 已死,但是 subsys 被锁
解决办法:
rm -f /var/lock/subsys/elasticsearch

创建索引

curl -XPUT http://localhost:9200/index

创建映射
curl -XPUT http://localhost:9200/index -H 'Content-Type:application/json' -d'
{
  "mappings": {
    "_doc": {
      "properties": {
        "id": { "type": "integer" },
        "countryCodes": { "type": "integer" },
        "phoneNumber": { "type": "keyword" },
        "userName": {
          "type": "text",
          "analyzer": "ik_max_word",
          "search_analyzer": "ik_smart"
        },
        "pwd": { "type": "keyword" },
        "email": { "type": "keyword" },
        "nickName": {
          "type": "text",
          "analyzer": "ik_max_word",
          "search_analyzer": "ik_smart"
        },
        "headImage": { "type": "keyword" },
        "isDelete": { "type": "integer" },
        "invitationCode": { "type": "keyword" },
        "remark": { "type": "keyword" },
        "source": { "type": "integer" },
        "createTime": { "type": "date" },
        "updateTime": { "type": "date" }
      }
    }
  }
}'

SpringBoot集成elasticsearch

pom依赖

这里只添加了主要的依赖,其他的如web、mvc、test、json等依赖自行添加

        <!-- springboot集成elasticsearch的依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <!--es客户端-->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>6.7.2</version>
        </dependency>

配置文件:

  #elasticsearch配置
  data:
    elasticsearch:
      cluster-name: 你的集群名称
      cluster-nodes: 你的ip:你的端口(9300)

实现ElasticsearchRepository

public interface InsuranceProductDao extends ElasticsearchRepository<InsuranceProductEntity,Integer> {
}

调用InsuranceProductDao接口中的方法即可实现增删改查

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 您可以参考官方文档来安装Elasticsearch:https://www.elastic.co/guide/cn/elasticsearch/reference/current/install-elasticsearch.html。 ### 回答2: 要在Linux安装Elasticsearch,可以按照以下步骤进行: 1. 首先,确保已经安装Java Runtime Environment(JRE),因为Elasticsearch是用Java编写的。可以通过运行命令`java -version`来验证JRE的安装情况。 2. 接下来,前往Elasticsearch的官方网站(https://www.elastic.co/products/elasticsearch)下载适用于Linux安装包。根据你的系统架构选择下载64位或32位版本。 3. 下载完成后,解压缩压缩包。可以使用命令`tar -xf elasticsearch-x.x.x.tar.gz`来解压缩。这将会创建一个名为elasticsearch-x.x.x的目录。 4. 进入解压后的目录,然后打开config文件夹,编辑elasticsearch.yml文件,根据你的需求进行必要的配置更改,如监听端口、集群名称等。 5. 保存并关闭elasticsearch.yml文件后,你可以启动Elasticsearch。在命令行中切换到elasticsearch-x.x.x目录,然后运行`./bin/elasticsearch`命令。 6. 启动后,Elasticsearch会在后台运行,并通过默认端口9200提供RESTful API接口。可以通过在浏览器中访问`http://localhost:9200`来验证安装成功。 以上就是在Linux安装Elasticsearch的基本步骤。根据具体情况,还可以进行其他配置(如内存限制、集群配置等),以满足特定需求。 ### 回答3: 要在Linux安装Elasticsearch,首先需要确保你的系统满足所需的要求。Elasticsearch需要Java环境,因此请确保你已经安装Java Development Kit(JDK)。 安装步骤如下: 1. 首先,更新你的系统: sudo apt update 2. 安装JDK: sudo apt install default-jdk 3. 验证JDK的安装java -version 如果能够打印出Java的版本信息,说明JDK已经正确安装。 4. 下载Elasticsearch: 在Elasticsearch的官方网站上下载最新版本的压缩包,或者通过命令行下载: wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.4-linux-x86_64.tar.gz 5. 解压缩文件: tar -xzf elasticsearch-7.13.4-linux-x86_64.tar.gz 6. 进入解压缩后的目录: cd elasticsearch-7.13.4 7. 启动Elasticsearch: ./bin/elasticsearch Elasticsearch将会启动,并在后台运行。 8. 验证Elasticsearch安装: 使用curl命令或者浏览器访问以下URL来验证Elasticsearch是否成功启动: curl -X GET "http://localhost:9200" 如果能够得到类似下面的响应,说明Elasticsearch已经安装并运行正常: { "name" : "your-machine-name", "cluster_name" : "elasticsearch", "cluster_uuid" : "xxxxxx", "version" : { "number" : "7.13.4", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "xxxxxx", "build_date" : "xxxxxx", "build_snapshot" : false, "lucene_version" : "xxxxxx", "minimum_wire_compatibility_version" : "xxxxxx", "minimum_index_compatibility_version" : "xxxxxx" }, "tagline" : "You Know, for Search" } 恭喜!现在你已经成功在Linux安装Elasticsearch。你可以通过编辑配置文件`./config/elasticsearch.yml`来配置Elasticsearch的相关设置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值