步骤一、安装依赖nodejs
# mkdir /usr/local/nodejs
# cd /usr/local/nodejs
# wget https://npm.taobao.org/mirrors/node/latest-v8.x/node-v8.17.0-linux-x64.tar.gz
# tar -xf node-v8.17.0-linux-x64.tar.gz
# node -v
v8.17.0
# vim /etc/profile
export NODE_HOME=/usr/local/nodejs
export PATH=$PATH:$NODE_HOME/bin
# source /etc/profile
步骤二、修改elasticsearch.yml(支持跨域访问)
vim /etc/elasticsearch/elasticsearch.yml
# 添加
http.cors.enabled: true
http.cors.allow-origin: "*"
步骤三、获取elasticsearch-head-master,并安装必要组件
# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
# unzip master.zip
# cd elasticsearch-head-master
# vim package.json #证书失效替换
license Apache-2.0
# npm install -g grunt-cli
# npm install grunt --save-dev
# grunt -version
步骤四、修改配置
# vim Gruntfile.js
connect => server => options 添加 hostname: '192.168.120.128',
# cd _site/
# vim app.js
localhost替换为安装es机器的IP (192.168.120.128)
步骤五、测试
# grunt server
# nohup grunt server &
访问测试
步骤六、补充
1、npm install 速度缓慢解决方法
# npm get registry #显示当前的镜像网址
# npm config set registry http://registry.npm.taobao.org #使用淘宝的镜像网址
# npm get registry
2、运行grunt server报错
# grunt server
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Invalid or unexpected token
Warning: Task "server" not found. Use --force to continue.
Aborted due to warnings.
检查配置文件
如果运行缺少依赖,检查以下包是否安装完成
# npm install grunt-contrib-clean
# npm install grunt-contrib-concat
# npm install grunt-contrib-watch
# npm install grunt-contrib-copy
# npm install grunt-contrib-connect
# npm install grunt-contrib-jasmine
3、在使用的时候会发现基本查询报404
需要修改vendor.js 将contentType全部替换为application/json;charset=UTF-8