Elasticsearch, Kibana安装

Centos7

安装Elasticsearch

安装

因为ES启动不能用root账号,手工安装配置较繁琐,故直接用rpm进行安装。根据官网的6.8安装提示

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
vi /etc/yum.repos.d/elasticsearch.repo
# 加入内容开始
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
# 加入内容结束
# 安装,提示会安装版本6.8.13
yum install elasticsearch

如果下载很慢,可以手动下载rpm包,然后用rpm命令安装

rpm --install elasticsearch-6.8.13.rpm

将ES添加到服务

sudo systemctl daemon-reload
systemctl enable elasticsearch.service

配置JDK和系统环境变量

此时需要准备好JDK8环境,例如将JDK放到 /opt/jdk/latest,修改 /etc/sysconfig/elasticsearch, 修改其中的

# Elasticsearch Java path
JAVA_HOME=/opt/jdk/latest
MAX_OPEN_FILES=65535
MAX_MAP_COUNT=262144

在 /etc/profile里添加JAVA_HOME无效,必须在这个配置文件里添加(或者写到elasticsearch.service这个文件里)
JVM的内存大小不在这个文件配置,另外这里设置了MAX_OPEN_FILES和MAX_MAP_COUNT后,就不需要修改limits.conf和sysctl.conf了。

配置ES

修改 /etc/elasticsearch/elasticsearch.yml, 调整以下几处

path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
...
network.host: 0.0.0.0
http.port: 9200

修改 /etc/elasticsearch/jvm.options, 调整以下几处,根据自己需要调整

-Xms5g
-Xmx5g
8:-Xloggc:/var/log/elasticsearch/gc.log

启动ES

systemctl start elasticsearch
systemctl status elasticsearch -l

防火墙打开端口

firewall-cmd --zone=public --list-all
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

检查

从浏览器访问9200端口,应该能看到JSON输出
从命令行,用curl检查

$ curl -H "Content-Type: application/json" -XPUT 'http://192.168.2.8:9200/store/test_data/1?pretty' -d "{\"title\":\"It's the title\",\"cost\": \"years\"}"
{
  "_index" : "store",
  "_type" : "test_data",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

$ curl -XGET "http://192.168.2.8:9200/_cluster/health?pretty=true"
{
  "cluster_name" : "elasticsearch",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 7,
  "active_shards" : 7,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 5,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 58.333333333333336
}

添加密码

需要在配置文件中开启x-pack验证, 修改/etc/elasticsearch/elasticsearch.yml,在末尾添加, 并重启

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

执行以下命令, 这里会一次性给4个用户分别设置密码,elastic, kibana, logstash_system,beats_system

bin/elasticsearch-setup-passwords interactive

安装Kibana

安装

根据官网的6.8安装提示

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
vi /etc/yum.repos.d/kibana.repo
# 内容开始
[kibana-6.x]
name=Kibana repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
# 内容结束
# 安装
sudo yum install kibana

也可以手工下载后,通过rpm命令安装

sudo rpm --install kibana-6.8.13-x86_64.rpm

加入服务

systemctl daemon-reload
systemctl enable kibana

配置

配置文件在 /etc/kibana/kibana.yml,修改

server.port: 5601
server.host: "192.168.2.8"
elasticsearch.hosts: ["http://localhost:9200"]

server.host最好不设为0.0.0.0,因为ES装在本机,所以使用http://localhost:9200
如果elasticsearch已经配置了密码,需要修改这两行

# is proxied through the Kibana server.
elasticsearch.username: "kibana"
elasticsearch.password: "xxx"

启动

systemctl start kibana
systemctl status kibana

防火墙打开端口

firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload

posted on 2021-01-16 22:35  Milton  阅读(285)  评论(0编辑  收藏  举报

导航