使用yum方式安装
1.在/etc/yum.repos.d/下创建文件elasticsearch.repo,文件内容:
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
2.执行 yum install --enablerepo=elasticsearch elasticsearch 命令安装
3.执行 systemctl start elasticsearch.service 启动elasticsearch
使用wget下载
1.安装wget
yum install -y wget
2.下载elasticsearch压缩包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.3-linux-x86_64.tar.gz
3.解压缩
tar -zxvf elasticsearch-7.9.3-linux-x86_64.tar.gz
4.配置外网访问
修改elasticsearch.yml配置
vim config/elasticsearch.yml
显示文件行数,命令行模式下
:set number
解除注释内容,第55行,59行
#修改网卡 127.0.0.1表示只允许当前系统访问,如果想要对外访问则可以改为 0.0.0.0
network.host: 0.0.0.0
#访问端口,默认是9200
http.port: 9200
5.启动elasticsearch
./bin/elasticsearch
可能遇到的问题
1.can not run elasticsearch as root
elasticsearch不能用root启动,需切换到普通用户启动
需要更改普通用户的权限
chown -R lusi elasticsearch-7.9.3
2.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
修改文件
vi /etc/security/limits.conf
追加内容
* soft nofile 65536
* hard nofile 65536
3.max number of threads [3766] for user [ziv] is too low, increase to at least [4096]
修改文件
vi /etc/security/limits.conf
追加内容
* hard nproc 4096
* soft nproc 4096
4.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改文件
vim /etc/sysctl.conf
追加内容
vm.max_map_count = 262144
重新加载/etc/sysctl.conf配置
sysctl -p
5.the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
修改elasticsearch的配置文件
vi config/elasticsearch.yml
追加内容
discovery.seed_hosts: ["127.0.0.1", "[::1]"]