隨着Skywalking 6.0 GA版本的發佈,Skywalking終於支持Elasticsearch 6.x版本,本文作爲搭建Skywalking 6.0集羣系列文章的第一篇介紹下Elasticsearch 6.6集羣的搭建。
1. 準備
1.1 節點規劃
IP | cluster.name | node.name |
---|---|---|
10.130.10.11 | es_log | es_1 |
10.130.10.12 | es_log | es_2 |
10.130.10.13 | es_log | es_3 |
1.2 安裝Java運行環境JRE
wget -c -P /tmp https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u202-b08/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz
mkdir /usr/java;\
tar xf /tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz -C /usr/java;\
rm -rf /usr/java/default;\
ln -s /usr/java/jdk8u202-b08-jre /usr/java/default;\
tee -a /etc/profile << 'EOF'
export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
EOF
2. 安裝
2.1 導入Elasticserach軟件源
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch;\
tee /etc/yum.repos.d/elasticsearch.repo << 'EOF'
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
2.2 安裝軟件
yum install elasticsearch -y
2.3 配置Limit
- LimitMEMLOCK
開啓內存鎖定 - LimitNPROC
最大進程數,系統支持的最大進程數:32768
查看系統最大支持進程數:cat /proc/sys/kernel/pid_max
- LimitNOFILE
打開文件數,系統默認最大文件描述符:791020
查看系統最大文件描述符:cat /proc/sys/fs/file-max
mkdir /etc/systemd/system/elasticsearch.service.d;\
cat > /etc/systemd/system/elasticsearch.service.d/override.conf << 'EOF'
[Service]
Environment=JAVA_HOME=/usr/java/default
LimitMEMLOCK=infinity
LimitNOFILE=204800
LimitNPROC=4096
EOF
2.4 配置JVM(可選)
- 默認是2G
-
不要超過可用 RAM 的 50%
Lucene 能很好利用文件系統的緩存,它是通過系統內核管理的。如果沒有足夠的文件系統緩存空間,性能會受到影響。 此外,專用於堆的內存越多意味着其他所有使用 doc values 的字段內存越少
-
不要超過 32 GB
如果堆大小小於 32 GB,JVM 可以利用指針壓縮,這可以大大降低內存的使用:每個指針 4 字節而不是 8 字節
sed -i '/-Xms2g/c\-Xms3g' /etc/elasticsearch/jvm.options;\
sed -i '/-Xmx2g/c\-Xmx3g' /etc/elasticsearch/jvm.options
2.5 配置elasticsearch.yml
- cluster.name
集羣名稱,默認是elasticsearch,建議修改爲更明確的名稱,比如es_log
- node.name
節點名,默認隨機指定一個name列表中名字,建議修改爲明確的名稱,比如es_1,es_2,es_3
- network.host
主機IP
- path.data
數據目錄
- path.logs
日誌目錄
- discovery.zen.ping.unicast.hosts
節點發現
2.5.1 所有節點執行相同的命令
mkdir -p /home/elasticsearch/data /home/elasticsearch/logs;\
chown -R elasticsearch. /home/elasticsearch;\
sed -i '/cluster.name/c\cluster.name: es_log' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/network.host/c\network.host: 0.0.0.0' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/path.data/c\path.data: /home/elasticsearch/data' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/path.logs/c\path.logs: /home/elasticsearch/logs' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/discovery.zen.ping.unicast.hosts/c\discovery.zen.ping.unicast.hosts: ["10.130.10.11","10.130.10.12","10.130.10.13"]' /etc/elasticsearch/elasticsearch.yml
2.5.2 各個節點執行對應的命令
#節點-1
sed -i '/node.name/c\node.name: es_1' /etc/elasticsearch/elasticsearch.yml
#節點-2
sed -i '/node.name/c\node.name: es_2' /etc/elasticsearch/elasticsearch.yml
#節點-3
sed -i '/node.name/c\node.name: es_3' /etc/elasticsearch/elasticsearch.yml
2.6 啓動
systemctl enable elasticsearch;\
systemctl daemon-reload;\
systemctl start elasticsearch;\
systemctl status elasticsearch
2.7 配置防火牆
firewall-cmd --add-port=9200/tcp --permanent;\
firewall-cmd --add-port=9300/tcp --permanent;\
firewall-cmd --reload
3. 安裝中文分詞插件(可選)
#查看已安裝插件
/usr/share/elasticsearch/bin/elasticsearch-plugin list
#安裝IK
/usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.6.0/elasticsearch-analysis-ik-6.6.0.zip
4. 查詢
#查看節點信息
curl -X GET http://localhost:9200/_nodes
#打開文件數信息
curl -X GET http://localhost:9200/_nodes/stats/process?filter_path=**.max_file_descriptors
#集羣健康狀態
curl -X GET http://localhost:9200/_cat/health?v
#查看集羣索引數
curl -X GET http://localhost:9200/_cat/indices?v
#查看磁盤分配情況
curl -X GET http://localhost:9200/_cat/allocation?v
#查看集羣節點
curl -X GET http://localhost:9200/_cat/nodes?v
#查看集羣其他信息
curl -X GET http://localhost:9200/_cat