在Ubuntu上安装ElasticSearch,kibana

2020-03-24 1930点热度 2人点赞 0条评论

Elasticsearch

官方文档

Install Elasticsearch with Debian Package

导入Elasticsearch PGP密钥

Elasticsearch会用一段指纹签名发布的包,需要导入PGP密钥才能正常安装

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

从APT仓库安装

首先如果没有安装过apt-transport-https,需要首先进行安装:

sudo apt-get install apt-transport-https

然后保存ElasticSearch仓库定义到/etc/apt/sources.list.d/elastic-7.x.list:

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

然后使用如下命令安装Elasticsearch

sudo apt-get update && sudo apt-get install elasticsearch

配置elasticsearch

官方文档

Configuring Elasticsearch

节点配置

安装完成之后,配置文件在/etc/elasticsearch目录下,需要修改elasticsearch.yml进行配置,修改的内容如下(/etc/elasticsearch需要root用户才能进入和编辑,需要使用root用户才能修改):

cluster.name: hs-es-cluster
node.name: hs
node.attr.rack: work-computer
path.data: /var/lib/elasticsearch【未变动】
path.logs: /var/log/elasticsearch【未变动】
network.host: 192.168.2.3
http.port: 9200
discovery.seed_hosts: ["192.168.2.3"]
cluster.initial_master_nodes: ["hs"]

启停命令

通过service status判断是否启动

sudo service elasticsearch status

启停elasticsearch

sudo service elasticsearch start
sudo service elasticsearch stop

浏览器验证

浏览器输入http://192.168.2.3:9200 看端口是否能够访问,出现熟悉的“You Know,for Search”,说明安装启动成功。

kibana

官方文档

Install Kibana with Debian package

安装kibana

安装elasticsearch的时候已经添加过ES仓库,不必重复添加,只需要使用以下命令即可安装kibana

sudo apt install kibana

配置kibana

首先修改如下配置

server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://auvyo.com:9200"]
kibana.index: ".kibana"
kibana.defaultAppId: "home"

说明如下:server.host需要制定绑定的IP,如果绑定了192.168.2.3,则只能通过这个IP访问,0.0.0.0代表所有主机均可访问。

添加样例数据?

通过浏览器访问主机的5601端口,首页显示是否添加样例数据。如果已经知道怎么用kibana了,就不用添加垃圾数据,如果想要学习使用kibana,则添加样例数据,看看如何使用kibana。

魔法开始的地方,添加安全认证并使用Platinum license

进入kibana的Stack Management/License management,点击“Start trial”

点击之后,显示试用licence已生效:

为elasticsearch,kibana添加安全认证

因为当前elasticsearch,kibana没有任何安全保护,任何人都可以访问,任何人都可以修改数据,缺乏安全认证,因此以下将给elasticsearch,kibana添加密码保护,访问elasticsearch和kibana,均需要输入用户名和密码方可访问。

为elasticsearch添加安全认证

官方文档Security settings in Elasticsearch

在elasticsearch.yml文件中添加以下内容:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

重启elasticsearch服务之后,将需要输入用户名和密码之后才能进入:

以下将设置elasticsearch的用户名和密码:

cd /usr/share/elasticsearch
bin/elasticsearch-setup-passwords interactive

然后根据提示输入内置用户的密码。

root@gs:/usr/share/elasticsearch# bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana_system]: 
Reenter password for [kibana_system]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

然后在web页面elasticsearch访问界面输入用户名elastic和刚刚设置的密码,即可正常访问。

在kibana中设置elasticsearch的用户名和密码

在kibana.yml文件中去掉如下部分的注释,并修改用户名和密码,如下:

elasticsearch.username: "elastic"
elasticsearch.password: "password"

重启kibana之后,将需要输入用户名和密码之后方可登录:


输入用户名和密码之后,即可进入页面。用户名为elasitc,密码为刚刚设置的内置用户的密码。

破解ES证书验证,使用Platinum license证书

参照docker版elasticsearch证书破解[6.3.2版本]

原理一样,参照着做即可破解。

以下附上7.8.0版本的jar包和licence。

链接:https://pan.baidu.com/s/14J5FCM3V9KGhoUS0EM4gtA 
提取码:vg98

最后附上一张破解成功之后的截图:

王显锋

激情工作,快乐生活!

文章评论