基础配置
1.下载elasticsearch安装包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.5.zip
sha1sum elasticsearch-5.6.5.zip
unzip elasticsearch-5.6.5.zip
2.配置es环境变量
sudo vi /etc/profile
ES_HOME=/home/tq/elasticsearch-5.6.5
PATH=$ES_HOME:$PATH
export ES_HOME
3.运行es
./bin/elasticsearch -d -p pid
运行日志生成在$ES_HOME/logs/目录下
4.检查是否安装成功
curl -XGET 'localhost:9200/?pretty'
5.杀掉es进程
kill `cat pid`
6.替换es默认配置文件
./bin/elasticsearch -Epath.conf=/path/to/my/config/
7.通过配置环境变量方式,在配置文件中注入属性值
node.name: ${HOSTNAME}
network.host: ${ES_NETWORK_HOST}
8.可通过提示输入,修改配置属性值
elasticsearch.yml中:
node:
name: ${prompt.text}
启动时提示:
Enter value for [node.name]:
输入: node1
则该es进程的node.name=node1
9.制订日志删除策略(暂不使用)
vi log4j2.properties
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.rolling.strategy.action.condition.type = IfLastModified
appender.rolling.strategy.action.condition.age = 7D
appender.rolling.strategy.action.PathConditions.type = IfFileName
appender.rolling.strategy.action.PathConditions.glob = ${sys:es.logs.cluster_name}-*
Elasticsearch 配置
1.配置日志&索引存储地址
为了避免升级造成了数据丢失,需要将文件存储在其他目录,而不是在默认目录下
path:
logs: /var/log/elasticsearch //日志存储路径
data: /var/data/elasticsearch //es的索引数
2.集群名称,用于节点加入集群(不同的集群名称千万不能一样)
cluster.name: logging-prod
3.节点名称
node.name: prod-data-2 //可以使用hostname作为节点名称。如:node.name: ${HOSTNAME}
4.关闭交换区,避免内存交换。
bootstrap.memory_lock: true
关于内存交换:Linux把它的物理RAM分成多个内存块,称之为分页。内存交换(swapping)是这样一个过程,它把内存分页复制到预先设定的叫做交换区的硬盘空间上,以此释放内存分页。物理内存和交换区加起来的大小就是虚拟内存的可用额度。 内存交换有个缺点,跟内存比起来硬盘非常慢。内存的读写速度以纳秒来计算,而硬盘是以毫秒来计算,所以访问硬盘比访问内存要慢几万倍。交换次数越多,进程就越慢,所以应该不惜一切代价避免内存交换的发生。
5.设置网络
network.host: 192.168.4.12(本机ip)
6.集群中的节点列表(可以使用hostname,hostname需要和IP绑定)
discovery.zen.ping.unicast.hosts: ["host1:port", "host2:port"]
7.通过配置这个参数来防止master集群脑裂现象 (集群总节点数量/2)+1(暂不使用)
discovery.zen.minimum_master_nodes: 3
8.一个集群中的N个节点启动后,才允许进行数据恢复处理(暂不使用)
gateway.recover_after_nodes: 3
9.删除库时是否显式指定索引库名称
action.destructive_requires_name: true
设置是否可以通过正则或者_all删除或者关闭索引库,默认true表示必须需要显式指定索引库名称。生产环境建议设置为true,删除索引库的时候必须显式指定,否则可能会误删索引库中的索引库
10.JVM内存大小设置(内存大小设置不要超过物理机的50%,确保剩下的50%的够物理机使用)
vi jvm.options
-Xms2g //默认最小堆内存
-Xmx2g //默认最大堆内存
11.ulimit 限制打开文件数,若不设置可能会写入失败
通过ulimit -n 查看目前最大打开个数
sudo vi /etc/security/limits.conf
输入:
tq - nofile 65536 --tq是启动es的用户
查看命令:
ulimit -n
12.虚拟内存,增加mmap
root 用户 vi /etc/sysctl.conf
vm.max_map_count=262144
通过sysctl vm.max_map_count检查
13.线程数设置
ulimit -u 2048 (设置之前,通过ulimit -u查看,大于2048则无需配置)或 设置nproc为2048 到 /etc/security/limits.conf
14.关闭分片自动转移
PUT http://ip:9200/_cluster/settings
{
"transient":{
"cluster.routing.allocation.enable":"none"
}
}
15.设置节点角色
node.master: true
node.data: true
16.设置集群通信参数
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
FAQ
1.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
答:需要增加虚拟内存,增加mmap,见(12)
2.ERROR: bootstrap checks failed system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
这是在因为Centos6不支持SecComp,而ES5.2.0默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。
解决:
在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
3.删除es中.watcher-history文件
curl -XDELETE '192.168.6.170:9200/.watcher-history-6-2017.11.*?pretty'