1. 验证jdk
首先需要验证系统是否已经安装jdk , 要求使用jdk1.8 以上版本
[root@app110 ~]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
2. 安装ES(elasticsearch)
2.1 新建普通用户
由于Elasticsearch可以接收用户输入的脚本并且执行,为了系统安全考虑,不允许root账号启动,所以建议给Elasticsearch单独创建一个用户来运行Elasticsearch
[root@app110 ~]# groupadd es
[root@app110 ~]# useradd es -g es
设置目录属主和属组
[root@app110 ~]# mkdir -p /opt/ES/
[root@app110 ~]# chown -R es:es /opt/ES/
[root@app110 ~]# su - es
[es@app110 ~]$
2.2 安装
使用winSCP将elasticsearch-6.8.0.tar.gz
上传到/opt/ES/目录下
[root@app110 ES]# ll
total 145092
-rw-r--r--. 1 root root 148571591 Jun 13 07:23 elasticsearch-6.8.0.tar.gz
[root@app110 ES]#
解压软件
[root@app110 ES]# tar xf elasticsearch-6.8.0.tar.gz
[root@app110 ES]# cd elasticsearch-6.8.0
修改ES配置文件
// 现将配置文件 备份一下
[root@app110 ES]# cp -a config/elasticsearch.yml{,_$(date +%F)}
//修改配置参数
[root@app110 ES]# vi 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: my-application # 集群名称
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: app01 # 主机名
#
# 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: /path/to/data
path.data: /opt/ES/elasticsearch-6.8.0/data # 数据路径
# Path to log files:
#
path.logs: /opt/ES/elasticsearch-6.8.0/logs # 日志路径
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.memory_lock: false # 修改内存配置
bootstrap.system_call_filter: false
#
# 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.0.1
network.host: 10.6.12.80 #本机IP
#
# Set a custom port for HTTP:
#
http.port: 9200 #配置端口号
transport.tcp.port: 9300 #配置端口号
# 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: ["host1", "host2"]
discovery.zen.ping.unicast.hosts: ["10.6.12.80", "10.6.12.81", "10.6.12.110"] # 配置集群
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
discovery.zen.minimum_master_nodes: 2 # 最小master配置数, 如果2台主机配置为1, 如果3台主机配置为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: "*"
创建ES数据文件和日志文件
mkdir -p /opt/ES/elasticsearch-6.8.0/data
mkdir -p /opt/ES/elasticsearch-6.8.0/logs
切换为root用户修改配置
//在文件的末尾添加下面的参数值
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
//安装log4j
yum install -y log4j*
chown es:es -R /opt/ES/elasticsearch-6.8.0
vi /etc/security/limits.d/90-nproc.conf
mit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 4096
root soft nproc unlimited
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
chown es /opt/ES/elasticsearch-6.8.0 -R
2.3 启动
su es
.[root@app110 elasticsearch-6.8.0]# ./bin/elasticsearch -d
2.4 验证
[root@ayzxweb ~] jps
61562 Jps
61503 Elasticsearch
启动一些错误信息
错误1
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:94)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:160)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
解决方案:
这是出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑,
建议创建一个单独的用户用来运行ElasticSearch
创建elsearch用户组及elsearch用户
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
错误2
Exception in thread "main" 2017-11-12 12:17:55,776 main ERROR No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property ‘log4j2.debug‘ to show Log4j2 internal initialization logging.
2017-11-12 12:17:56,319 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
解决方案:
[root@node2 ~]# yum install -y log4j*
[root@node2 ~]# chown dashuju:dashuju -R /usr/local/src/elasticsearch-5.6.3
错误3
max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解决方案:
切换到root用户,进入limits.d目录下修改配置文件
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048
错误4
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决方案:
切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
错误5
ERROR: [2] bootstrap checks failed ##还有错误,这个是要改文件数,这个因为太多我就不放图了。
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:
[root@node1 src]# cat /etc/sysctl.conf
vm.max_map_count=655360
[root@node2 src]# cat /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
[root@node2 ~]# sysctl -p
vm.max_map_count = 655360
错误6
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
解决方案:
vi /usr/local/elasticsearch-5.5.1/config/elasticsearch.yml
配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
错误7 failed to obtain node locks
解决方案:
ps aux | grep elastic
kill -9 进程号
./elasticsearch
错误8 java.nio.file.AccessDeniedException
java.nio.file.AccessDeniedException: /data/wwwroot/elasticsearch-6.2.4/config/jvm.options
解决方案:
原因:当前用户没有执行权限
解决方法: chown linux用户名 elasticsearch安装目录 -R
例如:chown ealsticsearch /data/wwwroot/elasticsearch-6.2.4 -R
PS:其他Java软件报.AccessDeniedException错误也可以同样方式解决,给 执行用户相应的目录权限即可