【Elasticsearch】安装

安装Java

elasticsearch的运行需要依赖java,需要先将java安装好并添加JAVA_HOME环境变量;
否则,仅安装elasticsearch运行会报错:

[root@localhost bin]# ./elasticsearch
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
[root@localhost bin]# 

下载安装java

yum install java-1.8.0-openjdk
yum install java-1.8.0-openjdk-devel.x86_64

输入以下命令找到java的安装路径

[root@localhost log_dispatch]# which java 
/usr/bin/java
[root@localhost log_dispatch]# ls -lr /usr/bin/java
lrwxrwxrwx 1 root root 22 6月   5 16:04 /usr/bin/java -> /etc/alternatives/java
[root@localhost log_dispatch]# ls -lrt /etc/alternatives/java 
lrwxrwxrwx 1 root root 73 6月   5 16:04 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el7_9.x86_64/jre/bin/java

最终找到的java的安装路径是:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el7_9.x86_64

添加JAVA_HOME的环境变量

输入命令编辑文件

vi /etc/profile 

在最后一行添加以下内容:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el7_9.x86_64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

运行以下命令使得JAVA_HOME生效

source /etc/profile

安装elasticsearch

下载

https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.1.1/elasticsearch-2.1.1.tar.gz

解压

# 一般把需要安装的软件安装到 /opt 目录下
mv elasticsearch-2.1.1.tar.gz /opt cd /opt
# 解压
tar zxvf elasticsearch-2.1.1.tar.gz
# 修改名称
mv elasticsearch-2.1.1 elasticsearch
# 到 bin 目录下启动
cd elasticsearch/bin
./elasticsearch # 此时启动会报错,还不能启动

安全原因,需要创建单独用户:

由于 ElasticSearch 可以接收用户输入的脚本并且执行,为了系统安全考虑,
需要创建一个单独的用户用来运行 ElasticSearch

# 创建 elsearch 用户组及 elsearch 用户
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch

# 更改 elasticsearch 文件夹及内部文件的所属用户及组为 elsearch:elsearch
cd /opt
chown -R elsearch:elsearch  elasticsearch

# 切换到 elsearch 用户再启动
su elsearch 
cd elasticsearch/bin
./elasticsearch

你可能感兴趣的:(elasticsearch,java,jvm)