关于centos:Centos-7-安装系列10ElasticSearch-862

2次阅读

共计 3281 个字符,预计需要花费 9 分钟才能阅读完成。

@TOC

一、零碎环境

操作系统:Centos 7
已配置环境:空

二、解压装置

2.1 解压压缩包

上传压缩包到 /opt 目录下

cd /opt

解压并创立数据目录

tar -zxvf elasticsearch-8.6.2-linux-x86_64.tar.gz
mv elasticsearch-8.6.2 elasticsearch
mkdir /opt/elasticsearch/data

2.2 批改配置文件

cd /opt/elasticsearch/config/
cp elasticsearch.yml elasticsearch.yml.cp
vi elasticsearch.yml

在文件开端增加以下配置:

cluster.name: test-elasticsearch
node.name: es-node0
path.data: /opt/elasticsearch/data
path.logs: /opt/elasticsearch/logs
network.host: 0.0.0.0
cluster.initial_master_nodes: ["es-node0"]

2.3 增加操作用户

es 不容许应用 root 用户操作,须要独自增加用户,并给 es 文件夹赋权

useradd es
chown -R es:es /opt/elasticsearch/

2.4 启动

后盾启动 ES

su es
cd /opt/elasticsearch/bin/
./elasticsearch -d

此时没法失常启动 ES,报错了。

对于【max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]】
批改配置

exit
vi /etc/security/limits.conf

在文件开端增加以下内容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

对于【max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]】

vi /etc/sysctl.conf

增加以下内容:

 vm.max_map_count=262145

刷新配置后重启 ES

sysctl -p
su es
cd /opt/elasticsearch/bin/
./elasticsearch -d

2.5 凋谢端口

因为防火墙开启的缘故,须要凋谢 ES 的端口

exit
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload

然而,此时拜访 es 还是会失败。

再次查看配置文件,会发现配置文件中开端多了些平安相干的配置

vi elasticsearch.yml

批改以下内容:

xpack.security.enabled: false

敞开 es,重新启动

ps -ef|grep elastic
kill 2896

su es
cd /opt/elasticsearch/bin/
./elasticsearch -d

此时拜访 ES,失常。

拜访地址:http://192.168.88.159:9200/
健康检查:
http://192.168.88.159:9200/_cluster/health?pretty=true
集群详细信息:
http://192.168.88.159:9200/_cluster/state?pretty

2.6 开机自启动配置

查看以后的开机启动服务

chkconfig --list

在 /etc/init.d 目录下创立启动文件

exit;
vi /etc/init.d/elasticsearch

增加内容如下

#!/bin/bash
#chkconfig: 2345 63 37
#description: elasticsearch
#processname: elasticsearch-8.6.2
export ES_HOME=/opt/elasticsearch
case $1 in
        start)
                su es<<!
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
                ;;
        stop)
                ## 也能够依据 ps 命令获取 elasticsearch 过程的 pid
                ##es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
                ##kill -9 $es_pid

                pid=`cat $ES_HOME/pid`
                kill -9 $pid
                echo "elasticsearch is stopped"
                ;;
        restart)
                pid=`cat $ES_HOME/pid`
                kill -9 $pid
                echo "elasticsearch is stopped"
                sleep 1
                su es<<!
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
        ;;
    *)
        echo "start|stop|restart"
        ;;
esac
exit 0

留神⚠️:
1、脚本中主动实现了用户的切换,在 es 用户下启动 ES
2、采纳 ./bin/elasticsearch -d -p pid 命令启动,会在目录下生成 pid 文件,服务 stop 时能够间接读取 pid 文件获取 pid。
阐明:
每个被 chkconfig 治理的服务须要在对应的 init.d 下的脚本加上两行或者更多行的正文。
第一行通知 chkconfig 缺省启动的运行级以及启动和进行的优先级。如果某服务缺省不在任何运行级启动,那么应用 – 代替运行级。
第二行对服务进行形容,能够用 \ 跨行正文。

chkconfig: 2345 63 37 指的是指定 kibana 服务在 2、3、4、5 的 level 等级下脚本执行程序是 63,1、6 的 level 等级下脚本执行程序是 37。

减少脚本的可执行权限

chmod +x /etc/init.d/elasticsearch

把 ES 服务增加到 chkconfig 列表

chkconfig --add elasticsearch

设置 ES 服务自启动

chkconfig elasticsearch on

查看 ES 服务自启动状态

chkconfig --list elasticsearch

如果 2~5 都是 on,就表明会主动启动了

服务启动
service elasticsearch start
服务进行
service elasticsearch stop
服务重启
service elasticsearch restart

## 2.7 设置用户名明码认证

留神:因为 ES 曾经启动,且不是应用下面脚本的命令启动,故而想要应用下面三条命令,需得先敞开本来的 ES 程序。
ps -ef|grep elastic
kill 3142

启动 ES

service elasticsearch start

批改配置

vi /opt/elasticsearch/config/elasticsearch.yml

批改以下内容

xpack.security.enabled: true
http.cors.enabled: true
http.cors.allow-origin: “*”
http.cors.allow-headers: Authorization

重置 ES 中用户 elastic 的明码:

service elasticsearch restart
cd /opt/elasticsearch/bin/
./elasticsearch-reset-password -u elastic
y

此时拜访 http://192.168.88.159:9200/ 会没有响应,须要将 http 改为 https,或者批改配置禁用 ssl:

vi elasticsearch.yml

三、总结

本文内容:
在空白的 Centos 7 零碎中,装置部署 ElasticSearch 8.6,同时设置开机自启和明码安全策略。

我是陈冰安,在常识宇宙中摸爬滚打,分享个人所得,也期待气味相投。

正文完
 0