2020年10月6日00:31:26
1,注意elasticsearch和java的版本关系
https://www.elastic.co/cn/support/matrix#matrix_jvm
2,安装jdk,这里因为是elasticsearch7.x所以必须是java11以上的版本
yum search java | grep -i --color JDK
yum install java-1.8.0-openjdk-devel.x86_64
yum install java-11-openjdk.x86_64
如果有其他版本最好删除,避免意外的问题
vi /etc/profile
在最后面追加
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.8.10-0.el8_2.x86_64 export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin
注意去/usr/lib/jvm/ 查看具体的版本
source /etc/profile
java -version
3,下载elasticsearch
官方下载地址: https://www.elastic.co/cn/downloads/elasticsearch
//artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz
这里最后使用其他工具下载,然后上传上去,有点大300多M
LINUX X86_64版本
如果你想yum安装
vi /etc/yum.repos.d/
elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
yum install --enablerepo=elasticsearch elasticsearch
4,启动elasticsearch
tar -zxvf elasticsearch-7.9.2-linux-x86_64.tar.gz
mv elasticsearch-7.9.2 elasticsearch
mv elasticsearch /usr/local/
cd /usr/local/elasticsearch
bin目录下面启动
./elasticsearch
测试:http://192.168.3.15:9200/
返回的是一个json
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "9fLpa7KBTD6nExFBGALYwA",
"version" : {
"number" : "7.9.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d34da0ea4a966c4e49417f2da2f244e3e97b4e6e",
"build_date" : "2020-09-23T00:45:33.626720Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
你也可以使用es的可视化插件 elasticsearch-head
5,启动可能遇到的问题
5.1,can not run elasticsearch as root 不能以root运行
useradd es
passwd es
chown -R es:es /usr/local/elasticsearch
su es
5.2 开放远程访问
vi conf/elasticsearch.yml
修改 network.host 为 0.0.0.0
network.host: 0.0.0.0
1
配置cluster.initial_master_nodes为当前node,默认为注释,放开注释就行了
cluster.initial_master_nodes: ["node-1", "node-2"]
5.3 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
network.host: 0.0.0.0 #改为0.0.0.0对外开放,如对特定ip开放则改为指定ip
http.port: 9200 #可更改端口不为9200
启动的话可能会报错
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:
1、切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
5.4 Option UseConcMarkSweepGC was deprecated in version 9.0
将jvm.options文件里的内容修改为:
-XX:+UseConcMarkSweepGC 改为 -XX:+UseG1GC
5.5 内存太小
cd 到es目录修改 ./config/jvm.options:
vim ./config/jvm.options
1
修改该内容:
-Xms1G
-Xmx1G
5.6 安装 ElasticHD 这个ui更好看点
下载地址: https://github.com/360EntSecGroup-Skylar/ElasticHD/releases
选择 https://github.com/360EntSecGroup-Skylar/ElasticHD/releases/download/1.4/elasticHD_linux_amd64.zip
and64架构的
1. unzip elasticHD_linux_amd64.zip
2. 修改权限:chmod -R 777 ElasticHD
3. 运行: ./ElasticHD -p 127.0.0.1:9800
如果你想开启远程访问,启动命令改为:
运行: ./ElasticHD -p 0.0.0.0:9800
访问
ip:9800
ElasticHD可以独立运行不依赖其他组件运行,还可以连接不同的elasticsearch,非常方便