当我们安装elasticsearch时,需要注意一下问题
- 优化配置
以下是如何通过jvm.options文件设置堆大小的示例:
-Xms2g
-Xmx2g
将最小堆大小(Xms)和最大堆大小(Xmx)设置为彼此相等
设置Xmx为不超过物理RAM的50%,以确保有足够的物理RAM用于内核文件系统缓存 但是不能超过32g,超过32g java指针将不是压缩的,反而会慢
锁住swap,这会影响es性能(或者修改elasticsearch.yml 添加配置bootstrap.memory.lock)
- 当开启 bootstrap.memory.lock: TURE
启动报错:
memory locking requested for elasticsearch process but memory is not locked
之后重启,还是报上面的错误。以为没配好,之后又改了n次。还是不行。
然后查资料,果然,配置文件不一样了。。
limits.conf这里的配置,只适用于通过PAM认证登录用户的资源限制,它对systemd的service的资源限制不生效。登录用户的限制,通过 /etc/security/limits.conf 来配置
对于systemd service的资源限制,现在放在 /etc/systemd/system.conf 和 /etc/systemd/user.conf
这两个文件里面了。
主要就是/etc/systemd/system.conf这个文件
然后修改下面几项:
DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity
注意把注释行去掉
安装elasticsearch5.0
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.0.0.tar.gz
tar xf elasticsearch-5.0.0.tar.gz
mv elasticsearch-5.0.0 /usr/local/elasticsearch
mkdir -pv /data/elasticsearch/{data,logs}
useradd elasticsearch
chown -R elasticsearch.elasticsearch /data/elasticsearch
chown -R elasticsearch.elasticsearch /usr/local/elasticsearch/
修改配置文件
cat /usr/local/elasticsearch/config/elasticsearch.yml |grep -v "^#" |grep -v "^$"
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
修改系统参数
cat /etc/security/limits.conf |grep -v "^#" |grep -v "^$"
* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536
启动es
su - elasticsearch -c "/usr/local/elasticsearch/bin/elasticsearch &"
安装elasticsearch-head插件
下载
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
安装node环境
wget https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-x64.tar.xz
mv node-v10.15.0-linux-x64 /usr/local/node
添加node环境变量
vim /etc/profile
添加:
export NODE_HOME=/usr/local/node
export PATH=$PATH:$NODE_HOME/bin
source /etc/profile
[root@elas src]# node -v
v10.15.0
[root@elas src]# npm -v
6.4.1
安装grunt(grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等工作,elasticsearch-head插件就是通过grunt启动的)
[root@elas src]# cd elasticsearch-head-master/
[root@elas elasticsearch-head-master]# npm install -g grunt-cli
/usr/local/node/bin/grunt -> /usr/local/node/lib/node_modules/grunt-cli/bin/grunt
+ [email protected]
added 152 packages from 122 contributors in 22.183s
[root@elas elasticsearch-head-master]# grunt -version
grunt-cli v1.3.2
修改elasticsearch-head-master下Gruntfile.js配置文件,添加hostname: '*',
connect: {
server: {
options: {
hostname: '*',
port: 9100,
base: '.',
keepalive: true
}
安装cnpm
[root@elas elasticsearch-head-master]# npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
/usr/local/node/bin/cnpm -> /usr/local/node/lib/node_modules/cnpm/bin/cnpm
+ [email protected]
added 679 packages from 898 contributors in 16.873s
继续执行
yum install bzip2 -y
cnpm install
修改 elasticsearch.yml
添加以下几行
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
重启elasticsearch
安装完成后没有报错的话启动elasticsearch-head-master
grunt server &
当执行 cnpm install时候报错解决:
Get /binary-mirror-config/latest from https://registry.npm.taobao.org error: ConnectionTimeoutError: Connect timeout for 5000ms, GET https://registry.npmjs.com/binary-mirror-config/latest -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":4,"createSocketErrorCount":0,"closeSocketCount":4,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)……
然后找到报错根源:
/nodejs/lib/node_modules/cnpm/node_modules/urllib/lib/urllib.js
修改掉文件里面的常量 TIMEOUT、TIMEOUTS 的 5s 为 10s