kibana源码编译

发布于:2024-04-18 ⋅ 阅读:(32) ⋅ 点赞:(0)

一、安装nodejs16.14.2及yarn

(一)nodejs

1、下载

https://cdn.npmmirror.com/binaries/node/v16.14.2/node-v16.14.2-linux-x64.tar.gz

2、解压

tar -zxf node-v16.14.2-linux-x64.tar.gz -C /app
cd /app
mv node-v16.14.2-linux-x64 node

3、配置环境变量

vim /etc/profile

在最后添加如下内容:

export NODE_HOME=/app/node
#export JAVA_HOME=/app/jdk

export PATH=$NODE_HOME/bin:$PATH
#export PATH=$NODE_HOME/bin:$JAVA_HOME/bin:$PATH

使环境变量生效:

source /etc/profile

4、验证

[root@localhost kibana]# node -v
v16.14.2
[root@localhost kibana]# npm -v
8.5.0
[root@localhost kibana]# gem -v
3.0.9

5、配置国内源

# 设置淘宝源
npm config set registry https://registry.npmmirror.com
npm config set puppeteer_download_host=https://registry.npmmirror.com
# 取消ssl证书验证
npm config set strict-ssl false

(二)yarn

1、安装

npm install -g yarn

2、验证

[root@localhost kibana]# yarn -v
1.22.21

3、配置国内源

# 设置淘宝源
yarn config set registry https://registry.npmmirror.com
# 设置浏览器驱动下载地址
yarn config set "chromedriver_cdnurl" "https://npm.taobao.org/mirrors/chromedriver"

二、安装ruby

安装ruby的话,尽量安装2.4以上的版本,因为后面安装fpm的时候对此有要求。

#1. 离线安装 rvm:
# rvm 是用来管理 ruby 的,而 ruby 的其中一个“程序”叫 rubygems,也就是我们用它装 fpm 的,手动装各种库用 gem。
[root@nginx01 ~]# curl -sSL https://github.com/rvm/rvm/tarball/stable -o rvm-stable.tar.gz
 
#2. 解压 rvm 包:
[root@nginx01 ~]# tar -xzvf rvm-stable.tar.gz
 
#3. 进入解压目录,安装 rvm:
[root@nginx01 ~]# cd rvm-rvm-6bfc921/
[root@nginx01 rvm-rvm-6bfc921]# ./install --auto-dotfiles
 
#4. 重新加载 rvm:
[root@nginx01 rvm-rvm-6bfc921]# source /usr/local/rvm/scripts/rvm
 
#5. 查看 rvm 可安装版本:
[root@nginx01 rvm-rvm-6bfc921]# rvm list known
 
#6. 选择安装 ruby 2.6.3:
# 下载安装过程比较慢,请耐心等待
[root@nginx01 rvm-rvm-6bfc921]# rvm install 2.6.3
 
#7. 设置默认使用 ruby 版本:
[root@nginx01 rvm-rvm-6bfc921]# rvm use 2.6.3 --default
Using /usr/local/rvm/gems/ruby-2.6.3
[root@nginx01 rvm-rvm-6bfc921]# ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

三、安装其他依赖包

rpm-build、fpm主要是打包成rpm\deb等类型的包使用的

yum install rpm-build gcc-c++ make git
gem install fpm -v 1.5.0

四、安装上网工具

科学上网工具,我选择的是redsock,其他的不太好用

  1. 安装libevent
yum install libevent libevent-devel -y

2、安装配置redsocks

git clone https://github.com/darkk/redsocks.git
cd redsocks/
make
echo 'base {
    log_debug = on;
    log_info = on;
    log = "file:/tmp/reddi.log";
    daemon = on;
    redirector = iptables;
}
redsocks {
    local_ip = 127.0.0.1;
    local_port = 2080;
    ip = 192.168.2.3;
    port = 7890;
    type = socks5;
}' > redsocks.conf

注意: 替换ip = 192.168.2.3;port = 7890;ip为你的宿主机的Window系统的IP,port为Windows的科学上网工具的端口,我的上网工具配置如下:

在这里插入图片描述

3、安装配置iptables

yum install -y iptables iptables-services

echo '#!/bin/bash
# Create new chain
iptables -t nat -N REDSOCKS
# Ignore LANs and some other reserved addresses.
iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
#iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN
# Anything else should be redirected to port 2080
-A REDSOCKS -d proxy_server_ip -j RETURN
iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 2080
iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDSOCKS
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDSOCKS
iptables -t nat -A OUTPUT -p tcp --dport 8503 -j REDSOCKS' > iptables-proxy-start.sh

echo 'iptables -F
iptables -X
iptables -Z
iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z
killall redsocks' > iptables-proxy-stop.sh

8503为测试的出口地址,比如代收的110,143端口。

4、启动

systemctl start iptables
./redsocks -c redsocks.conf
sh iptables-proxy-start.sh

五、编译kibana

1、拉取代码,代码很大,大概6~10G

git clone -b v7.17.5 https://github.com/elastic/kibana.git

2、开始下载依赖并编译

cd kibana
yarn kbn bootstrap
# 执行上面这一步的时候会出现各种报错,诸如下载chrome_driver失败、安装geco,可以手动安装这些报错的包,如下:
# npm install -g chromedriver
# npm install -g geckodriver
npx browserslist@latest --update-db

3、开始打包

打包之前先了解一下打包命令的可选参数:

[root@localhost kibana]# yarn build --help
yarn run v1.22.21
$ node scripts/build --all-platforms --help
usage: node scripts/build

build the Kibana distributable

options:
  --skip-archives                     Don't produce tar/zip archives #--跳过存档不生成tar/zip存档
  --skip-os-packages                  Don't produce rpm/deb/docker packages # --跳过操作系统包不要生成rpm/deb/docker包
  --all-platforms                     Produce archives for all platforms, not just this one # --所有平台为所有平台生成存档,而不仅仅是这一个
  --rpm                               Only build the rpm packages #--rpm仅构建rpm包
  --deb                               Only build the deb packages #--deb只构建deb包
  --docker-images                     Only build the Docker images #--docker镜像仅构建docker镜像
  --docker-context-use-local-artifact Use a local artifact when building the Docker context # --docker上下文使用本地工件构建docker上下文时使用本地工件
  --docker-cross-compile              Produce arm64 and amd64 Docker images #--docker交叉编译生成arm64和amd64 docker镜像
  --docker-contexts                   Only build the Docker build contexts #--docker上下文仅构建docker构建上下文
  --skip-docker-ubi                   Don't build the docker ubi image #--跳过docker ubi不要构建docker ubiimage
  --skip-docker-ubuntu                Don't build the docker ubuntu image #--跳过docker ubuntu不要构建docker ubntu镜像
  --release                           Produce a release-ready distributable #--release生成可发布的版本
  --version-qualifier                 Suffix version with a qualifier  #--版本限定符用限定符后缀版本
  --skip-node-download                Reuse existing downloads of node.js #--跳过nodejs下载,重用node.js的现有下载
  --verbose,-v                        Turn on verbose logging #--verbose,-v打开详细日志记录
  --no-debug                          Turn off debug logging #--无调试关闭调试日志记录

经过我的多次尝试,我们只需要打包成”生成可发布的版本“即可,也就是ELK官网上可下载的版本,其他版本直接跳过,命令如下:

[root@localhost kibana]# yarn build --release --skip-os-packages --skip-docker-ubi --skip-docker-ubuntu 
yarn run v1.22.21
$ node scripts/build --all-platforms --release --skip-os-packages --skip-docker-ubi --skip-docker-ubuntu
 info [  global  ] Verifying environment meets requirements
   │ succ Node.js version verified
   │ succ ✓ 0 sec

 info [  global  ] Cleaning artifacts from previous builds
   │ debg Deleting patterns: ['/usr/local/src/kibana/build',
   │        '/usr/local/src/kibana/target',
   │        '/usr/local/src/kibana/.node_binaries']
   │ debg Deleted 3 files/directories
   │ succ ✓ 9 sec

 info [  global  ] Downloading node.js builds for all platforms
   │ debg Downloading shasum values for node version 16.14.2 from https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/dist/v16.14.2/SHASUMS256.txt

......中间过程省略......
......中间过程省略......
......中间过程省略......

info [  kibana  ] Creating the archives for each platform
   │ info archiving /usr/local/src/kibana/build/default/kibana-7.17.5-linux-x86_64 to /usr/local/src/kibana/target/kibana-7.17.5-linux-x86_64.tar.gz
   │ info archiving /usr/local/src/kibana/build/default/kibana-7.17.5-linux-aarch64 to /usr/local/src/kibana/target/kibana-7.17.5-linux-aarch64.tar.gz
   │ info archiving /usr/local/src/kibana/build/default/kibana-7.17.5-darwin-x86_64 to /usr/local/src/kibana/target/kibana-7.17.5-darwin-x86_64.tar.gz
   │ info archiving /usr/local/src/kibana/build/default/kibana-7.17.5-darwin-aarch64 to /usr/local/src/kibana/target/kibana-7.17.5-darwin-aarch64.tar.gz
   │ info archiving /usr/local/src/kibana/build/default/kibana-7.17.5-windows-x86_64 to /usr/local/src/kibana/target/kibana-7.17.5-windows-x86_64.zip
   │ debg archive metrics: [{ group: 'distributable size', id: 'tar', value: 263798754 },
   │        { group: 'distributable file count', id: 'default', value: 37747 },
   │        { group: 'distributable size', id: 'tar', value: 277017617 },
   │        { group: 'distributable file count', id: 'default', value: 37747 },
   │        { group: 'distributable size', id: 'tar', value: 256355436 },
   │        { group: 'distributable file count', id: 'default', value: 37749 },
   │        { group: 'distributable size', id: 'tar', value: 192526999 },
   │        { group: 'distributable file count', id: 'default', value: 37745 },
   │        { group: 'distributable size', id: 'zip', value: 375647041 },
   │        { group: 'distributable file count', id: 'default', value: 37326 }]
   │ succ ✓ 4 min 26 sec

 info [  kibana  ] Creating Docker build contexts
   │ info Generating kibana docker build context bundle
   │ info Generating kibana-ubi8 docker build context bundle
   │ info Generating kibana-ironbank docker build context bundle
   │ info Generating kibana-cloud docker build context bundle
   │ succ ✓ 0 sec

 info [  global  ] Writing sha1sums of archives and packages in target directory
   │ succ ✓ 3 sec

Done in 1301.40s.

以上就打包完成了,耗费时间很长。

打包好的安装包如下:

[root@localhost kibana]#  ll target/
总用量 1335092
-rw-r--r-- 1 root root 192528483 33 10:56 kibana-7.17.5-darwin-aarch64.tar.gz
-rw-r--r-- 1 root root       164 33 10:57 kibana-7.17.5-darwin-aarch64.tar.gz.sha512.txt
-rw-r--r-- 1 root root 256355606 33 10:55 kibana-7.17.5-darwin-x86_64.tar.gz
-rw-r--r-- 1 root root       163 33 10:57 kibana-7.17.5-darwin-x86_64.tar.gz.sha512.txt
-rw-r--r-- 1 root root      6480 33 10:57 kibana-7.17.5-docker-build-context.tar.gz
-rw-r--r-- 1 root root       170 33 10:57 kibana-7.17.5-docker-build-context.tar.gz.sha512.txt
-rw-r--r-- 1 root root 277017459 33 10:54 kibana-7.17.5-linux-aarch64.tar.gz
-rw-r--r-- 1 root root       163 33 10:57 kibana-7.17.5-linux-aarch64.tar.gz.sha512.txt
-rw-r--r-- 1 root root 263799071 33 10:53 kibana-7.17.5-linux-x86_64.tar.gz
-rw-r--r-- 1 root root       162 33 10:57 kibana-7.17.5-linux-x86_64.tar.gz.sha512.txt
-rw-r--r-- 1 root root 377276328 33 10:57 kibana-7.17.5-windows-x86_64.zip
-rw-r--r-- 1 root root       161 33 10:57 kibana-7.17.5-windows-x86_64.zip.sha512.txt
-rw-r--r-- 1 root root      6417 33 10:57 kibana-cloud-7.17.5-docker-build-context.tar.gz
-rw-r--r-- 1 root root       176 33 10:57 kibana-cloud-7.17.5-docker-build-context.tar.gz.sha512.txt
-rw-r--r-- 1 root root      8805 33 10:57 kibana-ironbank-7.17.5-docker-build-context.tar.gz
-rw-r--r-- 1 root root       179 33 10:57 kibana-ironbank-7.17.5-docker-build-context.tar.gz.sha512.txt
-rw-r--r-- 1 root root      6525 33 10:57 kibana-ubi8-7.17.5-docker-build-context.tar.gz
-rw-r--r-- 1 root root       175 33 10:57 kibana-ubi8-7.17.5-docker-build-context.tar.gz.sha512.txt
-rw-r--r-- 1 root root     65666 33 10:48 optimizer_bundle_metrics.json

月 3 10:57 kibana-ironbank-7.17.5-docker-build-context.tar.gz.sha512.txt
-rw-r–r-- 1 root root 6525 3月 3 10:57 kibana-ubi8-7.17.5-docker-build-context.tar.gz
-rw-r–r-- 1 root root 175 3月 3 10:57 kibana-ubi8-7.17.5-docker-build-context.tar.gz.sha512.txt
-rw-r–r-- 1 root root 65666 3月 3 10:48 optimizer_bundle_metrics.json


如果需要制作docker容器镜像,还需要安装docker命令。