栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

1. Elasticsearch 搭建

1. Elasticsearch 搭建

 祝您身体健康,前程似锦,小弟期待文章对您有帮助,也期待您的打赏:

目录

一、安装JDK(root用户权限下)

二、安装Elasticsearch(root用户权限下)

三、配置

四、 启动Elasticsearch

五、访问elasticsearch的状态

六. 安装elasticsearch-head插件

七. 启动


一、安装JDK(root用户权限下)

yum install -y java

java -version

二、安装Elasticsearch(root用户权限下)

1.下载并安装GPG key

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

2.添加yum仓库

vim /etc/yum.repos.d/es.repo

[elasticsearch-6.x] name=Elasticsearch repository for 6.x packages baseurl=https://artifacts.elastic.co/packages/6.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md

3.安装elasticsearch

yum install -y elasticsearch

三、配置

1. (root用户下)配置外网访问IP

vim /etc/elasticsearch/elasticsearch.yml

2. (root用户下)修改limits.conf

vi /etc/security/limits.conf #添加如下内容: * soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 4096

3 . (root用户下)修改/etc/sysctl.conf 

#添加下面配置: vm.max_map_count=655360

4.(root用户下) 执行命令

sysctl -p

四、 启动Elasticsearch

1、(root用户下)创建用户:elasticsearch

adduser elasticsearch(自动安装的时候可能创建有了)

2、(root用户下)创建用户密码,需要输入两次

passwd elasticsearch (测试就1eGhXZ0n78WoqSw6) //修改强一点的密码,免得遭受攻击

3、(root用户下)将对应的文件夹权限赋给该用户

find / -name elasticsearch

发现安装在: /usr/share/elasticsearch/

chown -R elasticsearch /usr/share/elasticsearch/

4. (root用户下)防止切换到elasticsearch,报"This account is currently not available"

usermod -s /bin/bash elasticsearch

5. (root用户下)切换到elasticsearch用户下

su elasticsearch

6. (elasticsearch用户下)启动elasticsearch

/usr/share/elasticsearch/bin/elasticsearch

五、访问elasticsearch的状态

1. 本地访问

[root@localhost ~]# curl http://127.0.0.1:9200/_cluster/health?pretty=true

{

"cluster_name" : "elasticsearch",

"status" : "green",

"timed_out" : false,

"number_of_nodes" : 1,

"number_of_data_nodes" : 1,

"active_primary_shards" : 0,

"active_shards" : 0,

"relocating_shards" : 0,

"initializing_shards" : 0,

"unassigned_shards" : 0,

"delayed_unassigned_shards" : 0,

"number_of_pending_tasks" : 0,

"number_of_in_flight_fetch" : 0,

"task_max_waiting_in_queue_millis" : 0,

"active_shards_percent_as_number" : 100.0

}

2. 对外IP访问

[root@localhost ~]# curl http://192.168.161.131:9200/_cluster/health?pretty=true

{

"cluster_name" : "elasticsearch",

"status" : "green",

"timed_out" : false,

"number_of_nodes" : 1,

"number_of_data_nodes" : 1,

"active_primary_shards" : 0,

"active_shards" : 0,

"relocating_shards" : 0,

"initializing_shards" : 0,

"unassigned_shards" : 0,

"delayed_unassigned_shards" : 0,

"number_of_pending_tasks" : 0,

"number_of_in_flight_fetch" : 0,

"task_max_waiting_in_queue_millis" : 0,

"active_shards_percent_as_number" : 100.0

}

3. 查看es里面有什么内容

[root@localhost ~]# curl -i -XGET 'http://192.168.161.131:9200/_count?'

HTTP/1.1 200 OK

content-type: application/json; charset=UTF-8

content-length: 71

{"count":0,"_shards":{"total":0,"successful":0,"skipped":0,"failed":0}}

解释: 返回头部200,执行成功0个,返回0个

// 健康检查

curl http://192.168.161.131:9200/_cluster/health?pretty

// 集群详细信息 curl http://192.168.161.131:9200/_cluster/state?pretty

六. 安装elasticsearch-head插件

1. 安装npm命令:

yum install gcc gcc-c++

wget https://npm.taobao.org/mirrors/node/v10.14.1/node-v10.14.1-linux-x64.tar.gz

tar -xvf node-v10.14.1-linux-x64.tar.gz

mv node-v10.14.1-linux-x64 /usr/local/node

vi /etc/profile

在文件最后添加以下配置:

export NODE_HOME=/usr/local/node export PATH=$NODE_HOME/bin:$PATH

source /etc/profile

node -v

npm -v

npm install -g cnpm --registry=https://registry.npm.taobao.org

npm install -g grunt-cli --registry=https://registry.npm.taobao.org

grunt -version

2. 下载安装elasticsearch-head

git clone https://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

cnpm install (好像会出现红色的错误,先不管吧)

[root@localhost elasticsearch-head]# grunt -version

grunt-cli v1.3.2

grunt v1.0.1

(上面这样子显示两个就Ok啦)

3. 配置

3.1 vim Gruntfile.js (注意逗号)

3.2 vim _site/app.js

3.3 vim /etc/elasticsearch/elasticsearch.yml

增加:

http.cors.enabled: true

http.cors.allow-origin: "*"

七. 启动

systemctl restart elasticsearch

systemctl status elasticsearch

cd /home/study/ELK/elasticsearch-head && grunt server &

(运行后,按enter, 会退回命令行,服务已经在后台运行了)

// 如果想要关闭grunt服务

ps -ef | grep grunt

kill -9 pid

5. 访问

 (期待您上面二维码打赏,也祝您前程似锦,步步高升)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/342831.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号