elasticsearch啓動常見錯誤

由於安全問題elasticsearch 不讓用root用戶直接運行,因此要建立新用戶。
具體操做以下:
useradd es
passwd es
再輸入兩次密碼(自定義)

mkdir -p /export/servers/data

mkdir -p /export/servers/logs

chown -R es:es /export/servers/elasticsearch

chown -R es:es /export/servers/data

chown -R es:es /export/servers/logs

而後使用es用戶啓動

切換es用戶命令:su es

cd /export/servers/elasticsearch
啓動集羣命令:bin/elasticsearch
---------------------
做者:NicholasEcho
來源:CSDN
原文:https://blog.csdn.net/weixin_41615494/article/details/79591335
版權聲明:本文爲博主原創文章,轉載請附上博文連接!html

原文:https://www.cnblogs.com/zhi-leaf/p/8484337.htmljava

問題出現環境,OS版本:CentOS-7-x86_64-Minimal-1708;ES版本:elasticsearch-6.2.2。node

一、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]linux

  每一個進程最大同時打開文件數過小,可經過下面2個命令查看當前數量nginx

ulimit -Hn ulimit -Sn

  修改/etc/security/limits.conf文件,增長配置,用戶退出後從新登陸生效web

* soft nofile 65536 * hard nofile 65536

 

二、max number of threads [3818] for user [es] is too low, increase to at least [4096]json

  問題同上,最大線程個數過低。修改配置文件/etc/security/limits.conf,增長配置bootstrap

1
2
*               soft    nproc           4096
*               hard    nproc           4096

  可經過命令查看vim

ulimit -Hu ulimit -Su

 

三、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]centos

  修改/etc/sysctl.conf文件,增長配置vm.max_map_count=262144

vi /etc/sysctl.conf
sysctl -p

  執行命令sysctl -p生效

 四、Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch/elasticsearch-6.2.2-1/config/jvm.options

  elasticsearch用戶沒有該文件夾的權限,執行命令

 

 

5.Elasticsearch在linux下使用命令sh elasticsearch start,按鍵ctrl+c的時候程序就會stop掉,如何將程序在後臺啓動呢?
須要使用:./elasticsearch -d
這時執行的時候會出現沒有權限./elasticsearch: Permission denied
須要受權執行命令:chmod +x bin/elasticsearch
再次執行./elasticsearch -d便可啓動
使用ps aux|grep elasticsearch能夠查看是否啓動


 

 

6.

第一個是es的基本配置文件,第二個是日誌配置文件,es也是使用log4j來記錄日誌的,因此logging.yml裏的設置按普通log4j配置文件來設置就好了。下面主要講解下elasticsearch.yml這個文件中可配置的東西。
cluster.name:elasticsearch
配置es的集羣名稱,默認是elasticsearch,es會自動發如今同一網段下的es,若是在同一網段下有多個集羣,就能夠用這個屬性來區分不一樣的集羣。
node.name:」FranzKafka」
節點名,默認隨機指定一個name列表中名字,該列表在es的jar包中config文件夾裏name.txt文件中,其中有不少做者添加的有趣名字。
node.master:true
指定該節點是否有資格被選舉成爲node,默認是true,es是默認集羣中的第一臺機器爲master,若是這臺機掛了就會從新選舉master。
node.data:true
指定該節點是否存儲索引數據,默認爲true。
index.number_of_shards:5
設置默認索引分片個數,默認爲5片。
index.number_of_replicas:1
設置默認索引副本個數,默認爲1個副本。
path.conf:/path/to/conf
設置配置文件的存儲路徑,默認是es根目錄下的config文件夾。
path.data:/path/to/data
設置索引數據的存儲路徑,默認是es根目錄下的data文件夾,能夠設置多個存儲路徑,用逗號隔開,例:
path.data:/path/to/data1,/path/to/data2
path.work:/path/to/work
設置臨時文件的存儲路徑,默認是es根目錄下的work文件夾。
path.logs:/path/to/logs
設置日誌文件的存儲路徑,默認是es根目錄下的logs文件夾
path.plugins:/path/to/plugins
設置插件的存放路徑,默認是es根目錄下的plugins文件夾
bootstrap.mlockall:true
設置爲true來鎖住內存。由於當jvm開始swapping時es的效率會下降,因此要保證它不swap,能夠把ES_MIN_MEM和ES_MAX_MEM兩個環境變量設置成同一個值,而且保證機器有足夠的內存分配給es。同時也要容許elasticsearch的進程能夠鎖住內存,linux下能夠經過`ulimit-lunlimited`命令。
network.bind_host:192.168.0.1
設置綁定的ip地址,能夠是ipv4或ipv6的,默認爲0.0.0.0。network.publish_host:192.168.0.1
設置其它節點和該節點交互的ip地址,若是不設置它會自動判斷,值必須是個真實的ip地址。
network.host:192.168.0.1
這個參數是用來同時設置bind_host和publish_host上面兩個參數。
transport.tcp.port:9300
設置節點間交互的tcp端口,默認是9300。
transport.tcp.compress:true
設置是否壓縮tcp傳輸時的數據,默認爲false,不壓縮。
http.port:9200
設置對外服務的http端口,默認爲9200。
http.max_content_length:100mb
設置內容的最大容量,默認100mb
http.enabled:false
是否使用http協議對外提供服務,默認爲true,開啓。
gateway.type:local
gateway的類型,默認爲local即爲本地文件系統,能夠設置爲本地文件系統,分佈式文件系統,hadoop的HDFS,和amazon的s3服務器,其它文件系統的設置方法下次再詳細說。
gateway.recover_after_nodes:1
設置集羣中N個節點啓動時進行數據恢復,默認爲1。
gateway.recover_after_time:5m
設置初始化數據恢復進程的超時時間,默認是5分鐘。
gateway.expected_nodes:2
設置這個集羣中節點的數量,默認爲2,一旦這N個節點啓動,就會當即進行數據恢復。
cluster.routing.allocation.node_initial_primaries_recoveries:4
初始化數據恢復時,併發恢復線程的個數,默認爲4。
cluster.routing.allocation.node_concurrent_recoveries:2
添加刪除節點或負載均衡時併發恢復線程的個數,默認爲4。
indices.recovery.max_size_per_sec:0
設置數據恢復時限制的帶寬,如入100mb,默認爲0,即無限制。
indices.recovery.concurrent_streams:5
設置這個參數來限制從其它分片恢復數據時最大同時打開併發流的個數,默認爲5。
discovery.zen.minimum_master_nodes:1
設置這個參數來保證集羣中的節點能夠知道其它N個有master資格的節點。默認爲1,對於大的集羣來講,能夠設置大一點的值(2-4)
discovery.zen.ping.timeout:3s
設置集羣中自動發現其它節點時ping鏈接超時時間,默認爲3秒,對於比較差的網絡環境能夠高點的值來防止自動發現時出錯。
discovery.zen.ping.multicast.enabled:false
設置是否打開多播發現節點,默認是true。
discovery.zen.ping.unicast.hosts:[「host1″,」host2:port」,」host3[portX-portY]」]
設置集羣中master節點的初始列表,能夠經過這些節點來自動發現新加入集羣的節點

安裝head插件(集羣管理插件)

cd /usr/share/elasticsearch/bin/
./plugin install mobz/elasticsearch-head
ll /usr/share/elasticsearch/plugins/head
http://192.168.2.215:9200/_plugin/head/


安裝kopf插件(集羣資源查看和查詢插件)
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
http://192.168.2.215:9200/_plugin/kopf

啓動elasticearch
/etc/init.d/elasticsearch start

安裝kibana
kibana本質上是elasticsearch web客戶端,是一個分析和可視化elasticsearch平臺,可經過kibana搜索、查看和與存儲在elasticsearch的索引進行交互。能夠很方便的執行先進的數據分析和可視化多種格式的數據,如圖表、表格、地圖等。

Discover頁面:交互式的瀏覽數據。能夠訪問所匹配的索引模式的每一個索引的每一個文檔。能夠提交搜索查詢,過濾搜索結果和查看文檔數據。還能夠搜索查詢匹配的文檔數據和字段值的統計數據。還能夠選定時間以及刷新頻率
https://download.elastic.co/kibana/kibana/kibana-4.5.1-linux-x64.tar.gz
tar zxvf kibana-4.5.1-linux-x64.tar.gz
mv kibana-4.5.1-linux-x64 /usr/local/
vi /etc/rc.local
/usr/local/kibana-4.5.1-linux-x64/bin/kibana > /var/log/kibana.log 2>&1 &
vi /usr/local/kibana-4.5.1-linux-x64/config/kibana.yml
server.port: 5601
server.host: "192.168.2.215"
elasticsearch.url: "http://192.168.2.215:9200"

將nginx日誌轉換成json

vim /usr/local/nginx/conf/nginx.conf
log_format access1 '{"@timestamp":"$time_iso8601",'
        '"host":"$server_addr",'
        '"clientip":"$remote_addr",'
        '"size":$body_bytes_sent,'
        '"responsetime":$request_time,'
        '"upstreamtime":"$upstream_response_time",'
        '"upstreamhost":"$upstream_addr",'
        '"http_host":"$host",'
        '"url":"$uri",'
        '"domain":"$host",'
        '"xff":"$http_x_forwarded_for",'
        '"referer":"$http_referer",'
        '"status":"$status"}';
    access_log  /var/log/nginx/access.log  access1;

從新載入nginx

/usr/local/nginx/sbin/nginx -s reload

安裝logstash
在logstash中,包括了三個階段:
輸入input --> 處理filter(不是必須的) --> 輸出output

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
echo "
[logstash-2.1]
name=Logstash repository for 2.1.x packages
baseurl=http://packages.elastic.co/logstash/2.1/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1" >> /etc/yum.repos.d/logstash.repo
yum install logstash -y
經過配置驗證Logstash的輸入和輸出
vim /etc/logstash/conf.d/stdout.conf
input {
        stdin {}
}

output {
        stdout {
                codec => "rubydebug"
        }
}

vim /etc/logstash/conf.d/logstash.conf
input {
        stdin {}
}
input {
        stdin {}
 }
output {
        elasticsearch {
                hosts => ["192.168.2.215:9200"]
                index => "test"
        }
}

http://192.168.2.215:9200/_plugin/head/

vim /etc/logstash/conf.d/logstash.conf
output {
        elasticsearch {
                hosts => ["192.168.2.215:9200"]
                index => "test"
        }
input {
        file {
          type => "messagelog"
          path => "/var/log/messages"
          start_position => "beginning"
        }
}
output {
        file {
          path => "/tmp/123.txt"
        }
        elasticsearch {
                hosts => ["192.168.2.215:9200"]
                index => "system-messages-%{+yyyy.MM.dd}"
        }
}

檢查配置文件語法
/etc/init.d/logstash configtest

vim /etc/init.d/logstash
LS_USER=root
LS_GROUP=root

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/logstash.conf &

 

 

 

chown -R es:es /usr/local/elasticsearch/
相關文章
相關標籤/搜索