天天看點

centos7.5安裝Elasticsearch,Kibana,Logstash

環境要求:

# jdk 最低版本是8
java -version
echo $JAVA_HOME

# 作業系統:centos7
bash-4.2$ cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core) 

           

elasticsearch安裝步驟 官網

  1. 安裝

# 建議本地用迅雷下載下傳好傳上去,官方的yum源或者wget太慢了
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-x86_64.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-x86_64.rpm.sha512
shasum -a 512 -c elasticsearch-7.3.2-x86_64.rpm.sha512 
sudo rpm --install elasticsearch-7.3.2-x86_64.rpm
           
  1. 啟動

# 安裝完成之後,es會自動建立elasticsearch使用者和使用者組,官方的啟動方式是如下:
# 啟動
systemctl start elasticsearch

# 關閉
systemctl stop elasticsearch
           

但是,官方啟動我用的時候是有問題的,我還是比較喜歡按照套路來走,用elasticsearch使用者去進行相關操作

# 設定密碼(elasticsearch使用者群組已經建立,但是不能登入)
passwd elasticsearch
# 系統添加的預設使用者是不能登入的,需要更改/etc/passwd,改成如下
elasticsearch:x:996:994:elasticsearch user:/home/elasticsearch:/bin/bash
# 登入elasticsearch使用者
su elasticsearch
# 切換到安裝目錄執行
./bin/elasticsearch

           
  1. 插件安裝

# 檢視運作狀态
ps aux|grep elasticsearch

# 添加中文分詞插件
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.3.2/elasticsearch-analysis-ik-7.3.2.zip
# 重新開機es使之生效
systemctl restart elasticsearch
           
  1. 錯誤處理

  • max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
# 切換到root,在末尾處添加
1. vim /etc/security/limits.conf
*    hard    nofile    65536
*    soft    nofile    65536
root soft nproc 5000
root hard nproc 5000

2. 重新登入
           
  • max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
# 解決方案
1、切換到root使用者修改配置sysctl.conf
vim /etc/sysctl.conf 
添加下面配置:
vm.max_map_count=655360
并執行指令:
sysctl -p
           
  • the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
# 解決方案
編輯yml檔案,取消下面一行的注釋
# node.name: node-1 
更新叢集節點
cluster.initial_master_nodes: ["node-1"] 
           
  • Cannot open file /var/log/elasticsearch/gc.log due to Permission denied
# 給使用者添權重限
chown -R elasticsearch:elasticsearch /var/log/elasticsearch/
           
  1. 外網通路

# 更新elasticsearch.yml
network.host: 0.0.0.0
# 開放防火牆
# 開放端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent 
# 更新規則
firewall-cmd --reload
           
  1. 啟動與關閉

# elasticsearch 使用者執行
./bin/elasticsearch -d
ps -ef|grep elasticsearch|grep bootstrap |awk '{print $2}' |xargs kill -9
           
  1. 開機啟動

  • 腳本
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch

export JAVA_HOME=/usr/java/jdk1.8.0_221-amd64
export JAVA_BIN=/usr/java/jdk1.8.0_221-amd64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

case "$1" in
start)
    su elasticsearch<<!
    cd /usr/share/elasticsearch
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
stop)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    ;;
restart)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    su lyt<<!
    cd /usr/share/elasticsearch
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
*)
    echo "start|stop|restart"
    ;;
esac

exit $?
           
  • 設定開機啟動
cd /etc/init.d/
# 替換原有的elasticsearch檔案為上文的啟動腳本
# 添加到開機啟動
systemctl enable elasticsearch
           
  • 叢集環境配置

    伺服器有三台192.168.43.110,192.168.43.120,192.168.43.130

# 開放防火牆
firewall-cmd --zone=public --add-port=9300/tcp --permanent
firewall-cmd --reload
           

調整elasticsearch.yml配置檔案

# 叢集mingcheng
cluster.name: es_cluster
# 節點名稱,這兒我直接取名為 master
node.name: node-1
# 網絡綁定,這裡我綁定 0.0.0.0,支援外網通路
network.host: 0.0.0.0
# 設定對外服務的http端口,預設為9200
http.port: 9200
# 支援跨域通路
http.cors.enabled: true
http.cors.allow-origin: "*"
# 設定節點間互動的tcp端口,預設是9300
transport.tcp.port: 9300
# 手動指定可以成為 mater 的所有節點的 name 或者 ip,這些配置将會在第一次選舉中進行計算
cluster.initial_master_nodes:
                        - node-1
                        - node-2
                        - node-3
discovery.seed_hosts:
                - 192.168.43.110:9300
                - 192.168.43.120:9300
                - 192.168.43.130:9300
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
           

kibana安裝步驟

  1. 安裝

# 通過wget方式擷取,如果網絡不好,可以自己手動下載下傳上傳
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.3.2-x86_64.rpm
shasum -a 512 kibana-7.3.2-x86_64.rpm 
sudo rpm --install kibana-7.3.2-x86_64.rpm

cd kibana-7.3.2-linux-x86_64/bin

# 設定開機啟動
systemctl enable kibana.service
# 啟動服務 
systemctl start kibana.service
# 檢視啟動狀态
systemctl status kibana.service


# 如果通過安裝包,需要進行如下設定:添加到系統服務,設定開機啟動
cd /etc/systemd/system
vim kibana.service
#添加如下内容
[Service]
ExecStart=/opt/kibana-7.3.2-linux-x86_64/bin/kibana

[Install]
WantedBy=multi-user.target
# 重新整理 
systemctl daemon-reload

           
  1. kibana 配置

# 更改 /etc/kibana/kibana.yml
server.host: "0.0.0.0"
# 這裡面是http/https請求位址,不是域名和ip
elasticsearch.hosts: ["http://192.168.43.110:9200"]
# 配置el賬号密碼
elasticsearch.username: "elasticsearch"
elasticsearch.password: "elasticsearch"
           
  1. 開放防火牆

# 開放端口
firewall-cmd --zone=public --add-port=5601/tcp --permanent 
# 更新規則
firewall-cmd --reload
           

繼續閱讀