1 确认版本一致
elasticsearch-8.3.1-linux-x86_64.tar.gz
kibana-8.3.1-linux-x86_64.tar.gz
2 在磁盘空间最大的目录下解压文件(注:不能是/root及其子目录)
例如:
1 mkdir -p /home/yk/es_cs
2 cd /home/yk/es_cs
3 将文件复制到该目录下
4 tar -xzvf elasticsearch-8.3.1-linux-x86_64.tar.gz
5 tar -xzvf kibana-8.3.1-linux-x86_64.tar.gz
3 修改es配置文件
1 cd elasticsearch-8.3.1/config
2 vim elasticsearch.yml,如需外网访问请添加下面的内容,否则只能本地访问
http.host: 0.0.0.0
3 vim jvm.options,根据需求调整内存,默认4g,打开如下注释并调整到需要的值即可
## -Xms4g
## -Xmx4g
4 新建用户用于启动es,默认不允许root用户启动
1 useradd es
2 passwd es,输入密码es
3 chown -R es:es /home/yk/es_cs
5 需要运行一次es
1 su es /home/yk/es_cs/elasticsearch-8.3.1/bin/elasticsearch
2 运行到最后会出现一些内容如下,需要保存下来:
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.
ℹ️ Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
XWM_cL0N8NtO8AAXf_7X
ℹ️ HTTP CA certificate SHA-256 fingerprint:
fc2a712f4756d519db1082afafff23940b0b41c54557b36da504176e8a636147
ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjMuMSIsImFkciI6WyIxMC4yMzkuNTAuMTk2OjkyMDAiXSwiZmdyIjoiZmMyYTcxMmY0NzU2ZDUxOWRiMTA4MmFmYWZmZjIzOTQwYjBiNDFjNTQ1NTdiMzZkYTUwNDE3NmU4YTYzNjE0NyIsImtleSI6ImxuWnIwb0VCc2JuaENNSnR6THF1OmhiSV9OSVJaVEl5NGdKcHdTa1UybUEifQ==
ℹ️ Configure other nodes to join this cluster:
• On this node:
⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
⁃ Restart Elasticsearch.
• On other nodes:
⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.
3 ctrl c退出服务
6 将Elasticsearch添加为系统服务
1 cd /etc/init.d
2 vi elasticsearch,复制以下内容进文件,请注意调整环境变量路径ES_HOME
#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-8.3.1
export ES_HOME=/home/yk/es_cs/elasticsearch-8.3.1
case $1 in
start)
su es<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
stop)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su es<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
3 chmod 777 elasticsearch
4 添加和删除服务并设置启动方式
chkconfig --add elasticsearch #添加系统服务
chkconfig --del elasticsearch #删除系统服务
5 启动服务
service elasticsearch start #启动
service elasticsearch stop #停止
service elasticsearch restart #重启
6 设置服务开机启动
chkconfig elasticsearch on #开启
chkconfig elasticsearch off #关闭
7 服务启动后如果不能访问请检查防火墙
8 启动后访问https://服务ip:9200/,键入用户名elastic ,密码是第一次启动后保存的密码,这里是XWM_cL0N8NtO8AAXf_7X,出现如下字样表示启动成功
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "0_5pr310QoKpOLHKtlUwZw",
"version" : {
"number" : "8.3.1",
"build_type" : "tar",
"build_hash" : "b9a6b2867996ba92ceac66cb5bafc6db25e7910e",
"build_date" : "2022-06-29T18:39:55.731992798Z",
"build_snapshot" : false,
"lucene_version" : "9.2.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
7 修改密码
1 cd /home/yk/es_cs/elasticsearch-8.3.1/bin/
2 ./elasticsearch-reset-password -u elastic -i 例如密码设置成123456
########### 最终用户名是elastic #######
########### 密码是123456 #######
3 重启登录即可
8 证书相关
1 用如下的命令来得到证书的 fingerprint:
openssl x509 -fingerprint -sha256 -in /home/yk/es_cs/elasticsearch-8.3.1/config/certs/http_ca.crt
2 生成证书
cd /home/yk/es_cs/elasticsearch-8.3.1/config/certs
openssl x509 -in http_ca.crt -out cert.pem
9 安装kibana
1 cd /home/yk/es_cs/kibana-8.3.1/config
2 vim kibana.yml
3 文件中新增一行server.host: "0.0.0.0"用于外网访问
4 cd /home/yk/es_cs/kibana-8.3.1
5 su es ./bin/kibana
6 访问 http://服务ip:5601
7 键入es首次启动页面给予的token,如果过期了到es安装目录(/home/yk/es_cs/elasticsearch-8.3.1)执行bin/elasticsearch-create-enrollment-token -s kibana --url "https://服务ip:9200"
8 键入kibana启动界面给的6位数字
9 配置自动完成,输入账户密码登录,账户elastic密码123456(刚才es修改的密码)
10 kibana配置https
1 cd /home/yk/es_cs/elasticsearch-8.3.1
2 ./bin/elasticsearch-certutil csr -name kibana-server -dns example.com, localhost 生成csr-bundle.zip文件
3 解压文件unzip csr-bundle.zip
4 将文件拷贝到kibana的config文件夹中
cp -r kibana-server/kibana-server.csr /home/yk/es_cs/kibana-8.3.1/config/
cp -r kibana-server/kibana-server.key /home/yk/es_cs/kibana-8.3.1/config/
5 cd /home/yk/es_cs/kibana-8.3.1/config/
6 openssl x509 -req -in kibana-server.csr -signkey kibana-server.key -out kibana-server.crt
7 修改配置文件
1 vim kibana.yml
2 添加以下内容到文件
server.ssl.certificate: config/kibana-server.crt
server.ssl.key: config/kibana-server.key
server.ssl.enabled: true
3 重启kibana
cd /home/yk/es_cs/kibana-8.3.1
su es ./bin/kibana &
参考:
Kibana和浏览器之间HTTPS连接
elasticsearch8.2.0 初始化忘记密码重置
Elasticsearch创建安全账户
重置elastic密码
linux 安装elasticsearch 8
Elastic Stack 8.0 安装 - 保护你的 Elastic Stack 现在比以往任何时候都简单
如何在 Linux,MacOS 及 Windows 上进行安装 Elasticsearch
Elastic:如何在一个机器上同时模拟多个节点
Elasticsearch:设置 Elastic 账户安全
go链接https的es
Go Elasticsearch 快速入门
es go支持tls