给女朋友做网站的素材,美化网站代码,网站维护一般需要多久时间,商城小程序搭建背景
公司的业务需要在加密的情况下使用#xff0c;为此#xff0c;研究测试了一下es8是如何启用TLS的。以下是测试使用过程。
x-pack了解
在 Elasticsearch 7.11.0 版本及更高版本中#xff0c;X-Pack 功能在默认情况下已经整合到 Elastic Stack 的各个组件中#xff0…背景
公司的业务需要在加密的情况下使用为此研究测试了一下es8是如何启用TLS的。以下是测试使用过程。
x-pack了解
在 Elasticsearch 7.11.0 版本及更高版本中X-Pack 功能在默认情况下已经整合到 Elastic Stack 的各个组件中并且具有不同的名称和许可证。以下是 Elastic Stack 中一些主要的 X-Pack 功能和对应的新名称 安全性Security提供了身份验证、授权、加密通信和安全审计等功能用于保护 Elasticsearch 和 Kibana 的访问和数据安全。 警报Alerting用于配置和管理警报规则当符合特定条件时发送通知、触发操作或运行自定义脚本。 监控Monitoring提供了集群健康状况、节点性能和资源使用情况等实时监控指标以及用于可视化和分析的监控仪表板。 报告Reporting用于生成漂亮的报表和可视化图表支持将报告导出为 PDF、CSV 或 PNG 格式并支持计划定期生成和发送报告。 图形探索Graph Exploration用于分析和可视化数据之间的关系帮助发现隐藏的模式和连接。 机器学习Machine Learning提供了强大的机器学习功能用于自动检测异常、预测趋势和进行故障检测。
请注意具体的功能和名称可能会随着 Elastic Stack 版本的更新而有所变化请参考官方文档以获取最新的信息和功能详细说明。
基本知识
1、默认情况下服务器将使用两个端口进行通讯9200与9300
9200用于http通讯各类restful客户端例如kibana浏览器直接访问、agent等等需要通过该端口与服务器连接。9300用于elasticsearch服务器集群内各服务器节点间的通讯。
2、如果首次使用yum或者rpm按装elasticsearch服务器安装程序会自动进行安全配置并生成几个安全配置需要的文件如ca的keystore、用于http加密通讯的keystore(http.p12)等这些最好保留下来当然我们也可以用它提供的证书工具在后面自行创建。注意如果不是首次安装而又希望系统再次自动生成安全配置需要先把/var/lib/elasticsearch里的东西删除干净。
3、通过自动安全配置生成的几个文件会放在/usr/share/elasticsearch下
elastic-stack-ca.p12 keystore文件存储了ca的公共证书及用于签发其他证书的密钥。默认没有这个文件可以自己手动生成transport.p12 包含了传输层密钥和证书用于elasticsearch节点间加密通讯。http.p12 这个keystore存储着http加密通讯需要的证书和密钥。http_ca.crt 证书文件用于集群内的http通讯加密。
es安装
环境介绍
单台 centos7部署单节点elasticsearch8.0.1
下载安装
elasticsearch中文下载地址https://elasticsearch.cn/download/ 选择自己需要的版本windows、Linux、mac等但需要注意不同版本之间的区别我此次使用es 8.0.1的rpm包进行测试。
#rpm包下载
[rootk8s-m2 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.1-x86_64.rpm
#直接使用rpm安装
warning: elasticsearch-8.0.1-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing... ################################# [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Updating / installing...1:elasticsearch-0:8.0.1-1 ################################# [100%]
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
--------------------------- Security autoconfiguration information ------------------------------Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.The generated password for the elastic built-in superuser is : GAe2y2Rqi0mvxjFMDZkIf this node should join an existing cluster, you can reconfigure this with
/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token token-here
after creating an enrollment token on your existing cluster.You can complete the following actions at any time:Reset the password of the elastic built-in superuser with
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic.Generate an enrollment token for Kibana instances with /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana.Generate an enrollment token for Elasticsearch nodes with
/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node.-------------------------------------------------------------------------------------------------
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemdsudo systemctl daemon-reloadsudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executingsudo systemctl start elasticsearch.service
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK正常情况下该版本的安装会出现以上的一些信息如果没有可能是由于不是第一次安装有之前遗留下的一些文件。仔细查看上面的输出信息说明默认情况下认证已经启用并配置好节点的加入方式密码重置token的生成等。
环境调整 由于es服务需要服务器调整连接数修改limits.conf文件如下
vim /etc/security/limits.conf
* soft nofile 655350
* hard nofile 655350调整vm.max_map_coun检查当前的 vm.max_map_count 值如果当前的值小于 262144需要调整。否则如果当前的值已经达到或超过 262144那么可以不进行任何更改当然也可以适量调大一点。
[rootk8s-m2 ~]# sysctl vm.max_map_count
[rootk8s-m2 ~]# echo vm.max_map_count655360 /etc/sysctl.conf
[rootk8s-m2 ~]# sysctl -pjvm使用内存大小调整默认情况下es配置使用的是-Xms4g和-Xmx4g可以按照自己所需进行调整。
启动
[rootk8s-m2 opt]# systemctl start elasticsearch.service
[rootk8s-m2 opt]# systemctl status elasticsearch
● elasticsearch.service - ElasticsearchLoaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)Active: active (running) since Mon 2023-10-09 10:44:39 CST; 20min agoDocs: https://www.elastic.coMain PID: 24259 (java)Tasks: 96Memory: 4.4GCGroup: /system.slice/elasticsearch.service├─24259 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl60 -Des.networkaddress.cache.negative.ttl10 -Djava.security.managerallow -XX:AlwaysPreTouch -Xss1m -Djava.awt.headlesstrue -Dfile...└─24694 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controllerOct 09 10:44:12 k8s-m2 systemd[1]: Starting Elasticsearch...
Oct 09 10:44:39 k8s-m2 systemd[1]: Started Elasticsearch.
[rootk8s-m2 opt]# 常用命令说明
使用yum或者rpm安装时和es相关的命令存放在/usr/share/elasticsearch/bin目录
#elastic用户命令重置其他用户类似指定
[rootk8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
#默认生成证书时配置的密码等信息
[rootk8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-keystore list
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
autoconfiguration.password_hash
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
#查看具体某项配置的密码
[rootk8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
0w9Z7YiEQG2rMWprA-8rYQ
#修改具体某项的密码如果之前已经设置可以覆盖
[rootk8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password#命令行检查
[rootk8s-m2 certs]# curl --cacert http_ca.crt -u elastic:GAe2y2Rqi0mvxjFMDZk -XGET https://192.168.2.141:9200/
{name : k8s-m2,cluster_name : elasticsearch,cluster_uuid : v5HBM6ACRiy31DBZmSa58g,version : {number : 8.0.1,build_flavor : default,build_type : rpm,build_hash : 801d9ccc7c2ee0f2cb121bbe22ab5af77a902372,build_date : 2022-02-24T13:55:40.601285296Z,build_snapshot : false,lucene_version : 9.0.0,minimum_wire_compatibility_version : 7.17.0,minimum_index_compatibility_version : 7.0.0},tagline : You Know, for Search
}#更多选项查看按自己所需查看
[rootk8s-m2 certs]# curl --cacert http_ca.crt -u elastic:GAe2y2Rqi0mvxjFMDZk -XGET https://192.168.2.141:9200/_cat
^.^
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/ml/anomaly_detectors
/_cat/ml/anomaly_detectors/{job_id}
/_cat/ml/trained_models
/_cat/ml/trained_models/{model_id}
/_cat/ml/datafeeds
/_cat/ml/datafeeds/{datafeed_id}
/_cat/ml/data_frame/analytics
/_cat/ml/data_frame/analytics/{id}
/_cat/transforms
/_cat/transforms/{transform_id}kibana连接加密的es
kibana下载安装
[rootk8s-m2 opt]# wget https://artifacts.elastic.co/downloads/kibana/kibana-8.0.1-x86_64.rpm
[rootk8s-m2 opt]# rpm -ivh kibana-8.0.1-x86_64.rpm生成kibana需要的相关证书
注意在这过程中要输入密码具体密码为上面/usr/share/elasticsearch/bin/elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password查看到的密码。
[rootk8s-m2 certs]# pwd
/etc/elasticsearch/certs
[rootk8s-m2 certs]# ll
-rw-rw---- 1 root elasticsearch 1915 Oct 9 09:57 http_ca.crt
-rw-rw---- 1 root elasticsearch 9981 Oct 9 09:57 http.p12
-rw-rw---- 1 root elasticsearch 5822 Oct 9 09:57 transport.p12# Private Key 私钥
[rootk8s-m2 certs]# openssl pkcs12 -in http.p12 -nocerts -nodes client.key
# Public Certificate 公共证书
[rootk8s-m2 certs]# openssl pkcs12 -in http.p12 -clcerts -nokeys client.cer
# CA Certificate 签署公共证书的CA
[rootk8s-m2 certs]# openssl pkcs12 -in http.p12 -cacerts -nokeys -chain client-ca.cer[rootk8s-m2 certs]# mkdir /etc/kibana/config/
[rootk8s-m2 certs]# cp /etc/elasticsearch/certs/client* /etc/kibana/config/主要配置修改
注意使用的是kibana账户密码不知道可以用elasticsearch-reset-password/usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana命令进行重置。
server.port: 5601
server.host: 192.168.2.141
server.publicBaseUrl: http://192.168.2.141:5601 #最好添加上
elasticsearch.username: kibana
elasticsearch.password: THR__INXYkH_lLCO3vV1
elasticsearch.ssl.certificate: /etc/kibana/config/client.cer #相关路径最好写绝对路径
elasticsearch.ssl.key: /etc/kibana/config/client.key
elasticsearch.ssl.certificateAuthorities: /etc/kibana/config/client-ca.cer
elasticsearch.ssl.verificationMode: certificatekibana启动并检查
[rootk8s-m2 opt]# systemctl start kibana
[rootk8s-m2 opt]# systemctl status kibana -l
#如果kibana异常可以查看日志进行排查
[rootk8s-m2 opt]# tail -f /var/log/kibana/kibana.logkibana访问
使用上面配置的服务器IP5601地址进行访问。 账号为elastic密码为es启动时输出到界面的密码。当然不记得也可以进行修改。
更多关于elasticsearch的知识分享请前往博客主页。编写过程中难免出现差错敬请指出