目录
一, ElasticSearch
集群基础环境初始化
准备三台虚拟机 IP地址为192.168.1.{105.106.107} ;hostname为master server1 server2
1.安装时间同步
[root@master ~]# yum -y install chrony [root@master ~]# vim /etc/chrony.conf ##修改配置文件 # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server ntp.aliyun.com iburst server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst [root@master ~]# systemctl enable --now chronyd ##设置开机自启 [root@master ~]# systemctl restart chronyd ##查看服务状态
二 .下载elasticsearch
[root@master ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.7-linux-x86_64.tar.gz ##下载linux tar包 [root@master ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.7-x86_64.rpm ##下载rpm包
三 .单点部署elasticsearch
安装elasticsearch
[root@master ~]# yum -y install elasticsearch-7.17.7-x86_64.rpm [root@master ~]# systemctl restart elasticsearch.service ##启动服务 [root@master ~]# systemctl status elasticsearch.service ● elasticsearch.service - Elasticsearch Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled) Active: active (running) since 三 2022-11-16 21:12:33 CST; 25s ago [root@master ~]# ss -ntl ##9200对外提供端口 9300 对内提供通信端口 State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::ffff:127.0.0.1]:9200 [::]:* LISTEN 0 128 [::1]:9200 [::]:* LISTEN 0 128 [::ffff:127.0.0.1]:9300 [::]:* LISTEN 0 128 [::1]:9300 [::]:*
修改配置文件
[root@master ~]# vim /etc/elasticsearch/elasticsearch.yml # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: elasticseach-666 ##修改集群名称 # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: master ##节点名称 # # ---------------------------------- Network ----------------------------------- # # By default Elasticsearch is only accessible on localhost. Set a different # address here to expose this node on the network: # network.host: 0.0.0.0 ##本机任意同网段都可以访问,默认是本机 # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.seed_hosts: ["host1", "host2"] discovery.seed_hosts: ["master","server1", "server2"] ##可以写主机名或ip地址。集群其他地址 [root@master ~]# systemctl restart elasticsearch.service
4.集群部署
[root@server1 ~]# yum -y install elasticsearch-7.17.7-x86_64.rpm ##节点安装elasticsearch [root@master ~]# scp /etc/elasticsearch/elasticsearch.yml @server1:/etc/elasticsearch/elasticsearch.yml elasticsearch.yml 100% 3476 4.6MB/s 00:00 [root@master ~]# scp /etc/elasticsearch/elasticsearch.yml @server2:/etc/elasticsearch/elasticsearch.yml elasticsearch.yml 100% 3476 3.7MB/s 00:00 ##将文件同步过去 [root@server1 ~]# vim /etc/elasticsearch/elasticsearch.yml ##修改节点名称 # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: server1 [root@master ~]# systemctl stop elasticsearch [root@master ~]# rm -f /var/log/elasticsearch/* [root@master ~]# rm -f /var/lib/elasticsearch/* [root@master ~]# systemctl restart elasticsearch //全部重新启动
查看集群状态
# --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.seed_hosts: ["host1", "host2"] discovery.seed_hosts: ["master","server1", "server2"] # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["master","server1", "server2"] [root@master elasticsearch]# curl 192.168.1.106:9200 { "name" : "server1", "cluster_name" : "elasticseach-666", "cluster_uuid" : "Jn2AyZx0S4y-7aOsX5bz3w", [root@master elasticsearch]# curl 192.168.1.107:9200 { "name" : "server2", "cluster_name" : "elasticseach-666", "cluster_uuid" : "Jn2AyZx0S4y-7aOsX5bz3w", ##查看集群 [root@master elasticsearch]# curl 192.168.1.107:9200/_cat/nodes 192.168.1.106 50 97 1 0.00 0.04 0.06 cdfhilmrstw * server1 192.168.1.105 55 93 1 0.00 0.03 0.05 cdfhilmrstw - master 192.168.1.107 55 96 1 0.00 0.04 0.05 cdfhilmrstw - server2