CentOS 7下RPM安装Elasticsearch7.X

2019-11-03 22:09
159
0

7.4以上版本自带了java环境所以不用另外下载安装java  jdk,另外7.4版本可以直接用root 账号执行不用再新建用户来执行安装操作。

elasticsearch

下载地址:https://www.elastic.co/cn/downloads/elasticsearch

tar包:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz

rpm包:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-x86_64.rpm

安装教程:https://www.elastic.co/guide/en/elasticsearch/reference/7.4/rpm.html#rpm-repo

kibana

https://www.elastic.co/cn/downloads/kibana

https://artifacts.elastic.co/downloads/kibana/kibana-7.4.2-linux-x86_64.tar.gz

https://artifacts.elastic.co/downloads/kibana/kibana-7.4.2-x86_64.rpm
安装教程:https://www.elastic.co/guide/en/kibana/7.4/rpm.html#rpm-repo

logstash https://www.elastic.co/cn/downloads/logstash

https://artifacts.elastic.co/downloads/logstash/logstash-7.4.2.tar.gz

https://artifacts.elastic.co/downloads/logstash/logstash-7.4.2.rpm

安装教程https://www.elastic.co/guide/en/logstash/7.4/installing-logstash.html#_yum

APM https://www.elastic.co/cn/downloads/apm

 

通过yum命令安装方式

1.rpm下载elasticsearch

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

2.创建 elasticsearch.repo

vi /etc/yum.repos.d/elasticsearch.repo

添加下面的配置:

[elasticsearch-7.x]
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=1
autorefresh=1
type=rpm-md

3.以管理者身份安装 依次执行下面的命令

sudo yum install elasticsearch

如果网速慢,则直接用迅雷下载最新elasticsearch rpm包

执行安装:

sudo rpm --install elasticsearch-7.4.2-x86_64.rpm

配置elastic随系统启动:

sudo chkconfig --add elasticsearch

启动命令:

sudo -i service elasticsearch start

停止命令:

sudo -i service elasticsearch stop

查看运行状态:

sudo -i service elasticsearch status

或者如下命令

配置elastic随系统启动:

systemctl daemon-reload
systemctl enable elasticsearch

启动命令:

systemctl start elasticsearch

停止命令:

systemctl stop elasticsearch

查看运行状态:

systemctl status elasticsearch

检测是否安装成功

curl -X GET "localhost:9200/"

返回如下信息标识安装成功

{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iGgceUkhT5WShbV7_YWu2Q",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

默认elastic程序所在位置:

/usr/share/elasticsearch

配置文件目录在/etc/elasticsearch/相当于tar.gz的config目录,配置文件:

/etc/elasticsearch/elasticsearch.yml

索引所在位置:

/var/lib/elasticsearch

日志输出在:

/var/log/elasticsearch/elasticsearch.log

开通外网访问:

1.修改配置文件elasticsearch.yml

node.name: node-1   #取消该注释
network.host: 192.168.136.110  #192.168.0.1改为自己elastic服务器地址
cluster.initial_master_nodes: ["node-1"]   #这里一定要这样设置

#在最后加上这两句,这样浏览器就可以访问了
http.cors.enabled: true
http.cors.allow-origin: "*"

2.修改系统配置

vi /etc/sysctl.conf

增加如下配置

vm.max_map_count=655360

执行以下命令确保配置生效

sysctl -p

3.设置资源参数

vi /etc/security/limits.conf

增加如下内容

* soft nofile 65536
* hard nofile 131072
* soft nproc 65536
* hard nproc 131072

因为启动Elasticsearch7.4以下版本需要使用非root用户,需要单独新建一个用户来启动Elasticsearch,所以需要配置如下。

1.添加elk用户

useradd elk         #创建用户elk

groupadd elk#创建组elk

useradd elk -g elk#将用户添加到组

# 创建数据和日志目录

mkdir  -pv  /opt/elk/data

mkdir  -pv  /opt/elk/logs

# 修改文件所有者

chown -R elk:elk /opt/elk/

chown -R elk:elk /user/local/elasticsearch-7.3.0/    

2.设置用户资源参数

vi /etc/security/limits.d/20-nproc.conf

设置elk用户参数,7.4以上可不用配置此项,7.4以下版本需要单独添加elk帐号进行安装,则需要配置

elk    soft    nproc     65536

设置账号和密码

1.切换到elastsearch的目录下,使用下列命令生成证书

cd /usr/share/elasticsearch/bin/
./elasticsearch-certutil cert -out /etc/elasticsearch/elastic-certificates.p12 -pass ""

2.打开elasticsearch.yaml,在尾部添加下面一行代码:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

3,生成帐号和密码

自动方式:

./elasticsearch-setup-passwords auto

手动方式:

./elasticsearch-setup-passwords interactive 

默认会生成好几个管理员账户,其中一个叫elastic的用户是超级管理员。


重启elastic

systemctl restart elasticsearch

测试配置否是成功

浏览器访问http://ip:port

http://192.168.0.21:9200

返回如下内容说明成功

{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iGgceUkhT5WShbV7_YWu2Q",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

 

 

参考资料:

https://www.jianshu.com/p/50ed93eab16e

https://blog.csdn.net/xiyao217/article/details/102869420

https://blog.csdn.net/u011265001/article/details/100084335

全部评论