[TOC]
### 目錄結構
假設安裝在 /opt/elk6目錄下
整體目錄為
```
root@test:~# tree -d -L 2 /opt/
/opt/
└── elk6
├── elasticsearch -> elasticsearch-6.1.2/
├── elasticsearch-6.1.2
├── elasticsearch-head
├── kibana -> kibana-6.1.2-linux-x86_64/
├── kibana-6.1.2-linux-x86_64
├── logstash -> logstash-6.1.2/
└── logstash-6.1.2
```
elasticsearch目錄為
```
root@Haproxy-A:/opt/elk6# tree -Ld 1 elasticsearch
elasticsearch
├── bin
├── config
├── default
├── lib
├── logs
├── modules
├── pid
└── plugins
```
### 目錄用戶要非root
```
root@test:/opt# ls -lh elk6/
total 16K
lrwxrwxrwx 1 elasticsearch elasticsearch 20 Jan 19 17:31 elasticsearch -> elasticsearch-6.1.2/
drwxr-xr-x 10 elasticsearch elasticsearch 4.0K Feb 28 14:35 elasticsearch-6.1.2
drwxr-xr-x 8 root root 4.0K Jan 19 19:08 elasticsearch-head
lrwxrwxrwx 1 elasticsearch elasticsearch 26 Jan 19 17:32 kibana -> kibana-6.1.2-linux-x86_64/
drwxrwxr-x 16 elasticsearch elasticsearch 4.0K Jan 19 18:12 kibana-6.1.2-linux-x86_64
lrwxrwxrwx 1 root root 15 Jan 19 17:32 logstash -> logstash-6.1.2/
drwxr-xr-x 11 root root 4.0K Jan 19 17:31 logstash-6.1.2
```
### 主配置文件
```
root@test:~# cat /opt/elk6/elasticsearch/config/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: elk6
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: elk6-node-1
#
# 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: /data/elk6_data
#
# Path to log files:
#
path.logs: /opt/elk6/elasticsearch/logs
#
# ----------------------------------- 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 -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.100.100
#
# Set a custom port for HTTP:
#
http.port: 9500
transport.tcp.port: 9600
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.5.30:9600"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"
```
### default環境變量文件
```
root@test:~# cat /opt/elk6/elasticsearch/default/elasticsearch
################################
# Elasticsearch
################################
# Elasticsearch home directory
ES_HOME=/opt/elk6/elasticsearch
# Elasticsearch Java path
JAVA_HOME=/application/jdk
# Elasticsearch configuration directory
ES_PATH_CONF=/opt/elk6/elasticsearch/config
# Elasticsearch PID directory
PID_DIR=/opt/elk6/elasticsearch/pid
# Additional Java OPTS
#ES_JAVA_OPTS=
# Configure restart on package upgrade (true, every other setting will lead to not restarting)
#RESTART_ON_UPGRADE=true
################################
# Elasticsearch service
################################
# SysV init.d
#
# The number of seconds to wait before checking if Elasticsearch started successfully as a daemon process
ES_STARTUP_SLEEP_TIME=5
################################
# System properties
################################
# Specifies the maximum file descriptor number that can be opened by this process
# When using Systemd, this setting is ignored and the LimitNOFILE defined in
# /usr/lib/systemd/system/elasticsearch.service takes precedence
MAX_OPEN_FILES=65536
# The maximum number of bytes of memory that may be locked into RAM
# Set to "unlimited" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml.
# When using systemd, LimitMEMLOCK must be set in a unit file such as
# /etc/systemd/system/elasticsearch.service.d/override.conf.
MAX_LOCKED_MEMORY=unlimited
# Maximum number of VMA (Virtual Memory Areas) a process can own
# When using Systemd, this setting is ignored and the 'vm.max_map_count'
# property is set at boot time in /usr/lib/sysctl.d/elasticsearch.conf
MAX_MAP_COUNT=262144
```
### jvm配置文件
```
root@test:/opt/elk6/elasticsearch/config# cat jvm.options
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms4g
-Xmx4g
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
## optimizations
# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch
## basic
# force the server VM
-server
# explicitly set the stack size
-Xss1m
# set to headless, just in case
-Djava.awt.headless=true
# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8
# use our provided JNA always versus the system one
-Djna.nosys=true
# turn off a JDK optimization that throws away stack traces for common
# exceptions because stack traces are important for debugging
-XX:-OmitStackTraceInFastThrow
# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps
# ensure the directory exists and has sufficient space
#-XX:HeapDumpPath=/heap/dump/path
## GC logging
#-XX:+PrintGCDetails
#-XX:+PrintGCTimeStamps
#-XX:+PrintGCDateStamps
#-XX:+PrintClassHistogram
#-XX:+PrintTenuringDistribution
#-XX:+PrintGCApplicationStoppedTime
# log GC status to a file with time stamps
# ensure the directory exists
#-Xloggc:${loggc}
# By default, the GC log file will not rotate.
# By uncommenting the lines below, the GC log file
# will be rotated every 128MB at most 32 times.
#-XX:+UseGCLogFileRotation
#-XX:NumberOfGCLogFiles=32
#-XX:GCLogFileSize=128M
```
### systemd啟動管理文件
```
root@test:~# cat /usr/lib/systemd/system/elasticsearch.service
[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target
[Service]
RuntimeDirectory=elasticsearch
Environment=ES_HOME=/opt/elk6/elasticsearch
Environment=ES_PATH_CONF=/opt/elk6/elasticsearch/config
Environment=PID_DIR=/opt/elk6/elasticsearch/pid
EnvironmentFile=-/opt/elk6/elasticsearch/default/elasticsearch
WorkingDirectory=/opt/elk6/elasticsearch
User=elasticsearch
Group=elasticsearch
ExecStart=/opt/elk6/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet
# StandardOutput is configured to redirect to journalctl since
# some error messages may be logged in standard output before
# elasticsearch logging system is initialized. Elasticsearch
# stores its logs in /var/log/elasticsearch and does not use
# journalctl by default. If you also want to enable journalctl
# logging, you can simply remove the "quiet" option from ExecStart.
StandardOutput=journal
StandardError=inherit
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of processes
LimitNPROC=4096
# Specifies the MEMLOCK
LimitMEMLOCK=infinity
# Specifies the maximum size of virtual memory
LimitAS=infinity
# Specifies the maximum file size
LimitFSIZE=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM
# Send the signal only to the JVM rather than its control group
KillMode=process
# Java process is never killed
SendSIGKILL=no
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
# Built for distribution-6.1.2 (distribution)
```
### init.d啟動腳本
```
root@test:~# cat /etc/init.d/elasticsearch
#!/bin/bash
#
# /etc/init.d/elasticsearch -- startup script for Elasticsearch
#
### BEGIN INIT INFO
# Provides: elasticsearch
# Required-Start: $network $remote_fs $named
# Required-Stop: $network $remote_fs $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts elasticsearch
# Description: Starts elasticsearch using start-stop-daemon
### END INIT INFO
JAVA_HOME=/application/jdk
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=elasticsearch
DESC="Elasticsearch Server"
DEFAULT=/opt/elk6/elasticsearch/default/${NAME}
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# The following variables can be overwritten in $DEFAULT
# Directory where the Elasticsearch binary distribution resides
ES_HOME=/opt/elk6/$NAME
# Additional Java OPTS
#ES_JAVA_OPTS=
# Maximum number of open files
MAX_OPEN_FILES=65536
# Maximum amount of locked memory
#MAX_LOCKED_MEMORY=
# Elasticsearch configuration directory
ES_PATH_CONF=$ES_HOME/config
# Maximum number of VMA (Virtual Memory Areas) a process can own
MAX_MAP_COUNT=262144
# Elasticsearch PID file directory
PID_DIR="$ES_HOME/pid"
# End of variables that can be overwritten in $DEFAULT
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
fi
# ES_USER and ES_GROUP settings were removed
if [ ! -z "$ES_USER" ] || [ ! -z "$ES_GROUP" ]; then
echo "ES_USER and ES_GROUP settings are no longer supported. To run as a custom user/group use the archive distribution of Elasticsearch."
exit 1
fi
# Define other required variables
PID_FILE="$PID_DIR/$NAME.pid"
DAEMON=$ES_HOME/bin/elasticsearch
DAEMON_OPTS="-d -p $PID_FILE"
export ES_JAVA_OPTS
export JAVA_HOME
export ES_PATH_CONF
if [ ! -x "$DAEMON" ]; then
echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON"
exit 1
fi
checkJava() {
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=`which java`
fi
if [ ! -x "$JAVA" ]; then
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
exit 1
fi
}
case "$1" in
start)
checkJava
log_daemon_msg "Starting $DESC"
pid=`pidofproc -p $PID_FILE elasticsearch`
if [ -n "$pid" ] ; then
log_begin_msg "Already running."
log_end_msg 0
exit 0
fi
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
mkdir -p "$PID_DIR" && chown elasticsearch:elasticsearch "$PID_DIR"
fi
if [ -n "$PID_FILE" ] && [ ! -e "$PID_FILE" ]; then
touch "$PID_FILE" && chown elasticsearch:elasticsearch "$PID_FILE"
fi
if [ -n "$MAX_OPEN_FILES" ]; then
ulimit -n $MAX_OPEN_FILES
fi
if [ -n "$MAX_LOCKED_MEMORY" ]; then
ulimit -l $MAX_LOCKED_MEMORY
fi
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
fi
# Start Daemon
start-stop-daemon -d $ES_HOME --start --user elasticsearch -c elasticsearch --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
return=$?
if [ $return -eq 0 ]; then
i=0
timeout=10
# Wait for the process to be properly started before exiting
until { kill -0 `cat "$PID_FILE"`; } >/dev/null 2>&1
do
sleep 1
i=$(($i + 1))
if [ $i -gt $timeout ]; then
log_end_msg 1
exit 1
fi
done
fi
log_end_msg $return
exit $return
;;
stop)
log_daemon_msg "Stopping $DESC"
if [ -f "$PID_FILE" ]; then
start-stop-daemon --stop --pidfile "$PID_FILE" \
--user elasticsearch \
--quiet \
--retry forever/TERM/20 > /dev/null
if [ $? -eq 1 ]; then
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
elif [ $? -eq 3 ]; then
PID="`cat $PID_FILE`"
log_failure_msg "Failed to stop $DESC (pid $PID)"
exit 1
fi
rm -f "$PID_FILE"
else
log_progress_msg "(not running)"
fi
log_end_msg 0
;;
status)
status_of_proc -p $PID_FILE elasticsearch elasticsearch && exit 0 || exit $?
;;
restart|force-reload)
if [ -f "$PID_FILE" ]; then
$0 stop
fi
$0 start
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0
```
- 運維筆記
- 零: 安裝部署篇
- Zabbix
- HAproxy
- Nginx
- Apache
- Tomcat
- Mysql
- Redis
- ELK
- MongoDB
- hadoop
- GIt
- JDK
- Docker
- OpenVPN
- iRedMail
- GitLab
- ESXi
- Jenkins
- NFS
- rsync
- Python
- Keepalived
- 軟件打包篇
- 私有倉庫篇
- kafka
- zookeeper
- Spark
- Linux基礎篇
- 1.1 Linux系統介紹
- 1.3 系統優化
- 1.4 問題總結
- Linux核心命令
- 聲明
- 1-文件和目錄操作命令
- 1.3 tree: 以樹形結構顯示目錄下的內容
- 2-文件過濾及內容編輯處理命令
- find:查找目錄下的文件
- 3-文本處理三劍客
- 4-Linux信息顯示與搜索文件命令
- du:統計磁盤空間使用情況
- 5-文件備份與壓縮命令
- rsync:文件同步工具
- 6-Linux用戶管理及用戶信息查詢命令
- 7-Linux磁盤與文件系統管理命令
- 8-Linux進程管理命令
- 9-Linux網絡管理命令
- 10-Linux系統管理命令
- 11-Linux系統常用內置命令
- 服務相關
- Nginx
- 安裝部署
- 文件路徑說明
- 服務啟動管理
- 配置文件說明
- json格式日志的配置文件
- https代理
- nginx負載均衡代理websocket
- 服務優化
- 維護腳本
- 問題總結
- rewrite帶?跳轉
- nginx查看默認安裝的模塊
- HAproxy
- 2.2.1 安裝部署
- 2.2.2 文件路徑說明
- 2.2.3 服務啟動管理
- 2.2.4 配置文件說明
- ha代理websocket
- 2.2.5 集群高可用
- 2.2.6 服務優化
- 2.2.7 維護腳本
- 2.2.8 問題總結
- PHP
- 2.3.1 安裝部署
- keepalived
- 配置文件注釋
- 配置多組VIP
- Java
- 安裝部署java
- ansible部署java
- supervisor
- supervisor安裝部署測試
- iptables
- CentOS7安裝配置iptables
- pm2相關
- kafka相關
- kafka和zookeeper集群安裝部署
- nodejs
- 安裝部署nodejs
- sersync
- sersync備份圖片服務
- gitlab相關
- gitlab安裝部署
- gitlab強制修改密碼
- gitlab不同的連接方式
- jenkins相關
- 安裝部署jenkins
- python相關
- python虛擬環境
- debian安裝pyhton3.6
- Turnserver服務器搭建
- NFS相關
- 固定NFS和rsync端口
- go相關
- 安裝go
- maven相關
- debian私有倉庫搭建
- 翻墻
- linux下的百度云盤
- 私有網盤owncloud部署
- crontab定時任務
- 數據庫相關
- mongodb
- 重用操作命令
- 副本集配置文件
- 慢查詢設置
- 數據備份恢復以及數據導入導出
- 從庫允許只讀設置
- redis
- redis單節點安裝部署
- 配置文件注釋
- redis分析工具rdbtools使用
- redis數據導入導出集群工具
- redis內存信息解釋
- redis警告優化
- PHP會話session保存到redis集群
- redis啟動關閉腳本
- elk相關
- elastersearch常用命令
- elasticsearch6所需配置文件
- elasticsearch6的head插件安裝
- elk6安裝腳本
- filebeat收集php日志多行轉換
- filebeat自定義index
- elk-dockercompes配置
- docker部署elk收集runtime日志
- elasticsearch6添加新節點報錯
- elasticsearch查看索引
- docker部署es+filebeat+kibana
- mysql相關
- mysql日志
- mysql密碼過期
- mysql用戶授權訪問庫
- mysql安裝部署
- MariaDB安裝部署
- 大數據相關
- hadoop相關
- Ambari2.6離線安裝hadoop
- Ambari安裝出現的問題
- 檢測hadoop當前運行了哪些服務端口腳本
- 監控相關
- CentOS7安裝Zabbix3.4
- docker安裝zabbix
- 運維腳本
- 根據配置文件檢查服務端口運行狀態
- nginx日志分析
- ngixn日志合并腳本
- nginx查詢關鍵鏈接響應時間
- 圖片同步腳本
- 批量獲取iptables設置的端口然后驗證本機端口是否存活
- 按日期統計不同接口的響應時間
- php進程假死狀態定時清理
- 運維自動化
- deb打包命令
- ansible相關
- ansible部署
- ansible配置推送
- 編程語言
- 1-SHELL
- 2-Python
- 3-GO
- 有趣的工具
- vim
- 聲明
- 第1章: Vim解決問題的方式
- 技巧1-認識 . 命令
- 技巧2-不要自我重復
- 技巧3-以進為退
- 技巧4-執行,重復,回退
- 技巧5-查找并手動替換
- 技巧6-認識 . 范式
- 第2章: 普通模式
- 第3章: 插入模式
- 第4章: 可視模式
- 第5章: 命令行模式
- 第6章: 管理多個文件
- 第7章: 打開及保存文件
- 第8章: 用動作命令在文檔中移動
- 第9章: 在文件間跳轉
- 第10章: 復制與粘貼
- 第11章: 宏
- 第12章: 按模式匹配及按原義匹配
- 第13章: 查找
- 第14章: 替換
- 第15章: global命令
- 第16章: 通過ctags建立索引并用其瀏覽源代碼
- 第17章: 編譯代碼并通過Quickfix列表瀏覽錯誤信息
- 第18章: 通過grep,vimgrep以及其他工具對整個工程進行查找
- 第19章: 自動補全
- 第20章: 利用Vim的拼寫檢查器查找并更正拼寫錯誤
- 第21章: 接下來干什么
- 附錄A 根據個人喜好定制Vim
- 終端命令記錄回放工具
- screen使用
- iftop查看網絡流量
- dna螺旋
- shell下的俄羅斯方塊
- 正經英語
- 有意思
- 問題記錄
- python相關
- pip安裝缺少openssl和libssl
- shell相關
- debian下執行數組變量報錯
- 服務相關問題
- ububtu安裝apache2報錯
- php升級mongo拓展插件
- elk節點分片失敗
- 操作系統相關問題
- 運維記錄
- 數據庫相關
- mongo3.4安裝以及優化參數腳本
- mongodb版本升級及優化
- redis動態取消rdb保存配置
- 代理負載均衡相關
- haproxy匹配ua規則分離搜索引擎流量
- haproxy不記錄某個域名或多個域名的日志
- 其他相關
- ImageMagick升級
- NFS強制卸載掛載
- 命令相關
- curl獲取指定域名ip的狀態碼
- awk相關記錄
- rsync傳輸限速指定ssh端口
- 操作系統相關
- centos使用阿里源
- ubuntu更換國內源
- 查看操作系統版本
- 內核優化
- Centos7修改語言為英文
- debian安裝xfs格式化工具
- 查看磁盤信息
- debian的啟動管理工具
- debian安裝vmtools
- debian重啟網卡不生效的解決
- 容器虛擬化
- Docker相關
- dokcer安裝
- docker常用命令
- docker簡單腳本
- Dockerfile相關
- 帶ssh的debian鏡像
- deocker創建簡單鏡像
- 官方文檔
- docker-compose安裝
- 報錯
- docker鏡像加速
- k8s相關
- k8s常用命令
- k8s名詞解釋
- k8s相關的 yaml文件
- VM相關
- 使用VMwareWorkstation批量操作linux虛擬機
- 在windows下使用shell批量操作Vmwarworkstation
- windows下批量操作虛擬機
- ESXI相關
- vsphere網絡相關
- 小愛好
- 不方便展示