CentOS7 部署单机版 elasticsearch

一、环境准备

1、准备一台系统为CentOS7的服务器
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
2、创建新用户,用于elasticsearch服务
# elastic不允许使用root账号启动服务
[root@localhost ~]# useradd elastic
[root@localhost ~]# passwd elastic 
Changing password for user elastic.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
3、设置ulimit
[root@localhost ~]# vi /etc/security/limits.conf
# 在文本最后添加如下几行
## 可以打开的最大文件数(软限制)
elastic soft nofile 65536
## 可以打开的最大文件数(硬限制)
elastic hard nofile 65536
## 可以创建的最大进程数(软限制)
elastic soft nproc 65535
## 可以创建的最大进程数(硬限制)
elastic hard nproc 65535

[root@localhost ~]# vi /etc/sysctl.conf
# 在文本最后添加下面行
## 设置单个进程可以拥有的最大内存映射区域数量
vm.max_map_count=262144

# 重启服务器,使其生效
4、查看ulimit值是否生效
[root@localhost ~]# su - elastic 
[elastic@localhost ~]$ ulimit -S -n
65536
[elastic@localhost ~]$ ulimit -H -n
65536
[elastic@localhost ~]$ cat /proc/sys/vm/max_map_count 
262144

二、安装elastic search

1、下载安装包
[root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.4-linux-x86_64.tar.gz
2、解压缩
# 解压缩
[root@localhost ~]# tar -zxvf elasticsearch-8.13.4-linux-x86_64.tar.gz
# 移动目录到/opt/下
[root@localhost ~]# mv elasticsearch-8.13.4 /opt/es/
3、设置目录权限
[root@localhost ~]# cd /opt
[root@localhost opt]# chown -R elastic: es
4、修改配置文件
[root@localhost es]# vi /opt/es/config/elasticsearch.yml
# 修改如下内容
## elastic节点名字
node.name: node-1
## 数据存放目录
path.data: /opt/es/data
## 日志存放目录
path.logs: /opt/es/logs
## 对所有IP开放,可以跟据需求修改
network.host: 0.0.0.0
5、设置启动脚本
vi /etc/systemd/system/elasticsearch.service

[Unit]
Description=ElasticSearch
After=network.target

[Service]
Type=simple
User=elastic
Group=elastic
ExecStart=/opt/es/bin/elasticsearch -d -p /opt/es/elasticsearch.pid
ExecStop=/opt/es/bin/elasticsearch-sysctl stop
PIDFile=/opt/es/elasticsearch.pid
# 修改线程数限制
LimitNPROC=65535
# 修改文件描述符限制
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
6、启动服务
# 重新加载服务
[root@localhost es]# systemctl daemon-reload 
# 启动服务
[root@localhost es]# systemctl start elasticsearch.service
# 设置开机自启动
[root@localhost es]# systemctl enable elasticsearch.service
7、查看服务是否启动成功
# 查看9200,9300端口是否启动
[root@localhost es]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name           
tcp6       0      0 :::9200                 :::*                    LISTEN      1605/java           
tcp6       0      0 :::9300                 :::*                    LISTEN      1605/java 
8、设置密码
[root@localhost es]# /opt/es/bin/elasticsearch-setup-passwords interactive
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This       command will be removed in a future release.
******************************************************************************

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana_system]: 
Reenter password for [kibana_system]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
9、修改密码

如果忘记密码,可以通过以下方式修改密码

[root@localhost es]# elasticsearch-reset-password -u elastic -i

三、测试

1、浏览器访问测试

浏览器中输入URL:https://IP:9200

输入账号密码

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是在 CentOS 上单机部署 Elasticsearch 和 X-Pack 的步骤: 1. 首先下载 Elasticsearch 和 X-Pack 的安装包。可以到官网下载最新版本,也可以使用 yum 安装。 2. 安装 Java 环境。Elasticsearch 需要 Java 环境的支持。可以使用以下命令安装 OpenJDK: ``` sudo yum install java-1.8.0-openjdk ``` 3. 解压 Elasticsearch 和 X-Pack 的安装包,并将其移动到 /usr/share 目录下: ``` sudo tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz sudo mv elasticsearch-7.6.2 /usr/share/elasticsearch sudo tar -zxvf x-pack-7.6.2-linux-x86_64.tar.gz sudo mv x-pack-7.6.2 /usr/share/x-pack ``` 4. 创建一个新用户来运行 Elasticsearch。可以使用以下命令创建一个名为 elasticsearch 的用户: ``` sudo useradd elasticsearch ``` 5. 给 Elasticsearch 和 X-Pack 相应的目录设置权限: ``` sudo chown -R elasticsearch:elasticsearch /usr/share/elasticsearch sudo chown -R elasticsearch:elasticsearch /usr/share/x-pack ``` 6. 修改 Elasticsearch 的配置文件。编辑 /usr/share/elasticsearch/config/elasticsearch.yml 文件,修改以下配置项: ``` cluster.name: my_cluster node.name: node1 network.host: 0.0.0.0 http.port: 9200 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/share/x-pack/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/share/x-pack/elastic-certificates.p12 xpack.security.http.ssl.enabled: true xpack.security.http.ssl.keystore.path: /usr/share/x-pack/http.p12 xpack.security.http.ssl.truststore.path: /usr/share/x-pack/http.p12 ``` 注意:xpack.security.enabled 设置为 true 是启用 X-Pack 的关键。xpack.security.transport.ssl.enabled 和 xpack.security.http.ssl.enabled 分别启用 Elasticsearch 和 HTTP 安全性。 7. 启动 Elasticsearch。使用以下命令启动 Elasticsearch: ``` sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch ``` 8. 验证 Elasticsearch 是否正常运行。在浏览器中访问 http://your_ip_address:9200,如果能够看到 Elasticsearch 的版本信息,则表示 Elasticsearch 已经成功运行。 至此,Elasticsearch 和 X-Pack 的单机部署就完成了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值