Elasticsearch集群搭建1Welcome to my ELK world!
系统环境:
jdk1.8环境
ubuntu16.04系统 172.20.1.10 node-1
ubuntu16.04系统 172.20.1.20 node-2
ubuntu16.0.4系统 172.20.1.30 node-3
安装elasticsearch版本:elasticsearch-6.2.2.tar.gz
安装包下载路径(里边有6.2.2版本、6.4.2版本和jdk1.8的包):
https://pan.baidu.com/s/1bTBb6n27wcunwAFCRB5yNQ 密码:8raw
1.安装elasticsearch参考:http://www.cnblogs.com/hanyinglong/p/5409003.html
说一下我自己的做法
查看一下自己的java环境换成jdk1.8,这个网上一大堆参考文档。
这里大概说一下,就是解压包然后配置环境变量
路径根据自己解压的位置去指定。最后source /etc/profile
mkdir -p /data/software/elasticsearch
创建用户,因为启动es不能用root用户。
sudo adduser es
然后敲个Y完事。
cd /home/下看一下有没有家目录。
然后到下载包存放路径解压包。
sudo tar -zxvf elasticsearch-2.3.1.tar.gz
sudo mv elasticsearch-2.3.1 /data/software/elasticsearch
sudo chown -R es.es /data/software/elasticsearch
我们看一下es的文件结构:
我们每个机器上做一个es,这个不是建议也不是什么经验之谈,因为你是运维(背锅侠),你的要注意都做一台机器上万一机器宕机了,数据可就全没了。最普通小白安全的做法就是3台机器每个服务器上只做一个节点(此做法允许且只允许任意一台服务器宕机),不了解es为什么这样做的请读我的技术点篇。
接下来我们修改elasticsearch的配置文件。
修改完成以后我们切换到es用户去启动es,记住:切换到es用户!切换到es用户!!切换到es用户!!!
要不就会出现如下情况:
但是你可能会遇到如下情况哈哈,不要慌:基本操作。
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
等问题,修改几个配置文件:/etc/profile文件最后边添加:ulimit -SHn 65536
/etc/security/limits.conf文件最后添加:
- soft nofile 65536
- hard nofile 65536
- soft nproc 4096
- hard nproc 4096
然后我们把这些配置应用到es用户可以看一下ulimit -Hn
一切正常后我们再启动
我们在网页访问ip:9200出来如下内容表示成功
其他的2个节点按上边的操作正常操作完毕(可能会出现的一个问题启动前先删除/data/software/elasticsearch/data/节点目录下的数据),出现如上图恭喜你成功了.
接下来就是安装比较麻烦又low的elasticsearch-head,也给大家操作一下吧,(生产环境能不用head插件尽量别用,因为安全性特别差暴露给别人,别人可以上你的es对节点进行操作)
elasticsearch 5.x之后不支持直接plugin安装head插件,而是将head作为一个独立的服务安装的,首先需要安装依赖的node,npm,grunt
apt-get install npm
apt-get install nodejs-legacy
npm install -g grunt
npm install -g grunt-cli
下载elasticsearch-head,我解压到目录/data/software/elasticsearch-head,将目录用户改为es
然后修改配置
1.修改head的连接地址 elasticsearch-head/_site/app.js
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
localhost改为自己的ip
2.修改服务器的监听地址elasticsearch-head/Gruntfile.js
connect: { server: { options: { port: 9100, base: '.', keepalive: true } } }
options中添加 hostname: '*'
3.修改elasticseach的配置文件elasticsearch.yml, 修改对应的ip以及跨域的设置,添加:
http.cors.enabled: true
http.cors.allow-origin: "*"
3 在elasticsearch-head下运行: grunt server
3.1 但是会出现错误提示(当时命令敲的npm start,应该是一样的):
root@ubuntu:/usr/local/kencery/elasticsearch-head# npm start
[email protected] start /usr/local/kencery/elasticsearch-head
grunt servergrunt-cli: The grunt command line interface (v1.2.0)
Fatal error: Unable to find local grunt.
If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:http://gruntjs.com/getting-started
npm ERR! Linux 4.4.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start:grunt server
npm ERR! Exit status 99
npm ERR!
npm ERR! Failed at the [email protected] start script 'grunt server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the elasticsearch-head package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! grunt server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs elasticsearch-head
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls elasticsearch-head
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/kencery/elasticsearch-head/npm-debug.log
看提示大概有提到版本不是最新的问题,所以就抱着试一试的心态去升级npm以及node
npm cache clean -f
npm install -g n
n stable
npm install npm@latest -g
再查看下版本,会看到
elasticsearch@ubuntu:~$ node -v
v10.4.0
elasticsearch@ubuntu:~$ npm -v
6.1.0
3.2 但是运行grunt server依然报错:
grunt hasn't been installed locally to your project
参考 https://segmentfault.com/q/1010000004172559/a-1020000004193932, 执行:
npm install grunt --save-dev
3.3 再次运行,依然报错:
elasticsearch@ubuntu:/usr/local/kencery/elasticsearch-head$ grunt server
Local Npm module "grunt-contrib-clean" not found. Is it installed?
Local Npm module "grunt-contrib-concat" not found. Is it installed?
Local Npm module "grunt-contrib-watch" not found. Is it installed?
Local Npm module "grunt-contrib-connect" not found. Is it installed?
Local Npm module "grunt-contrib-copy" not found. Is it installed?
Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Warning: Task "connect:server" not found. Use --force to continue.
然后我干脆把有关grunt的都装了一遍最新的:
npm install grunt@latest
npm install grunt-cli@latest
npm install grunt-contrib-copy@latest
npm install grunt-contrib-concat@latest
npm install grunt-contrib-uglify@latest
npm install grunt-contrib-clean@latest
npm install grunt-contrib-watch@latest
npm install grunt-contrib-connect@latest
npm install grunt-contrib-jasmine@latest
4.4 最后grunt server终于可以启动了:
elasticsearch@ubuntu:/usr/local/kencery/elasticsearch-head$ grunt server
(node:1527) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
可以看到elasticsearch服务的端口是9200,head插件服务的端口是9100,我们访问head然后head再访问的elasticsearch。
参考文档:
1https://blog.csdn.net/shm839218753/article/details/80618073