Elasticsearch在Centos 7上的安装与配置

安装Elasticsearch

手动安装elasticsearch

最简单的方式是通过Yum或rpm的方式进行安装,这里介绍的是手动安装的方法:

1、进入官网查看最新版本的下载链接

2、使用命令行进行下载:

3、解压文件

4、运行elasticsearch

执行 sh /usr/local/elasticsearch-2.4.0/bin/elasticsearch -d  其中-d表示后台启动

不出意外,可以看到如下报错信息:

原因是elasticsearch默认是不支持用root用户来启动的。

解决方案一:Des.insecure.allow.root=true

修改/usr/local/elasticsearch-2.4.0/bin/elasticsearch,添加 ES_JAVA_OPTS="-Des.insecure.allow.root=true"

或执行时添加: sh /usr/local/elasticsearch-2.4.0/bin/elasticsearch -d -Des.insecure.allow.root=true

注意:正式环境用root运行可能会有安全风险,不建议用root来跑。

解决方案二:添加专门的用户

使用 curl http://localhost:9200/ 查看是否运行,如果返回如下信息则标示运行正常:

elasticsearch默认restful-api的端口是9200 不支持Ip地址,只能在本机用http://localhost:9200来访问。如果需要改变,需要修改配置文件。

默认情况下 Elasticsearch 的 RESTful 服务只有本机才能访问,也就是说无法从主机访问虚拟机中的服务。为了方便调试,可以修改 /etc/elasticsearch/config/elasticsearch.yml 文件,加入以下两行:

或去除network.host 和http.port之前的注释,并将network.host的IP地址修改为本机外网IP。然后重启,Elasticsearch 关闭方法(输入命令: ps -ef | grep elasticsearch ,找到进程,然后kill掉就行了。

如果外网还是不能访问,则有可能是防火墙设置导致的。

使用YUM进行安装

添加elasticsearch的repo,在/etc/yum.repos.d/下新增elasticsearch.repo:

文件内容如下:

然后使用最简单的yum命令即可进行安装:

使用RPM进行安装

也是非常的简单。

防火墙设置

1、关闭selinux

2、安装firewall

yum install firewalld firewall-config

3、开放端口

至此,elasticsearch就顺利安装完成了,但是为了更好的使用,还需要安装中文分析工具等插件,下篇文章再做介绍。

使用systemd管理elasticsearch服务

elsticsearch配置说明

如果使用yum或rpm方式安装Elasticsearch默认的配置文件地址是:/etc/elasticsearch/elasticsearch.yml,详细的配置说明可以参考Configuring Elasticsearch。另外还有一个系统配置存放在/etc/sysconfig/elasticsearch,可设置的内容包含如下参数:

ES_USER The user to run as, defaults to elasticsearch.
ES_GROUP The group to run as, defaults to elasticsearch.
JAVA_HOME Set a custom Java path to be used.
MAX_OPEN_FILES Maximum number of open files, defaults to 65536.
MAX_LOCKED_MEMORY Maximum locked memory size. Set to unlimited if you use thebootstrap.memory_lock option in elasticsearch.yml.
MAX_MAP_COUNT Maximum number of memory map areas a process may have. If you use mmapfsas index store type, make sure this is set to a high value. For more information, check the linux kernel documentation about max_map_count. This is set via sysctl before starting elasticsearch. Defaults to 262144.
LOG_DIR Log directory, defaults to /var/log/elasticsearch.
DATA_DIR Data directory, defaults to /var/lib/elasticsearch.
CONF_DIR Configuration file directory (which needs to include elasticsearch.ymland log4j2.properties files), defaults to /etc/elasticsearch.
ES_JAVA_OPTS Any additional JVM system properties you may want to apply.
RESTART_ON_UPGRADE Configure restart on package upgrade, defaults to false. This means you will have to restart your elasticsearch instance after installing a package manually. The reason for this is to ensure, that upgrades in a cluster do not result in a continuous shard reallocation resulting in high network traffic and reducing the response times of your cluster.

另外,一些默认安装的文件路径如下:

Type Description Default Location Setting
home Elasticsearch home directory or $ES_HOME /usr/share/elasticsearch  
bin Binary scripts including elasticsearch to start a node and elasticsearch-plugin to install plugins /usr/share/elasticsearch/bin  
conf Configuration files including elasticsearch.yml /etc/elasticsearch path.conf
conf Environment variables including heap size, file descriptors. /etc/sysconfig/elasticsearch  
data The location of the data files of each index / shard allocated on the node. Can hold multiple locations. /var/lib/elasticsearch path.data
logs Log files location. /var/log/elasticsearch path.logs
plugins Plugin files location. Each plugin will be contained in a subdirectory. /usr/share/elasticsearch/plugins  
repo Shared file system repository locations. Can hold multiple locations. A file system repository can be placed in to any subdirectory of any directory specified here. Not configured path.repo
script Location of script files. /etc/elasticsearch/scripts path.scripts
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值