
系统ubuntu20.04
es集群: 对于ES集群来说,一旦环境搭建好之后,最好不要乱动主机名 一旦乱动主机名,集群崩溃 -- 或者数据不同步 如果不小心更新了主机名? 重新搭建环境 - 首先删除 /var/lib/elasticsearch/nodes/0/ 目录下的文件
ip规划
172.16.0.160 elastic-master.sswang.com elastic-master 172.16.0.161 elastic-slave1.sswang.com elastic-slave1 172.16.0.162 elastic-slave2.sswang.com elastic-slave1
首先三台机器修改主机名
172.16.0.160 root@elastic-master:~# hostnamectl set-hostname elastic-master 172.16.0.161 root@elastic-slave:~# hostnamectl set-hostname elastic-slave1 172.16.0.162 root@elastic-slave:~# hostnamectl set-hostname elastic-slave2
修改hosts做主机名解析
#三台机器同时写入 172.16.0.160 elastic-master.sswang.com elastic-master 172.16.0.161 elastic-slave1.sswang.com elastic-slave2 172.16.0.162 elastic-slave2.sswang.com elastic-slave3
首先在172.16.0.160上面做好免密码的密钥
root@elastic-master:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa Your public key has been saved in /root/.ssh/id_rsa.pub The key fingerprint is: SHA256:7rtIY8pjy1NIr7ijAmxv5Xa8dBd2C6QHHz2w0s1JBpg root@elastic-master The key's randomart image is: +---[RSA 3072]----+ | oo.o | | E. O . | | o = * | | . * . . | |. . o S. * . | |.o ..o. o + . | |o ..oo=... . . | |. o==*.*. . | |o.o+*+o.=o | +----[SHA256]-----+
再把做好的密钥文件拷贝到172.16.0.161和172.16.0.162上面去
root@elastic-master:~# ssh-copy-id elastic-slave1 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'elastic-slave1 (172.16.0.161)' can't be established. ECDSA key fingerprint is SHA256:e6246AoozwtEjYmPqU/mS4fWncpxKvoXtPgl9ZswNwQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes 输入yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@elastic-slave1's password: 输入密码 Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'elastic-slave1'" and check to make sure that only the key(s) you wanted were added. root@elastic-master:~# ssh-copy-id elastic-slave2 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'elastic-slave2 (172.16.0.162)' can't be established. ECDSA key fingerprint is SHA256:e6246AoozwtEjYmPqU/mS4fWncpxKvoXtPgl9ZswNwQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes 输入yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@elastic-slave2's password: 输入密码 Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'elastic-slave2'" and check to make sure that only the key(s) you wanted were added. root@elastic-master:~# ssh-copy-id elastic-master /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'elastic-master (172.16.0.160)' can't be established. ECDSA key fingerprint is SHA256:e6246AoozwtEjYmPqU/mS4fWncpxKvoXtPgl9ZswNwQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes 输入yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@elastic-master's password: 输入密码 Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'elastic-master'" and check to make sure that only the key(s) you wanted were added.
,
上面的做了这个就不用做配置了 首先安装expect apt install expect -y 生成密钥 ssh-keygen -t rsa -p "" -f /root/.ssh/id_rsa
脚本密钥免手动配置
for i in {160..162}
do
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.0.$i
expect {
\"*yes/no*\" {send \"yes\r\";exp_continue}
\"*password*\" {send \"123456\r\"; exp_continue}
\"*password*\" {send \"123456\r\";}
}"
done
172.16.0.160安装jdk
上传jdk包
包名jdk-8u261-linux-x64.tar.gz
安装jdk,首先创建目录,172.16.0.160上面操作
root@elastic-master:~# mkdir -p /data/{softs,server}
解压jdk到/data/server下
root@elastic-master:~# tar -xf jdk-8u261-linux-x64.tar.gz -C /data/server/
创建软连接,方便后期升级调用
root@elastic-master:~# ln -s /data/server/jdk1.8.0_261/ /data/server/java
配置jdk的全局环境变量
root@elastic-master:~# echo 'export JAVA_HOME=/data/server/java' >> /etc/profile
root@elastic-master:~# echo 'export JRE_HOME=$JAVA_HOME/jre' >> /etc/profile
root@elastic-master:~# echo 'export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/liv/dt.jat' >> /etc/profile
root@elastic-master:~# echo 'export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH' >> /etc/profile
让环境变量生效
root@elastic-master:~# source /etc/profile
root@elastic-master:~# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
172.16.0.161安装jdk
上传jdk包
包名jdk-8u261-linux-x64.tar.gz
安装jdk,首先创建目录,172.16.0.161上面操作
root@elastic-slave1:~#r:~# mkdir -p /data/{softs,server}
解压jdk到/data/server下
root@elastic-master:~# tar -xf jdk-8u261-linux-x64.tar.gz -C /data/server/
创建软连接,方便后期升级调用
root@elastic-slave1:~# ln -s /data/server/jdk1.8.0_261/ /data/server/java
配置jdk的全局环境变量
root@elastic-slave1:~# echo 'export JAVA_HOME=/data/server/java' >> /etc/profile
root@elastic-slave1:~# echo 'export JRE_HOME=$JAVA_HOME/jre' >> /etc/profile
root@elastic-slave1:~# echo 'export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/liv/dt.jat' >> /etc/profile
root@elastic-slave2:~# echo 'export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH' >> /etc/profile
让环境变量生效
root@elastic-slave1:~# source /etc/profile
root@elastic-slave1:~# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)172.16.0.162安装jd
上传jdk包
包名jdk-8u261-linux-x64.tar.gz
安装jdk,首先创建目录,172.16.0.162上面操作
root@elastic-slave2:~#r:~# mkdir -p /data/{softs,server}
解压jdk到/data/server下
root@elastic-master:~# tar -xf jdk-8u261-linux-x64.tar.gz -C /data/server/
创建软连接,方便后期升级调用
root@elastic-slave2:~# ln -s /data/server/jdk1.8.0_261/ /data/server/java
配置jdk的全局环境变量
root@elastic-slave2:~# echo 'export JAVA_HOME=/data/server/java' >> /etc/profile
root@elastic-slave2:~# echo 'export JRE_HOME=$JAVA_HOME/jre' >> /etc/profile
root@elastic-slave2:~# echo 'export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/liv/dt.jat' >> /etc/profile
root@elastic-slave2:~# echo 'export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH' >> /etc/profile
让环境变量生效
root@elastic-slave2:~# source /etc/profile
root@elastic-slave2:~# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)172.16.0.160安装Elasticsearch 7.14.0
上传Elasticsearch 7.14.0的包 下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-14-0 包名Elasticsearch 7.14.0 安装Elasticsearch 7.14.0 root@elastic-master:~# dpkg -i elasticsearch-7.14.0-amd64.deb 返回结果: Selecting previously unselected package elasticsearch. (Reading database ... 76547 files and directories currently installed.) Preparing to unpack elasticsearch-7.14.0-amd64.deb ... Creating elasticsearch group... OK Creating elasticsearch user... OK Unpacking elasticsearch (7.14.0) ... Setting up elasticsearch (7.14.0) ... ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set. Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore Processing triggers for systemd (245.4-4ubuntu3.11) ...
Elasticsearch配置文件文件存放路径
Elasticsearch配置文件文件存放路径
,
先备份配置文件
root@elastic-master:~# cp /etc/elasticsearch/elasticsearch.yml{,.bak}
root@elastic-master:~# vim /etc/elasticsearch/elasticsearch.yml
内容
#cluster.name: my-application
es集群的名称
#node.name: node-1
集群内的机器主机名或者ip地址
path.data: /var/lib/elasticsearch
数据库存储目录的详细位置,如果有单独的分区或者高性能的磁盘可以把目录改成相应的目录里
path.logs: /var/log/elasticsearch
日志存放目录
#network.host: 192.168.0.1
对外的ip地址,建议改成0.0.0.0
#http.port: 9200
对外的端口,客户端端口,数据内部通讯端口为9300
#discovery.seed_hosts: ["host1", "host2"]
主机发现,集群
#cluster.initial_master_nodes: ["node-1", "node-2"]
在初始化的时候谁可以做为主,可以多台同时作为主172.16.0.160修改配置文件elasticsearch.yml
root@elastic-master:~# vim /etc/elasticsearch/elasticsearch.yml 如下内容 # ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: elastic.example.com # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: 172.16.0.160 # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /var/lib/elasticsearch # # Path to log files: # path.logs: /var/log/elasticsearch # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- 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 # # By default Elasticsearch listens for HTTP traffic on the first free port it # finds starting at 9200. Set a specific HTTP port here: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- 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: ["172.16.0.160", "172.16.0.161", "172.16.0.162"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["172.16.0.160", "172.16.0.161", "172.16.0.162"] # # For more information, consult the discovery and cluster formation module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true # # 开启跨域访问支持,默认为false http.cors.enabled: true # 跨域访问允许的域名地址,(允许所有域名)以上使用正则 http.cors.allow-origin: "*"
172.16.0.161安装Elasticsearch 7.14.0
上传Elasticsearch 7.14.0的包 下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-14-0 包名Elasticsearch 7.14.0 安装Elasticsearch 7.14.0 root@elastic-slave1:~# dpkg -i elasticsearch-7.14.0-amd64.deb 返回结果: Selecting previously unselected package elasticsearch. (Reading database ... 76547 files and directories currently installed.) Preparing to unpack elasticsearch-7.14.0-amd64.deb ... Creating elasticsearch group... OK Creating elasticsearch user... OK Unpacking elasticsearch (7.14.0) ... Setting up elasticsearch (7.14.0) ... ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set. Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore Processing triggers for systemd (245.4-4ubuntu3.11) ...
修改配置文件
root@elastic-slave1:~# vim /etc/elasticsearch/elasticsearch.yml
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: elastic.example.com # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: 172.16.0.161 # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /var/lib/elasticsearch # # Path to log files: # path.logs: /var/log/elasticsearch # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- 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 # # By default Elasticsearch listens for HTTP traffic on the first free port it # finds starting at 9200. Set a specific HTTP port here: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- 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: ["172.16.0.160", "172.16.0.161", "172.16.0.162"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["172.16.0.160", "172.16.0.161", "172.16.0.162"] # # For more information, consult the discovery and cluster formation module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true # # 开启跨域访问支持,默认为false http.cors.enabled: true # 跨域访问允许的域名地址,(允许所有域名)以上使用正则 http.cors.allow-origin: "*"
172.16.0.162安装Elasticsearch 7.14.0
上传Elasticsearch 7.14.0的包 下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-14-0 包名Elasticsearch 7.14.0 安装Elasticsearch 7.14.0 root@elastic-slave2:~# dpkg -i elasticsearch-7.14.0-amd64.deb 返回结果: Selecting previously unselected package elasticsearch. (Reading database ... 76547 files and directories currently installed.) Preparing to unpack elasticsearch-7.14.0-amd64.deb ... Creating elasticsearch group... OK Creating elasticsearch user... OK Unpacking elasticsearch (7.14.0) ... Setting up elasticsearch (7.14.0) ... ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set. Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore Processing triggers for systemd (245.4-4ubuntu3.11) ...
修改配置文件
root@elastic-slave2:~# vim /etc/elasticsearch/elasticsearch.yml
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: elastic.example.com # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: 172.16.0.162 # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /var/lib/elasticsearch # # Path to log files: # path.logs: /var/log/elasticsearch # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- 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 # # By default Elasticsearch listens for HTTP traffic on the first free port it # finds starting at 9200. Set a specific HTTP port here: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- 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: ["172.16.0.160", "172.16.0.161", "172.16.0.162"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["172.16.0.160", "172.16.0.161", "172.16.0.162"] # # For more information, consult the discovery and cluster formation module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true # # 开启跨域访问支持,默认为false http.cors.enabled: true # 跨域访问允许的域名地址,(允许所有域名)以上使用正则 http.cors.allow-origin: "*"
启动Elasticsearch,三台同时启动
root@elastic-master:~# systemctl enable elasticsearch.service --now root@elastic-slave1:~# systemctl enable elasticsearch.service --now root@elastic-slave2:~# systemctl enable elasticsearch.service --now
查看Elasticsearch的状态
root@elastic-master:~# curl 172.16.0.160:9200
{
"name" : "172.16.0.160",
"cluster_name" : "elastic.example.com",
"cluster_uuid" : "HaBrBW50QWOtf0w3_zWWaw",
"version" : {
"number" : "7.14.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1",
"build_date" : "2021-07-29T20:49:32.864135063Z",
"build_snapshot" : false,
"lucene_version" : "8.9.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
解释:
"name" : "172.16.0.160"
主机节点
"cluster_name" : "elastic.example.com"
集群的名称
"cluster_uuid" : "HaBrBW50QWOtf0w3_zWWaw"
集群的唯一id
"tagline" : "You Know, for Search"
标签root@elastic-master:~# curl 172.16.0.161:9200
{
"name" : "172.16.0.161",
"cluster_name" : "elastic.example.com",
"cluster_uuid" : "HaBrBW50QWOtf0w3_zWWaw",
"version" : {
"number" : "7.14.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1",
"build_date" : "2021-07-29T20:49:32.864135063Z",
"build_snapshot" : false,
"lucene_version" : "8.9.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}root@elastic-master:~# curl 172.16.0.162:9200
{
"name" : "172.16.0.162",
"cluster_name" : "elastic.example.com",
"cluster_uuid" : "HaBrBW50QWOtf0w3_zWWaw",
"version" : {
"number" : "7.14.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1",
"build_date" : "2021-07-29T20:49:32.864135063Z",
"build_snapshot" : false,
"lucene_version" : "8.9.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}浏览器访问
http://172.16.0.160:9200

用浏览器查看es里面有那些内容
http://172.16.0.160:9200/_cat

查看es的主节点的状态
http://172.16.0.160:9200/_cat/master

查看es的node节点的状态
http://172.16.0.160:9200/_cat/nodes

解释: 172.16.0.162 14 96 0 0.20 0.22 0.33 cdfhilmrstw * 172.16.0.162 * 这里的*表示选择了这台节点做为主节点
查看集群状态
http://172.16.0.160:9200/_cat/health

解释: 集群中有三种颜色,黄色,红色,绿色 yellow黄色 集群中,有一台主机异常,不影响整体服务 red红色 集群崩溃 green绿色 集群中的所有节点运行正常
查看索引
root@elastic-master:~# curl -XGET 172.16.0.160:9200/_cat/indices
查看集群节点
root@elastic-master:~# curl -XGET 172.16.0.160:9200/_cat/nodes
查看索引
root@elastic-master:~# curl -XGET 172.16.0.160:9200/_cat/indices
创建索引
root@elastic-master:~# curl -XPUT 172.16.0.160:9200/index_test root@elastic-master:~# curl -XGET 172.16.0.160:9200/_cat/indices
格式化展示
root@elastic-master:~# curl 172.16.0.160:9200/index_test?pretty
{
"index_test" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "index_test",
"creation_date" : "1657719071339",
"number_of_replicas" : "1",
"uuid" : "NKFiLL1ATE6sPGBRzPt55w",
"version" : {
"created" : "7140099"
}
}
}
}
}
解释:
"number_of_shards" : "1",
数据切片,提高吞吐量
"number_of_replicas" : "1",
每台都有一个副本,实现高可用
删除索引
root@elastic-master:~# curl -XDELETE 172.16.0.160:9200/index_test root@elastic-master:~# curl -XGET 172.16.0.160:9200/_cat/indices
批量删除
curl -s http://172.16.0.160:9200/_cat/indices | awk '{print $3}'
for index in $(curl -s http://172.16.0.160:9200/_cat/indices | awk '{print $3}')
do
curl -XDELETE 172.16.0.160:9200/$index
done修改切片属性
curl -X PUT 172.16.0.160:9200/index_test -H 'Content-Type:application/json' -d '
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
}'
curl 172.16.0.160:9200/index_test?pretty在设置切片属性的时候,一定要注意在历史数据中,最好不要存在同名的索引,否则报错
给elasticsearch的相关命令添加上环境变量,默认安装的没有环境变量,系统无法识别到这些命令
root@elastic-master:~# echo 'export PATH=/usr/share/elasticsearch/bin:$PATH' >> /etc/profile.d/elasticsearch.sh root@elastic-master:~# source /etc/profile.d/elasticsearch.sh
常见插件
常见插件: 分词插件:analysis-icu、analysis-ik、等 管理插件:head、kopf、bigdest、等 注意: 随着elasticsearch的版本更新,很多之前可以直接安装的插件,目前无法直接安装了, 需要采取自定义的方式来安装 旧的插件地址 https://www.elastic.co/guide/en/elasticsearch/plugins/2.4/management.html 官方地址 https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html
,
root@elastic-master:~# elasticsearch-plugin list warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
如果安装失败重新再安装一边就行了,这里安装是需要联网的
root@elastic-master:~# elasticsearch-plugin install analysis-smartcn warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set. -> Installing analysis-smartcn -> Downloading analysis-smartcn from elastic [=================================================] 100% -> Installed analysis-smartcn -> Please restart Elasticsearch to activate any plugins installed root@elastic-master:~# elasticsearch-plugin install analysis-icu warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set. -> Installing analysis-icu -> Downloading analysis-icu from elastic [=================================================] 100% -> Installed analysis-icu -> Please restart Elasticsearch to activate any plugins installed root@elastic-master:~# systemctl restart elasticsearch.service
172.16.0.161安装插件,掠过安装返回结果
#先来添加环境变量 root@elastic-slave1:~# echo 'export PATH=/usr/share/elasticsearch/bin:$PATH' >> /etc/profile.d/elasticsearch.sh root@elastic-slave1:~# source /etc/profile.d/elasticsearch.sh root@elastic-slave1:~# elasticsearch-plugin install analysis-smartcn root@elastic-slave1:~# elasticsearch-plugin install analysis-icu root@elastic-slave1:~# systemctl restart elasticsearch.service
,
#先来添加环境变量 root@elastic-slave2:~# echo 'export PATH=/usr/share/elasticsearch/bin:$PATH' >> /etc/profile.d/elasticsearch.sh root@elastic-slave2:~# source /etc/profile.d/elasticsearch.sh root@elastic-slave2:~# elasticsearch-plugin install analysis-smartcn root@elastic-slave2:~# elasticsearch-plugin install analysis-icu root@elastic-slave2:~# systemctl restart elasticsearch.service
检查安装结果
root@elastic-slave2:~# elasticsearch-plugin list warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME Future versions of Elasticsearch will require Java 11; your Java version from [/data/server/jdk1.8.0_261/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set. analysis-icu analysis-smartcn
离线方式安装,把插件下载好以后放到/usr/share/elasticsearch/plugins/的目录即可
root@elastic-slave2:~# ls /usr/share/elasticsearch/ NOTICE.txt README.asciidoc bin jdk lib modules plugins root@elastic-slave2:~# ls /usr/share/elasticsearch/plugins/ analysis-icu analysis-smartcn #这个目录是存放离线插件的位置
