GrayLog 服務端需要一些環境依賴
- Linux 發行版(如Debian、Ubuntu、或推薦使用的CentOS)
- Elasticsearch 2.x (2.1.0 or later)graylog2.3以後版本支持了elasticsearch5.x版本,但是不支持6.x版本
- MongoDB 2.4 or later (latest stable version is recommended)
- Oracle Java SE 8 or later (OpenJDK 8 also works; latest stable update is recommended)
準備工作
- 在linux系統的/home下新建文件夾zzx
- 在zzx中新建:Java、Mongodb、Elasticsearch文件夾
安裝jdk8(elasticsearch依賴jdk8)
-
下載jdk
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz"
-
解壓二進制包
tar -xzvf jdk-8u144-linux-x64.tar.gz
-
給單獨的用戶添加環境變量
#elasticsearch
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch:elsearch "${TOP_DIR}/Elasticsearch/elasticsearch-5.4.0"
sudo su elsearch -c "export JAVA_HOME=/home/zzx/Java/jdk1.8.0_144 && export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar && export PATH=$JAVA_HOME/bin:$PATH:$HOME/bin && ${elasticsearch_top}/bin/elasticsearch"
備註
- jdk主要是給ElasticSearch和graylog使用的,ElasticSearch在啓動的時候會單獨開一個用戶,所用我們吧jdk設置成這個用戶使用,以便不影響系統中其他的jdk版本
MongoDB安裝
-
下載monogdb
在/home/zzx/Mongodb下執行curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.7.tgz
-
解壓二進制包
tar -xzvf mongodb-linux-x86_64-3.2.7.tgz
-
配置
#創建db目錄
mkdir -p /home/zzx/Mongodb/data/db
- 3.1. 可選配置
#自定義配置文件: mongodb.conf
#創建配置文件,放到一個目錄下,我的就放到了和mongodb的bin同級目錄裏了
vim mongodb.conf // 這裏是創建文件
#配置內容如下:
<<<<<<<<<<< 分割線
dbpath=/data/Mongodb/data/db
logpath=/data/Mongodb/log/mongodb.log
logappend=true
fork=true
port=27017
# auth = true
# 先關閉, 創建好用戶在啓動
>>>>>>>>>>>>分割線
- 啓動數據庫服務器
/home/zzx/Mongodb/mongodb-linux-x86_64-3.2.7/bin/mongod --dbpath /home/zzx/Mongodb/data/db
- 鏈接數據庫
/home/zzx/Mongodb/mongodb-linux-x86_64-3.2.7/bin/mongo/h
參考鏈接
https://itjh.net/2016/07/11/centos-install-mongodb/
在CentOS7上源碼安裝MongoDB 3.2.7
知識點
查詢mongdb的進程PID號
ps -ef | grep mongod
kill -4 [PID] //殺掉進程
mongodb啓動命令中讀取配置文件的參數是 -f
./mongod -f [mongod.conf文件目錄]
eg: ./mongod -f /home/mongodb/mongod.conf
elasticsearch安裝
- 下載elasticsearch
在/home/zzx/Elasticsearch下執行
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz - 解壓二進制包
tar -xzvf elasticsearch-5.5.2.tar.gz - 配置
1. 修改/home/zzx/Elasticsearch/elasticsearch-5.4.0/config目錄下的配置文件:elasticsearch.yml
2. 如果報JAVA內存不足的錯誤(如下),
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000
則修改配置文件/home/zzx/Elasticsearch/elasticsearch-5.4.0/config/jvm.options
vim /home/zzx/Elasticsearch/elasticsearch-5.4.0/config/jvm.options
....
修改後的圖片
3. 配置腳本:
#elasticsearch
groupadd elsearch
useradd elsearch -g elsearch
chown -R elsearch:elsearch "${TOP_DIR}/Elasticsearch/elasticsearch-5.4.0"
#java
killall -s 9 java
su - elsearch -c "export JAVA_HOME=/home/zzx/Java/jdk1.8.0_144 && export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar && export PATH=$JAVA_HOME/bin:$PATH:$HOME/bin && ${elasticsearch_top}/bin/elasticsearch&"
-
知識點
1. 啓動elasticSearch時,在最後面加一個給&符合,即可在後臺運行,shell關閉也會一直在運行
Graylog2安裝
- 下載graylog
wget https://packages.graylog2.org/releases/graylog/graylog-2.3.1.tgz
- 解壓安裝包
tar zxvf graylog-2.3.1.tgz
-
配置 graylog.conf.exampl文件在解壓文件中
#配置文件創建 cp graylog.conf.example /etc/graylog/server/server.conf
-
安裝輔助工具:pwgen、perl-Digest-SHA,用來生成密碼
yum install pwgen perl-Digest-SHA -y
-
生成密鑰-將生成的密文保存,下一步配置文件要用
pwgen -N 1 -s 96 echo -n 123456x | shasum -a 256
-
修改配置文件
vim /etc/graylog/server/server.conf
修改爲:
#命令生成 password_secret:pwgen -N 1 -s 96
password_secret =blwVhWyYQhf5zl3UBcLnxfXhoXVSxkSB7hH6ndUJzdQS2HOzlpnstp0slm0F4rekhuKcrVPSBLcuBEXvluL67dQEtNJvbUwv
#生成加密密碼 root_password_sha2: echo -n yourpassword | shasum -a 256
root_password_sha2 = 8670fc6414ede6766e9bdb469f9661d4bccd80ac2ed8197f0857b407320c8a8e
#配置rest api的URI
rest_listen_uri = http://127.0.0.1:9000/api/
#配置web 界面的URI
web_listen_uri = http://127.0.0.1:9000/
#配置 elasticsearch 配置文件路徑
elasticsearch_config_file = /etc/elasticsearch/elasticsearch.yml
問題記錄
-
配置完成以後,web頁面能訪問,但是無法搜索以及搜鎖長時間卡死不出結果
解決方法 :很有可能是es的索引出問題了,刪除es的索引curl -XDELETE 'http://0.0.0.0:9200/graylog_0/'