Centos 7上安装Java 8.x,Elasticsearch 5.x

这次我安装的是最新的Centos 7.3,装的是最小的安装包,所以得自己安装所有的常用工具,运行下面的命令:

yum -y install gcc gcc-c++ net-tools wget zip unzip telnet

1. Java 安装
命令行下载 JDK 有个麻烦的地方,必须先要接受 Oracle 的许可协议,不过可以通过设置 cookie 来解决。
cd /usr/local
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz

直接解压 tar -zxvf jdk-8u121-linux-x64.tar.gz 后,配置环境变量:

设置环境变量
vi /etc/profile
# set java environment
export JAVA_HOME=/usr/local/jdk1.8.0_121
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}

保存后运行 source /etc/profile  使环境变量生效
输入 java -version 确认是否安装成功。

2. 安装 Elasticsearch
cd /usr/local
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.1.tar.gz
tar -zxvf elasticsearch-5.2.1.tar.gz
mv elasticsearch-5.2.1 elasticsearch

添加专门的用户,elasticsearch不支持用root用户启动服务。
useradd elastic
chown -R elastic:elastic elasticsearch
su elastic
sh /usr/local/elasticsearch/bin/elasticsearch -d

查看进程:
ps -ef | grep elasticsearch

服务默认只对本机服务,要对外服务,需要去掉下面两行的注释:
vi /usr/local/elasticsearch/config/elasticsearch.yml
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.1.102
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
Posted by 何敏 on 2017-02-25 21:14:17