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. 访问

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骑着嘉陵车的男孩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值