$: tar -zxvf jdk-8u181-linux-x64.tar.gz
$: mkdir /usr/local/java
$: cp jdk1.8.0_181 /usr/local/java/
##配置环境变量.bash_profile 或者 /etc/profile
$: vi ~/.bash_profile
## 输入下列配置
JAVA_HOME=/usr/local/java/jdk1.8.0_181
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
$: java -version | javac -version
> java version "1.8.0_181"
> Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
> Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
> javac 1.8.0_181
Elasticsearch的安装过程非常容易,下面介绍在不同的操作系统如何安装 -
$ tar –xvf elasticsearch-5.3.0.tar.gz
$ mv elasticsearch-5.3.0 /home/es/
$ cd /home/es
在Windows中
> cd elasticsearch-5.3.0/bin
> elasticsearch
在Linux中
$ cd elasticsearch-5.3.0/bin
$ ./elasticsearch
修改访问es的ip及端口如下:
$ vi /home/es/elasticsearch-5.3.0/config/elasticsearch.yml
> #Set the bind address to a specific IP (IPv4 or IPv6):
> network.host: 172.16.119.154 (本机ip地址)
> #Set a custom port for HTTP:
> http.port: 9200
$ cd /home/es/elasticsearch-5.3.0/
前台启动:
$ ./bin/elasticsearch
后台启动:
$: ./elasticsearch-5.3.0/bin/elasticsearch -d
启动成功后,在web浏览器中输入172.16.119.154:9200,如果返回以下页面,则说明成功。
{
name: "YoXmVYH",
cluster_name: "elasticsearch",
cluster_uuid: "Yw8f033SSb6_oc5o2v1r7w",
version: {
number: "5.3.0",
build_hash: "3adb13b",
build_date: "2017-03-23T03:31:50.652Z",
build_snapshot: false,
lucene_version: "6.4.1"
},
tagline: "You Know, for Search"
}
启动后,如果只有本地可以访问,尝试修改配置文件 elasticsearch.yml
中network.host (注意配置文件格式不是以 # 开头的要空一格, : 后要空一格)
为 network.host: 0.0.0.0
默认端口是 9200
注意:关闭防火墙 或者开放9200端口
elasticsearch.yml配置文件格式不是以 # 开头的要空一格, : 后要空一格
(1)JVM内存问题
如果遇到:
说明jvm启动内存太大,机器内存不足(如果按照之前虚拟机配置中的1G来配置,则会出现此问题,因为es默认jvm启动内存是2g,所以我们需要配置一下es的启动内存)
编辑es/config/jvmoptions文件,修改以下两个参数:
#-Xms2g
#-Xmx2g
-Xms512m
-Xmx512m
(2)根权限执行问题
如果遇到:
根据提示,无法以根权限启动es程序,所以我们创建一个非根用户,并给它赋予目录该用户权限。es 无法以root用户启动
# groupadd es
# useradd es -g es -p es
# chown -R es:es /home/es
# chmod -R 770 /home/es/
# sudo su es
用root用户给es用户赋权时没有完全将es目录的所有文件权限给es,重新用root用户身份执行:(-R参数不要掉,表示递归将es目录下所有文件权限给es用户)
$ chown -R yehao:yehao /home/es/elasticsearch-5.3.0/
(3)内存问题:
有[1][2][3]三个问题,逐一解决:
[1]: initial heap size [16777216] not equal to maximum heap size [257949696]; this can cause resize pauses and prevents mlockall from locking the entire heap
第一个问题还是jvm内存问题,请重新检查可能碰到的问题(1)JVM内存问题,按照步骤重新检查一遍。
[2]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
Es进程设置的最大文件描述符太小,需要增加。
编辑/etc/security/limits.conf,最后加上:
es soft nofile 65536
es hard nofile 65536
然后重新连接shell,切换到es用户,再尝试启动es。
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
是因为操作系统的vm.max_map_count参数设置太小导致的,有两种方式解决,
sysctl -w vm.max_map_count=262144
$: vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
sysctl -a | grep “vm.max_map_count”
如果能正常输出262144,则说明修改成功
(4) 启动异常:ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
问题原因:因为Centos6不支持SecComp,而ES5.2.1默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。详见 :https://github.com/elastic/elasticsearch/issues/22899
解决方法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
(5) ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
解决方法:切换到root用户,编辑limits.conf 添加类似如下内容
$: vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
一、安装nodejs和rpm
1. su - root
2. yum install epel-release
3. yum install nodejs npm
注意:如果失败请检查CDN配置
$: vi /etc/resole.conf
添加:
nameserver: 8.8.8.8
nameserver: 114.114.114.114
$: systemctl restart NetworkManager 重启网络
二、下载并安装elasticsearch-head (yum install git安装Git)
1. git clone https://github.com/mobz/elasticsearch-head.git
2. cd elasticsearch-head
3. npm install
------------------------------------------------------------------------------
如果出现如下错误:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] license should be a valid SPDX license expression
npm ERR! Linux 3.10.0-693.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! node v6.14.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node install.js'.
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 phantomjs-prebuilt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs phantomjs-prebuilt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls phantomjs-prebuilt
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/elasticsearch-head/npm-debug.log
------------------------------------------------------------------------------
没有问题直接运行
4. npm run start
5. open http://localhost:9100 or http://you IP Address:9100 能正常打开说明head插件安装正确
三、如果想查询集群健康信息,那么需要在elasticsearch配置文件中授权
1. 在elasticsearch下的elasticsearch.yml下新增一下两行:
http.cors.enabled: true # elasticsearch中启用CORS
http.cors.allow-origin: "*" # 允许访问的IP地址段,* 为所有IP都可以访问
2. 重启elastsearch
systemctl restart elasticsearch.service
或者
cd /es
./bin/elasticsearch
四、修改es-head的localhost地址
1. cd ./elasticsearch-head #(elasticsearch-head源码文件夹)
2. vim Gruntfile.js
3. Add hostname
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
五、修改head的连接地址
1. cd ./elasticsearch-head #(elasticsearch-head源码文件夹)
2. vim ./_site/app.js
3. 将localhost修改为ESdeIP地址
修改前:this.base_uri = this.config.base_uri;
修改后:this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://you ip address:9200";
六、启动elasticsearch-head
1. cd elasticsearch-head(elasticsearch-head源码目录)
2. ./node_modules/grunt/bin/grunt server
后台启动 > nohup ./node_modules/grunt/bin/grunt server >1.out &
关闭:ps -axu | grep grunt
kill -9 $pid
若有不正确之处,请指正!!!