解压安装包到/opt/elasticsearch 目录下面
[root@s1-prod-it-web01 opt]# tree -L 1 elasticsearch/
elasticsearch/ ├── bin ├── config ├── lib ├── LICENSE.txt ├── modules ├── NOTICE.txt ├── plugins └── README.textile 由于 elasticsearch默认不能使用root用户启动,先创建用户useradd elasticsearch
授权主程序目录
chown -R elasticsearch:elasticsearch /opt/elasticsearch/
创建数据存储目录 mkdir -p /var/lib/elasticsearch
授权存储目录 chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
创建日志保存目录 mkdir -p /var/log/elasticsearch
授权日志保存目 chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
创建进程PID文件目录 mkdir -p /var/run/elasticsearch
授权进程PID文件目录 chown -R elasticsearch:elasticsearch /var/run/elasticsearch
加入的Systemd Service ,配置文件如下,为了方便应用,已经参考官方教程编辑好了
vim /usr/lib/systemd/system/elasticsearch.service
#################################################################
[Unit]
Description=Elasticsearch Documentation=http://www.elastic.co Wants=network-online.target After=network-online.target[Service]
Environment=ES_HOME=/opt/elasticsearch Environment=CONF_DIR=/opt/elasticsearch/config Environment=DATA_DIR=/var/lib/elasticsearch Environment=LOG_DIR=/var/log/elasticsearch Environment=PID_DIR=/var/run/elasticsearch #EnvironmentFile=-/etc/sysconfig/elasticsearchWorkingDirectory=/opt/elasticsearch
User=elasticsearch
Group=elasticsearchExecStartPre=/opt/elasticsearch/bin/elasticsearch-systemd-pre-exec
ExecStart=/opt/elasticsearch/bin/elasticsearch \
-p ${PID_DIR}/elasticsearch.pid \ --quiet \ -Edefault.path.logs=${LOG_DIR} \ -Edefault.path.data=${DATA_DIR} \ -Edefault.path.conf=${CONF_DIR}# 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 bytes of memory that may be locked into RAM
# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option # in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch #LimitMEMLOCK=infinity# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM# 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-5.2.2 (distribution)
##################################################################
重新加载Service 并加入开机启动,执行启动:
systemctl daemon-reload
systemctl enable elasticsearch.service && systemctl start elasticsearch.service
[root@s1-prod-it-web01 config]# curl -l http://localhost:9100
<html> <head><title>Node Exporter</title></head> <body> <h1>Node Exporter</h1> <p><a href="/metrics">Metrics</a></p> </body> </html>[root@s1-prod-it-web01 config]# curl -l http://localhost:9200 { "name" : "ALkP9Fh", "cluster_name" : "elasticsearch", "cluster_uuid" : "M0mxBeOVS4u0jttbWoqLcg", "version" : { "number" : "5.2.2", "build_hash" : "f9d9b74", "build_date" : "2017-02-24T17:26:45.835Z", "build_snapshot" : false, "lucene_version" : "6.4.1" }, "tagline" : "You Know, for Search" }