Martin.xu

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

安装环境 CentOS release 7
1、因Elasticsearch是基于Java写的,所以它的运行环境中需要java的支持,在Linux下执行命令:java -version,检查Jar包是否安装
安装java版本至少是1.8以上

检查当前系统是否有jdk 
java -version 
rpm -qa|grep java
移除当前系统安装的jdk 
rpm -e xxx

2、首先准备下载Elasticsearch5.5.0 安装包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz

3、下载到/usr/local 目录下,解压

tar -zxvf  elasticsearch-5.5.0.tar.gz

4、因为Elasticsearch5.0之后,不能使用root账户启动,我们先创建一个elasticsearch组和账户

groupadd elasticsearch
useradd  elasticsearch -g elasticsearch -p elasticsearch
chown -R elasticsearch:elasticsearch elasticsearch-5.5.0

5、启动elasticsearch

cd /usr/local/elasticsearch5.5.0/
su elasticsearch
./bin/elasticsearch

//或用以下命令
su - elasticsearch -c "/usr/local/elasticsearch-5.5.0/bin/elasticsearch -d"

这时候我们看见下面的提示,说明就成功了

[plain] view plain copy print?
[elasticsearch@vmlnx-sma bin]$ ./elasticsearch  
[2017-03-02T21:43:21,185][INFO ][o.e.n.Node               ] [] initializing ...  
[2017-03-02T21:43:21,264][INFO ][o.e.e.NodeEnvironment    ] [uY3prpy] using [1] data paths, mounts [[/ (/dev/mapper/VolGroup-lv_root)]], net usable_space [43.5gb], net total_space [54.6gb], spins? [possibly], types [ext4]  
[2017-03-02T21:43:21,265][INFO ][o.e.e.NodeEnvironment    ] [uY3prpy] heap size [1.9gb], compressed ordinary object pointers [true]  
[2017-03-02T21:43:21,268][INFO ][o.e.n.Node               ] node name [uY3prpy] derived from node ID [uY3prpyqTHim5twauiVWhQ]; set [node.name] to override  
[2017-03-02T21:43:21,271][INFO ][o.e.n.Node               ] version[5.2.2], pid[5602], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/3.10.5-3.el6.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_121/25.121-b13]  
[2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [aggs-matrix-stats]  
[2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [ingest-common]  
[2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-expression]  
[2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-groovy]  
[2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-mustache]  
[2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [lang-painless]  
[2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [percolator]  
[2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [reindex]  
[2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [transport-netty3]  
[2017-03-02T21:43:22,229][INFO ][o.e.p.PluginsService     ] [uY3prpy] loaded module [transport-netty4]  
[2017-03-02T21:43:22,230][INFO ][o.e.p.PluginsService     ] [uY3prpy] no plugins loaded  
[2017-03-02T21:43:24,689][INFO ][o.e.n.Node               ] initialized  
[2017-03-02T21:43:24,689][INFO ][o.e.n.Node               ] [uY3prpy] starting ...  
[2017-03-02T21:43:24,929][INFO ][o.e.t.TransportService   ] [uY3prpy] publish_address {10.245.250.65:9300}, bound_addresses {10.245.250.65:9300}  
[2017-03-02T21:43:24,948][INFO ][o.e.b.BootstrapChecks    ] [uY3prpy] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks  
[2017-03-02T21:43:28,010][INFO ][o.e.c.s.ClusterService   ] [uY3prpy] new_master {uY3prpy}{uY3prpyqTHim5twauiVWhQ}{AqALBH68RCucWcPmHCE6dw}{10.245.250.65}{10.245.250.65:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)  
[2017-03-02T21:43:28,034][INFO ][o.e.h.HttpServer         ] [uY3prpy] publish_address {10.245.250.65:9200}, bound_addresses {10.245.250.65:9200}  
[2017-03-02T21:43:28,034][INFO ][o.e.n.Node               ] [uY3prpy] started  
[2017-03-02T21:43:28,061][INFO ][o.e.g.GatewayService     ] [uY3prpy] recovered [0] indices into cluster_state

执行 

curl http://localhost:9200

打开另一个终端进行测试:

curl 'http://localhost:9200/?pretty'

你能看到以下返回信息:

{
   "status": 200,
   "name": "Shrunken Bones",
   "version": {
      "number": "1.4.0",
      "lucene_version": "4.10"
   },
   "tagline": "You Know, for Search"
}

开机启动配置

chmod +x /etc/rc.d/rc.local

vim /etc/rc.d/rc.local
su - elasticsearch -c "/usr/local/elasticsearch-5.5.0/bin/elasticsearch -d"

说明安装成功。
但是我们希望能够使用ip访问,那么还需要设置相关内容
跳转到Elasticsearch的config配置文件下,使用vim打开elasticsearch.yml,找到里面的"network.host",将其改为本机IP,保存。

cd elasticsearch/config/
vim elasticsearch.yml

重启ElasticSearch,浏览器访问验证

http://192.168.37.137:9200

安装nodejs

//yum方式安装 切换到root用户安装
curl –silent –location https://rpm.nodesource.com/setup_6.x | bash - 
sudo yum -y install nodejs

//查看版本
node –v
v6.10.3
npm –v
3.10.10

安装elasticsearch-head插件

cd /usr/local
git clone git://github.com/mobz/elasticsearch-head.git   //yum install -y git

//更改elasticsearch.yml
http.cors.enabled: true   //是否支持跨域
http.cors.allow-origin: "*"  //表示支持所有域名
#http.cors.allow-headers: Authorization   //安装了xpack,启用了basic authentication

//查看当前head插件目录下有无node_modules/grunt目录:
//没有:执行命令创建:
npm install grunt --save

cd elasticsearch-head

//安装head插件:
npm install

//或者使用重定向安装:
npm install -g cnpm --registry=https://registry.npm.taobao.org

//安装grunt:
npm install -g grunt-cli

//打开elasticsearch-head-master/Gruntfile.js,找到下面connect属性,新增hostname: ‘0.0.0.0’:

connect: {
        server: {
            options: {
                hostname: '0.0.0.0',
                port: 9100,
                base: '.',
                keepalive: true
            }
        }
    }  


//检查head根目录下是否存在base文件夹
//没有:将 _site下的base文件夹及其内容复制到head根目录下
cp -r _site/base ./


//启动grunt server:
//在head下运行grunt server -d启动head插件

访问head插件:
http://localhost:9100(启动后会有提示:Started connect web server on http://localhost:9100)

必做优化

禁用swap

sudo swapoff -a

修改linux内核参数

sudo vim /etc/security/limits.conf 

//添加如下内容:
 * soft nofile 65536
 * hard nofile 131072
 * soft memlock unlimited
 * hard memlock unlimited

修改虚拟内存空间及swap使用率

sudo vim /etc/sysctl.conf

vm.zone_reclaim_mode=0
vm.max_map_count=655360
vm.swappiness=1

 内核配置立即生效

sudo sysctl -p

修改创建本地线程数

sudo vim /etc/security/limits.d/90-nproc.conf 

//修改为
* soft nproc 2048

 

我们常见错误:

问题一:警告提示

[2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ] unable to install syscall filter: 

java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0]
at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0]

报了一大串错误,其实只是一个警告。

解决:使用心得linux版本,就不会出现此类问题了。

问题二: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 131072
* soft nproc 2048
* hard nproc 4096

问题三:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]

解决:切换到root用户,进入limits.d目录下修改配置文件。

vi /etc/security/limits.d/90-nproc.conf 

//修改如下内容:
* soft nproc 1024
//修改为
* soft nproc 2048

 

posted on 2017-07-24 14:33  Martin.xu  阅读(960)  评论(0编辑  收藏  举报