注: 本文首发于 My 公众号 CodeSheep ,可 长按 或 扫描 下面的 当心心 来订阅 ↓ ↓ ↓git
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz mv elasticsearch-5.3.0.tar.gz /opt cd /opt tar -xzvf elasticsearch-5.3.0.tar.gz cd elasticsearch-5.3.0/
cd /bin ./elasticsearch
按照道理应该就能够了,然而接下来各类坑一一出现,分别阐述github
错误1:
error='Cannot allocate memory' (errno=12)
npm
solutions: 因为elasticsearch5.0默认分配jvm空间大小为2g,须要改小一点vim
vim config/jvm.options -Xms2g → -Xms512m -Xmx2g → -Xmx512m
错误2: can not run elasticsearch as root服务器
solutions: 在 Linux 环境中,elasticsearch 不容许以 root 权限来运行!因此须要建立一个非root用户,以非root用户来起esjvm
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]elasticsearch
此错误出如今修改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
错误4:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]rest
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
最后终于在外网访问成功:
git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install # 此处我试图用cnpm install有问题,用npm能够 npm run start
而后在外网访问http://你的安装机IP:9100
新建 Index,能够直接向 Elastic 服务器发出 PUT 请求。下面的例子是新建一个名叫weather的 Index。
然而刷新elasticsearch-head可视化界面能够看到索引已经成功插入