logo
0
0
Login
🔧 chore: 更新 Elasticsearch 镜像名称和 CRL 分发点 URL

时间同步

chmod +x /etc/rc.d/rc.local 00 01 * * * /usr/sbin/ntpdate -u cn.pool.ntp.org

docker镜像(官方)

docker.cnb.cool/zhiqiangwang/elasticsearch:5.6.5 docker.cnb.cool/zhiqiangwang/elasticsearch:kibana-5.6.5

安装

创建用户

useradd elasticsearch passwd -l elasticsearch

上传并解压

tar -zxvf jdk-8u201-linux-x64.tar.gz mv jdk-8u201-linux-x64 /usr/local/java1.8

配置环境变量 /etc/profile

# Java Environment Variables export JAVA_HOME=/usr/local/java1.8 export JRE_HOME=$JAVA_HOME/jre export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

安装 OpenSSL

yum install openssl

配置系统文件使用数量

/etc/sysctl.conf 中添加以下内容

vm.max_map_count=262144

/etc/security/limits.conf 中添加以下内容

* - nofile 65536 * - memlock unlimited

安装 Elasticsearch

tar -zxvf elasticsearch-5.6.5.tar.gz chown elasticsearch:elasticsearch elasticsearch-5.6.5/ -R

安装插件search-guard-5

bin/elasticsearch-plugin install -b com.floragunn:search-guard-5:5.6.5-19.1

生成新节点证书

./gen_node_cert.sh 3 changeit capass

node-3*ca/root-ca.pemca/truststore.jks 文件复制到新节点服务器目录 elasticsearch/config/

修改 Elasticsearch 配置 elasticsearch.yml

cp elasticsearch.yml -/config/elasticsearch.yml

检查证书过期日期

[root@iZbp15b6kfepaf1vdu47unZ ca]# openssl x509 -noout -in node-1.crt.pem -dates notBefore=Dec 3 12:24:22 2025 GMT notAfter=Dec 3 12:24:22 2027 GMT

常见命令

在控制台输出日志启动

bin/elasticsearch

守护进程启动

bin/elasticsearch -d

停止

ps aux |grep elasticsearch kill 32225

常见的curl操作

检查集群状态

curl -XGET "http://localhost:9200/_cluster/health?pretty"

检查集群状态

curl -XGET "http://localhost:9200/_cluster/health?pretty"

禁用自动分片分配

curl -XPUT http://localhost:9200/_cluster/settings -d '{ "transient" : { "cluster.routing.allocation.enable" : "none" } }' 或者 curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{ "persistent" : { "cluster.routing.allocation.enable" : "none" }, "transient" : { "cluster.routing.allocation.enable" : "none" } }'

当集群状态为绿色时,启用自动分片分配

curl -XPUT http://localhost:9200/_cluster/settings -d '{ "transient" : { "cluster.routing.allocation.enable" : "all" } }' 或者 curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{ "persistent" : { "cluster.routing.allocation.enable" : "none" }, "transient" : { "cluster.routing.allocation.enable" : "all" } }'

如果集群没有设置持久化的自动分片参数,不要单独使用 persistent 来禁用自动分片。它要等到整个集群重启后才会生效,而且如果关闭单个节点,可能会导致分片迁移到其他节点。