CentOS7上ElasticSearch安装填坑记
按照道理应该就可以了,然而接下来各种坑一一出现,分别阐述
错误1:
error='Cannot allocate memory' (errno=12)
![](http://upload-images.jianshu.io/upload_images/9824247-bf7df623f31204b8.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
solutions:
由于elasticsearch5.0默认分配jvm空间大小为2g,需要改小一点
vim config/jvm.options
-Xms2g → -Xms512m
-Xmx2g → -Xmx512m
错误2: can not run elasticsearch as root
![](http://upload-images.jianshu.io/upload_images/9824247-ae352ae5780de1dd.png?imageMogr2/auto-orient/strip|imageView2/2/w/1180/format/webp)
solutions:
在 Linux 环境中,elasticsearch 不允许以 root 权限来运行!所以需要创建一个非root用户,以非root用户来起es
groupadd elk # 创建用户组elk
useradd elk -g elk -p 111111 # 创建新用户elk,-g elk 设置其用户组为 elk,-p 111 设置其密码6个1
chown -R elk:elk /opt # 更改 /opt 文件夹及内部文件的所属用户及组为 elk:elk
su elk # 切换到非root用户elk下来
错误3:(1) max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
(2) max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
此错误出现在修改config/elasticsearch.yml中的network.host为network.host: 0.0.0.0以便让外网任何IP都能来访问时。
solutions:
切换到root用户,然后
vim /etc/security/limits.conf
* soft nofile 300000
* hard nofile 300000
* soft nproc 102400
* soft memlock unlimited
* hard memlock unlimited
![](http://upload-images.jianshu.io/upload_images/9824247-06d4a2c3a5a28ff6.png?imageMogr2/auto-orient/strip|imageView2/2/w/414/format/webp)
错误4:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
![](http://upload-images.jianshu.io/upload_images/9824247-f347a09184d4c171.png?imageMogr2/auto-orient/strip|imageView2/2/w/978/format/webp)
solutions:
先要切换到root用户;
然后可以执行以下命令,设置 vm.max_map_count ,但是重启后又会恢复为原值。
sysctl -w vm.max_map_count=262144
持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 参数:
echo "vm.max_map_count=262144" > /etc/sysctl.conf
sysctl -p
![](http://upload-images.jianshu.io/upload_images/9824247-70f1fd2f3ca40884.png?imageMogr2/auto-orient/strip|imageView2/2/w/1091/format/webp)
最后终于在外网访问成功:
![](http://upload-images.jianshu.io/upload_images/9824247-b81eb7e914736546.png?imageMogr2/auto-orient/strip|imageView2/2/w/595/format/webp)
安装可视化插件 elasticsearch-head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install # 此处我试图用cnpm install有问题,用npm可以
npm run start
![](http://upload-images.jianshu.io/upload_images/9824247-b5ce1ede0ce91b04.png?imageMogr2/auto-orient/strip|imageView2/2/w/549/format/webp)
然后在外网访问http://你的安装机IP:9100
![](http://upload-images.jianshu.io/upload_images/9824247-9d0fbaec06affe90.png?imageMogr2/auto-orient/strip|imageView2/2/w/804/format/webp)
最后实际简单测试一下
新建 Index,可以直接向 Elastic 服务器发出 PUT 请求。下面的例子是新建一个名叫weather的 Index。
![](http://upload-images.jianshu.io/upload_images/9824247-519f086e398de237.png?imageMogr2/auto-orient/strip|imageView2/2/w/650/format/webp)
然而刷新elasticsearch-head可视化界面可以看到索引已经成功插入
![](http://upload-images.jianshu.io/upload_images/9824247-a6e9bc43827de5a7.png?imageMogr2/auto-orient/strip|imageView2/2/w/817/format/webp)
作者:CodeSheep
链接:https://www.jianshu.com/p/04f4d7b4a1d3
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。