网站首页 > 开源技术 正文
Elasticsearch 一切为了搜索
1.软件环境:
Centos7.9
3 台虚拟机,8 CPU, 16GB 内存。
主机地址: 10.10.1.1 10.10.1.2 10.10.1.3
2.JDK 安装
elasticsearch-7.x 自带 jdk12 无需安装
3. 下载地址
https://www.elastic.co/cn/downloads/
下载最新版本7.14安装包, elasticsearch-7.14.0-linux-x86_64.tar
4. 配置 hosts 文件
vim /etc/hosts
10.10.1.1 xszkygl1
10.10.1.2 xszkygl2
10.10.1.3 xszkygl3
5. 创建用户
useradd es
passwd es
注意:Elasticsearch 是无法通过 root 启动, 所以需要单独创建用户。
6. 解压安装
以 es 用户登录, 上传安装文件, 开始安装。
tar -zxvf elasticsearch-7.14.0-linux-x86_64.tar.gz -C /home/es
mv elasticsearch-7.14.0 es7.14
cd /home/es/es7.14
mkdir data
7. 配置Elasticsearch
7.1 主节点配置
cd /home/es/es7.14/config
vim elasticsearch.yml
cluster.name: kygl
path.data: /home/es/es7.14/data
path.logs: /home/es/es7.14/logs
network.host: 10.10.1.1
http.port: 9200
discovery.seed_hosts: ["xszkygl1", "xszkygl2", "xszkygl3"]
cluster.initial_master_nodes: ["xszkygl1","xszkygl2","xszkygl3"]
node.name: xszkygl1
transport.tcp.port: 9300
node.ingest: false
node.ml: false
cluster.remote.connect: false
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: false
node.master: true
node.data: false
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ml.enabled: false
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.kygl
xpack.security.transport.ssl.truststore.path: elastic-certificates.kygl
7.2 节点2 配置
cd /home/es/es7.14/config
vim elasticsearch.yml
cluster.name: kygl
path.data: /home/es/es7.14/data
path.logs: /home/es/es7.14/logs
network.host: 10.10.1.2
http.port: 9200
discovery.seed_hosts: ["xszkygl1", "xszkygl2", "xszkygl3"]
cluster.initial_master_nodes: ["xszkygl1","xszkygl2","xszkygl3"]
node.name: xszkygl2
transport.tcp.port: 9300
node.ingest: false
node.ml: false
cluster.remote.connect: false
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: false
node.master: false
node.data: true
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ml.enabled: false
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.kygl
xpack.security.transport.ssl.truststore.path: elastic-certificates.kygl
7.3 节点3 配置
cd /home/es/es7.14/config
vim elasticsearch.yml
cluster.name: kygl
path.data: /home/es/es7.14/data
path.logs: /home/es/es7.14/logs
network.host: 10.10.1.3
http.port: 9200
discovery.seed_hosts: ["xszkygl1", "xszkygl2", "xszkygl3"]
cluster.initial_master_nodes: ["xszkygl1","xszkygl2","xszkygl3"]
node.name: xszkygl3
transport.tcp.port: 9300
node.ingest: false
node.ml: false
cluster.remote.connect: false
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: false
node.master: false
node.data: true
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ml.enabled: false
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.kygl
xpack.security.transport.ssl.truststore.path: elastic-certificates.kygl
注意:配置文件 elasticsearch.yml 格式可能有问题, 比如冒号后面要有空格,前面不能有空格等!
8. 创建 Elasticsearch 用户
8.1 生成证书(任一节点)
cd /home/es/es7.14/bin
./elasticsearch-certutil ca
Please enter the desired output file [elastic-stack-ca.p12]:
Enter password for elastic-stack-ca.p12 :
第一步:-1>回车
第二步:-2>输入证书的密码:password123
生成 CA 文件: /home/es/es7.14/elastic-stack-ca.p12
8.2 生成秘钥文件
cd /home/es/es7.14/bin
./elasticsearch-certutil cert --ca elastic-stack-ca.p12
Enter password for CA (elastic-stack-ca.p12) :
Please enter the desired output file [elastic-certificates.p12]:
Enter password for elastic-certificates.kygl :
第一步:-1>输入前面设置的证书的密码:password123
第二步:-2>输入输出的密钥文件: elastic-certificates.kygl
第三步:-3>回车
8.3 拷贝密钥文件到其他节点
mv /home/es/es7.14/elastic-certificates.kygl /home/es/es7.14/config
cd /home/es/es7.14/config
scp elastic-certificates.kygl 10.10.1.2:/home/es/es7.14/config
scp elastic-certificates.kygl 10.10.1.3:/home/es/es7.14/config
8.4 修改权限(三个节点)
cd /home/es/es7.14/config
chmod 755 elastic-certificates.kygl
8.5 设置 Elasticsearch 用户密码(任一节点)
cd /home/es/es7.14/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]
第一步:-1>输入Elasticsearch 用户密码:elastic123
9. 系统配置(三个节点)
9.1 配置 sysctl.conf
vi /etc/sysctl.conf
fs.file-max = 6815744
vm.max_map_count=655360
sysctl -p
sysctl --system
sysctl -a
9.2 配置 limits.conf
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 32000
* hard nproc 32000
* hard memlock unlimited
* soft memlock unlimited
vim /etc/security/limits.d/20-nproc.conf
es soft nofile 65536
es hard nofile 65536
es soft nproc 32000
es hard nproc 32000
注意:需要重启操作系统!
9.3 重启后, 可以通过以下命令查看:
#查看
ulimit -Hn
ulimit -Sn
ulimit -Hu
ulimit -Su
9.4 配置 system.conf
vim /etc/systemd/system.conf
DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity
#配置生效
/bin/systemctl daemon-reload
10. JVM 配置(三个节点)
Elasticsearch 是基于Java开发的,所以依赖于JVM,建议根据物理内存调整 JVM 属性。
cd /home/es/es7.14/config/
vim jvm.options
-Xms16g
-Xmx16g
注意:JVM 需要根据物理主机内存进行设置, 建议设置物理内存的一半,不要超过32G。
11. 关闭网络防火墙(三个节点)
systemctl stop firewalld
systemctl disable firewalld
12. Elasticsearch 启动(三个节点)
12.1 编写启动脚本
vim start_es.sh
/home/es/es7.14/bin/elasticsearch -d
注意:-d 参数是后台启动。
12.2 Elasticsearch 访问
curl --user elastic:elastic123 -X GET http://10.10.1.1:9200
curl --user elastic:elastic123 -X GET http://10.10.1.2:9200
curl --user elastic:elastic123 -X GET http://10.10.1.3:9200
注意:由于我们创建了 Elasticsearch 用户, 访问时需要加上用户名和密码。
12.3 查看集群状态
执行如下命令, 查询集群状态如图10.3-1 所示, 表明Elasticsearch 启动成功。
curl --user elastic:elastic123 http://10.10.1.11:9200/_cluster/stats?pretty
12.4 编写 Elasticsearch 关闭脚本
vim stop_es.sh
PROCESS=`ps -ef | grep 'es7.14' |grep -v grep | grep -v PPID | awk '{ print $2}'`
echo $PROCESS
for i in $PROCESS
do
echo "Kill the elasticsearch process [ $i ]"
kill -9 $i
done
注意: 启动和关闭脚本都需要执行权限。
猜你喜欢
- 2024-11-07 如何将kibana的dashboard集成到自有系统中
- 2024-11-07 集群分布式下日志架构的搭建(集群日志管理)
- 2024-11-07 Elasticsearch算分优化方案之rescore_query
- 2024-11-07 最新JumpServer未授权访问漏洞(CVE-2023-42442)分析
- 2024-11-07 Spring Boot搭建 ELK,这才是正确看日志的方式
- 2024-11-07 大量使用 items_per_inner_pack 和 inner_packs_per_master_pack
- 2024-11-07 Kibana(一张图片胜过千万行日志)——转
- 2024-11-07 解决Elasticsearch集群开启账户密码安全配置自相矛盾的坑
- 2024-11-07 x-pack-sql-jdbc 发布后提示版本不兼容
- 2024-11-07 ES单机通过端口搭建伪集群(如何搭建es集群)
你 发表评论:
欢迎- 03-26业务监控—一站式搭建jmeter+telegraf+influxdb+Grafana看板
- 03-2615个最好的性能测试工具(软件测试工程师必备)
- 03-26软件测试工程师必备技巧!(软件测试工程师入门教程)
- 03-26UE4基础知识总结(七)(ue4入门)
- 03-26Portkeys推出新款HDMI播放器:5.5英寸FHD屏幕,支持4K输入/输出
- 03-26数字时代的纯粹,HiFiMan HM-901S 播放器体验
- 03-26CBN丨Double 11 sales shows resilience in China’s consumption
- 03-26AKG K812简单听感(akgk812pro评测)
- 最近发表
-
- 业务监控—一站式搭建jmeter+telegraf+influxdb+Grafana看板
- 15个最好的性能测试工具(软件测试工程师必备)
- 软件测试工程师必备技巧!(软件测试工程师入门教程)
- UE4基础知识总结(七)(ue4入门)
- Portkeys推出新款HDMI播放器:5.5英寸FHD屏幕,支持4K输入/输出
- 数字时代的纯粹,HiFiMan HM-901S 播放器体验
- CBN丨Double 11 sales shows resilience in China’s consumption
- AKG K812简单听感(akgk812pro评测)
- 盘点索尼Walkman发展史,哪台播放器让你印象深刻
- LUXMAN力仕 DA-07X 解码器#发烧hifi
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)