阿里云 centos yum 安装 Elasticsearch

安装java环境

  • 先看下本机是否已经安装,Elasticsearch最低支持java1.7
yum list installed |grep java
  • 如果没有安装请先安装,查看yum库中的java安装包
yum -y list java*
  • 安装java-1.8.0
yum -y install java-1.8.0-openjdk*
  • 安装完成后查看java版本
[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

  • 下载并安装ES的yum公钥
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
  • 配置Elasticsearch的yum源
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的缓存
yum makecache
  • 安装 Elasticsearch
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"
}
  • ip访问、外网访问、修改端口
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
  • 如何查看软件安装路径
rpm -qa|grep elasticsearch   #查找elasticsearch的安装包
rpm -ql elasticsearch-2.4.6-1.noarch #查找安装包的安装路径
打赏

Categories:

Tags: //

发表评论

电子邮件地址不会被公开。