安裝部署elasticsearch
1.下載地址
下載地址:https://www.elastic.co/downloads/elasticsearch,我這里下載的是 elasticsearch-6.4.0.tar.gz
2.解壓縮並創建數據目錄
[root@localhost soft]# tar -xvf elasticsearch-6.4.0.tar.gz
[root@localhost soft]# mv elasticsearch-6.4.0 /opt/
[root@localhost soft]#cd /opt/elasticsearch-6.4.0
[root@localhost soft]#mkdir data
3.創建用戶
因為啟動es不能在root用戶下啟動,所以要事先創建非root用戶
[root@localhost opt]# useradd esuser
[root@localhost opt]# chown -R esuser.esuser ./elasticsearch-6.4.0/
4.配置環境變量
[esuser@localhost ~]$ more .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/opt/jdk1.8.0_151
PATH=$JAVA_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin
export PATH
5.修改配置
vi /opt/elasticsearch-6.4.0/config/elasticsearch.yml
A.開放network.host,如下:
network.host: 192.168.1.85
B.在后面添加如下兩項
http.cors.enabled: true
http.cors.allow-origin: "*"
C.修改日志存放路徑
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /opt/elasticsearch-6.4.0/data
path.logs:/opt/elasticsearch-6.4.0/logs
6.修改系統配置文件
A.修改limits.conf配置文件
vi /etc/security/limits.conf
root用戶下添加如下2兩項,然后退出使用crate用戶登陸,使其生效
* hard nofile 65536
* soft nofile 65536
可是,我的配置本來就已經設置成這樣了的
網上找來找去,都是修改limits.conf文件這個答案,最怕這種了,所有的人都指向同一個答案,卻不能解決自己的問題
后來突然想到是不是環境變量的問題,仔細檢查了一遍,發現一個可疑的設置
vi /etc/profile
ulimit -n 65535
使用 ulimit -Hn 查看當前值,果然是65535,
ulimit -Hn
65535
也就是說每次更新環境變量的時候limits.conf的hard nofile 65536設置被覆蓋掉了
這就好辦了,vi /etc/profile 將 ulimit -n 65535 行注釋掉,退出重新進入當前用戶,再使用 ulimit -Hn 查看當前值,已經是65536了,設置成功!
B.修改sysctl.conf文件
vi /etc/sysctl.conf
vm.max_map_count=262144
執行下面命令生效
sysctl -p
7.配置jvm內存大小
修改文件./config/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms8g
-Xmx8g
修改文件
./bin/elasticsearch
添加紅色項目
export ES_HEAP_SIZE=8g
source "`dirname "$0"`"/elasticsearch-env
8.退出重新登錄用戶登錄並啟動
[root@localhost opt]# su - esuser
[esuser@localhost bin]$ cd /opt/elasticsearch-6.4.0/bin
[esuser@localhost bin]$./elasticsearch -d
9.測試我們的es是否好用
[esuser@localhost logs]$ curl http://192.168.1.85:9200/?pretty
{
"name" : "UyIrNGO",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "YNvgGJC0QLeMsKt71e7tsw",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[esuser@localhost logs]$
10.外部瀏覽器調試es時需要修改的配置
11.然后在瀏覽器里輸入如下地址
http://192.168.1.85:9200/
12.配置驗證(elastic默認的密碼是changeme)
修改配置文件,在配置文件最后加上
xpack.security.enabled: true
然后重新啟動
運行如下命令設置密碼
./elasticsearch-setup-passwords interactive
13.通過賬目密碼訪問
curl -u elastic:elastic "192.168.1.85:9200"
14.設置開機自啟動
在/etc/systemd/system目錄下創建elasticsearch.service文件
[Unit]
Description=elasticsearch
[Service]
User=yeemiao
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/home/yeemiao/es/bin/elasticsearch
[Install]
WantedBy=multi-user.target
設置開機自啟
systemctl enable elasticsearch
阿里雲機器
[yeemiao@common-es01 ~]$ more /etc/systemd/system/elasticsearch.service
[Unit]
Description=elasticsearch.service
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/su - yeemiao -c "/home/yeemiao/es/bin/elasticsearch -d -p pid"
[Install]
WantedBy=multi-user.target
15.問題
阿里雲ssh的方式登陸進去發現max file descriptors不生效,非要su - root后,再su - yeemiao才生效,是否生效可以用如下命令查看:
ulimit -Hn