安装java环境
- 先看下本机是否已经安装,Elasticsearch最低支持java1.7
yum list installed |grep java
- 如果没有安装请先安装,查看yum库中的java安装包
yum -y list java*
yum -y install java-1.8.0-openjdk*
[root@VM_145_20_centos ~]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
vim /etc/profile
- 在文件的末尾加上下面的代码,注意代码中的java-1.8.0*,请根据实际安装的来
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.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
- 检测一下,OK(额,我有强迫症哈哈),记得source 使配置文件生效
[root@VM_145_20_centos ~]# source /etc/profile
[root@VM_145_20_centos ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64
使用yum安装Elasticsearch
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
yum makecache
yum install elasticsearch
测试 Elasticsearch 是否安装成功
/sbin/chkconfig --add elasticsearch
systemctl start elasticsearch
[root@VM_145_20_centos ~]# curl -X GET localhost:9200
{
"name" : "Hyde",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "ji3aSaT4TAKuRO34a4twnQ",
"version" : {
"number" : "2.4.6",
"build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
"build_timestamp" : "2017-07-18T12:17:44Z",
"build_snapshot" : false,
"lucene_version" : "5.5.4"
},
"tagline" : "You Know, for Search"
}
vim /etc/elasticsearch/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
systemctl restart elasticsearch
- 浏览器中输入ip地址和端口访问试试,如果访问被拒绝,添加防火墙设置(我的阿里云服务器是需要设置的)
iptables -I INPUT -p tcp --dport 9200 -j ACCEPT