ElasticSearch学习二 单节点安装
安装
下载
到ElasticSearch 官网下载相应的版本:https://www.elastic.co/cn/downloads/past-releases#elasticsearch
上传并解压
Alt + p 打开SecureCRT的SFTP,使用put命令,把本地的elasticsearch-7.4.2-linux-x86_64.tar.gz上传到Linux服务器。
创建安装目录,并解压
[root@localhost ~]# mkdir /usr/local/es
[root@localhost ~]# tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz -C /usr/local/es
解压后的目录:
.
├── bin
├── config
├── jdk
├── lib
├── LICENSE.txt
├── logs
├── modules
├── NOTICE.txt
├── plugins
└── README.textile
bin: 可执行目录
config:配置文件所在目录
jdk:jdk目录
lib:依赖的库
配置文件
[root@localhost config]# ll
总用量 40
-rw-rw----. 1 root root 199 4月 23 12:41 elasticsearch.keystore
-rw-rw----. 1 root root 2831 10月 29 2019 elasticsearch.yml
-rw-rw----. 1 root root 3593 10月 29 2019 jvm.options
-rw-rw----. 1 root root 17545 10月 29 2019 log4j2.properties
-rw-rw----. 1 root root 473 10月 29 2019 role_mapping.yml
-rw-rw----. 1 root root 197 10月 29 2019 roles.yml
-rw-rw----. 1 root root 0 10月 29 2019 users
-rw-rw----. 1 root root 0 10月 29 2019 users_roles
elasticsearch.yml
# ================= Elasticsearch configuration =================
cluster.name: icoding-course
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
#内部节点之间沟通端口
transport.tcp.port: 9700
cluster.initial_master_nodes: ["node-1"]
#如果是CentOS 6版本 加入以下两行
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
cluster.name:配置elasticsearch的集群名称,默认是elasticsearch。建议修改成一个有意义的名称
node.name:节点名,elasticsearch会默认随机指定一个名字,建议指定一个有意义的名称,方便管理
network.host:设置为0.0.0.0允许外网访问
http.port: Elasticsearch的http访问端口
cluster.initial_master_nodes:初始化新的集群时需要此配置来选举master
transport.tcp.port:内部节点之间沟通端口
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping_timeout: 60s
启动
[root@localhost bin]# clear
[root@localhost bin]# pwd
/usr/local/es/elasticsearch-7.4.2/bin
[root@localhost bin]# ./elasticsearch
报错分析
启动之后会报错,报错内容如下
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk8/jre] does not meet this requirement
[2022-04-23T12:43:15,796][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [localhost.localdomain] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.4.2.jar:7.4.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.4.2.jar:7.4.2]
... 6 more
警告:jdk
第一个其实不算报错,只是提示以后Elasticsearch会要求jdk11,我们在CLASSPATH配置的jdk版本时8
[root@localhost bin]# echo $JAVA_HOME
/usr/local/jdk8
在Elasticsearch的解压目录里面提供了一个相应版本的jdk,只需要在Elasticsearch的bin目录中的elasticsearch-env配置JAVA_HOME就行。
export JAVA_HOME=/usr/local/es/elasticsearch-7.4.2/jdk
报错:root用户
Elasticsearch是不允许以root用户的身份允许,因此我们需要创建一个es组与es用户
[root@localhost bin]# groupadd es
[root@localhost bin]# useradd es -g es
[root@localhost bin]# chown -Rf es:es /usr/local/es/
第一句:添加用户组 es
第二句:添加用户 es,并把es用户添加到es组
第三句:把/usr/local/es/目录的下所有文件和目录都归属到es组,es用户
从root用户切换到es用户,再次运行
su es
cd /usr/local/es/elasticsearch-7.4.2/bin
./elasticsearch
报警:回收器
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
在elasticsearch 的config目录下的jvm.options 文件中,把垃圾回收器配置一下。
## GC configuration
#-XX:+UseConcMarkSweepGC
-XX:+UseG1GC
警告:最大文件描述符
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
最大文件描述符的数量需要修改掉,不让后面远程访问ES会报错。
/etc/security/limits.conf
在limits.conf文件末尾添加如下配置:
es soft nofile 65535
es hard nofile 65535
因为我们是用es启动,因此需要修改es用户的
警告:最大线程数
max number of threads [3795] for user [es] is too low, increase to at least [4096]
es soft nproc 4096
es hard nproc 4096
因为我们是用es启动,因此需要修改es用户的
警告:默认发现配置
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
缺少默认配置,至少需要配置discovery.seed_hosts/discovery.seed_providers/cluster.initial_master_nodes中的一个参数.
-
discovery.seed_hosts: 集群主机列表
-
discovery.seed_providers: 基于配置文件配置集群主机列表
-
cluster.initial_master_nodes: 启动时初始化的参与选主的node,生产环境必填
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["192.168.2.135" ]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["192.168.2.135"]
警告:最大虚拟内存
linux的最大虚拟内存在
/etc/sysctl.conf 文件中修改
vm.max_map_count=262144
总结
#切换到root用户
su root
#1.===最大可创建文件数太小======
vi /etc/security/limits.conf
#在文件末尾中增加下面内容
icoding soft nofile 65536
icoding hard nofile 65536
#====
vi /etc/security/limits.d/90-nproc.conf
#在文件末尾中增加下面内容
icoding soft nofile 65536
icoding hard nofile 65536
* hard nproc 4096
#注:*代表Linux所有用户名称
#2.===最大虚拟内存太小====
vi /etc/sysctl.conf
#在文件中增加下面内容
vm.max_map_count=655360
#重新加载,输入下面命令:
sysctl -p
访问
本地访问
elasticsearch在解决完jdk报警,root用户等问题之后就可以本地访问。
启动完成之后,再打开一个连接
curl http://127.0.0.1:9200
会返回
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "lmX9-4cTRSysRkDIN8Ew2w",
"version" : {
"number" : "7.4.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
"build_date" : "2019-10-28T20:40:44.881551Z",
"build_snapshot" : false,
"lucene_version" : "8.2.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
远程访问
只是修改了jdk报警、root用户启动等问题,此是还是无法访问,需要修改config目录下的elasticsearch.yml
network.host: 0.0.0.0
修改完elasticsearch.yml之后,会把之前的三个警告信息变成三个报错信息
ERROR: [3] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] [2]: max number of threads [3795] for user [es] is too low, increase to at least [4096] [3]: 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
防火墙
按照报错分析中的步骤修复完之后,还需要让linux操作系统的防火墙放行9200端口
#查看开放了哪些服务端口
firewall-cmd --list-all
#开放端口号命令,永久生效
firewall-cmd --add-port=9200/tcp --permanent
#重启防火墙,使配置生效
systemctl restart firewalld.service
此是通过http://192.168.2.135:9200/就可以访问了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律