ESRally壓測ElasticSearch性能 CentOS 7.5 安裝 Python3.7

1,CentOS 7.5 安裝 Python3.7 

一、安裝開發者工具php

yum -y groupinstall "Development Tools"
二、安裝Python編譯依賴包html

yum -y install openssl-devel zlib-devel bzip2-devel sqlite-devel readline-devel libffi-devel systemtap-sdt-devel
三、下載安裝包node

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
四、解壓&編譯python

tar zvxf Python-3.7.0.tgz
cd Python-3.7.0
./configure --prefix=/usr/local/python3.7 --enable-optimizations
make && make installgit

# 編譯完成後,建立軟連接文件到執行文件路徑:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
# 咱們能夠清除以前編譯的可執行文件及配置文件 && 清除全部生成的文件:
make clean && make distcleangithub


五、配置環境變量sql

文件: /etc/profile.d/python37.shdocker

if [ -z ${PYTHON37_HOME} ]; then
export PYTHON37_HOME=/usr/local/python3.7
export PATH=${PYTHON37_HOME}/bin:${PATH}
fi
六、加載環境變量shell

source /etc/profile.d/python37.sh
七、測試編程

python3 -c "import sys; print(sys.version)"

bug: 使用pip 命令失敗
2.1 錯誤信息
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting virtualenv
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not find a version that satisfies the requirement virtualenv (from versions: )
No matching distribution found for virtualenv
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

2.2 緣由
系統版本centos6.5,其中openssl的版本爲OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7須要的openssl的版本爲1.0.2或者1.1.x,須要對openssl進行升級,並從新編譯python3.7.0。yum 安裝的openssl 版本都比較低。

2.3 升級openssl
# 1.下賊openssl
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -zxvf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a
# 2.編譯安裝
./config --prefix=/usr/local/openssl no-zlib #不須要zlib
make
make install
# 3.備份原配置
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak
# 4.新版配置
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
# 5.修改系統配置
## 寫入openssl庫文件的搜索路徑
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
## 使修改後的/etc/ld.so.conf生效 
ldconfig -v
# 6.查看openssl版本
openssl version

openssl version 提示:

 /usr/local/openssl/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

假如你的libssl.so.1.1 文件在/usr/local/openssl/lib/下面,能夠這樣作

ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1

ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

再從新裝3.7
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make && make install

 

 

Fatal Python error: initfsencoding: Unable to get the locale encoding
LookupError: unknown encoding: GB18030

設置字符集:
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN.UTF-8
以後就解決了
裝好後,unset下
遇到奇葩找不到源的問題 No matching distribution found for esrally:
用國內豆瓣代理
 pip3 install  --trusted-host  http://pypi.douban.com/simple/   esrally

 


 2,git2 安裝

centos7系統默認的git安裝版本是1.8,可是在項目構建中發現git版本太低,因而用源碼編譯的方式進行升級.

 

安裝流程

一、第一步卸載原有的git。

yum remove git

二、安裝相關依賴

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc yum install gcc perl-ExtUtils-MakeMaker 

三、安裝git

wget https://github.com/git/git/archive/v2.10.5.tar.gz(這個沒有configure,沒法加載 更新爲openssl 1.1的版本)
 wget https://www.kernel.org/pub/software/scm/git/git-2.11.1.tar.gz

tar -xzvf v2.10.5.tar.gz
cd git-2.10.5
編譯安裝git(若是更新了openssl到1.1版本,須要指定一下:--with-openssl=/usr/local/openssl)

./configure --prefix=/usr/local/git --with-openssl=/usr/local/openssl

sudo make && make install

配置環境變量

echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile && source /etc/profile

查看git版本

git --version

安裝完成:
生成ssh key :
#ssh-keygen -t rsa -C 「xxx@gmail.com」
登陸Github點擊Edit your profile->SSH keys,添加./.ssh/id_rsa.pub中的內容

問題解決

正常的流程就是按照上面的流程進行安裝便可,下面總結一些在安裝過程當中遇到的幾個問題.
一、make prefix=/usr/local/git all進行編譯的時候提示以下錯誤

LINK git-credential-store libgit.a(utf8.o): In function `reencode_string_iconv': /usr/src/git-2.8.3/utf8.c:463: undefined reference to `libiconv' libgit.a(utf8.o): In function `reencode_string_len': /usr/src/git-2.8.3/utf8.c:502: undefined reference to `libiconv_open' /usr/src/git-2.8.3/utf8.c:521: undefined reference to `libiconv_close' /usr/src/git-2.8.3/utf8.c:515: undefined reference to `libiconv_open' collect2: ld returned 1 exit status make: *** [git-credential-store] Error 1 

這個問題主要是系統缺乏libiconv庫致使的。根據上面提供的連接,下載libiconv便可。

cd /usr/local/src wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar -zxvf libiconv-1.14.tar.gz cd libiconv-1.14 配置 ./configure --prefix=/usr/local/libiconv 編譯 make 安裝 make install 創建軟鏈接 ln -s /usr/local/lib/libiconv.so /usr/lib ln -s /usr/local/lib/libiconv.so.2 /usr/lib 

這時候還libiconv庫已經安裝完成,下面進入咱們的git安裝目錄,按照下面的方式進行安裝

make configure
./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv 編譯 make 安裝 make install 加入環境變量 export PATH=$PATH:/usr/local/bin/git 檢測版本號 git --version 

二、在安裝libiconv時會遇到./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)的錯誤提示,進行下面的操做便可解決.

進入錯誤文件路徑
cd libiconv-1.14/srclib 編輯文件stdio.in.h找到698行的樣子,內容是_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); 將這一行註釋掉(注意註釋必定要用/**/來進行註釋),替換爲下面的內容 #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif

安裝git編譯的時候發生報錯:

  1. [root@localhost git-2.4.5]# make
  2. SUBDIR perl
  3. /usr/bin/perl Makefile.PL PREFIX='/usr/local/git' INSTALL_BASE='' --localedir='/usr/local/git/share/locale'
  4. Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
  5. BEGIN failed--compilation aborted at Makefile.PL line 3.
  6. make[1]: *** [perl.mak] Error 2
  7. make: *** [perl/perl.mak] Error 2

解決辦法以下:
yum install perl-ExtUtils-Embed -y
安裝完之後從新編譯解決問題

若是有其餘的問題,能夠參考公衆乾號:浪子編程走四方


做者:一介布衣q
連接:https://www.imooc.com/article/275738
來源:慕課網
本文原創發佈於慕課網 ,轉載請註明出處,謝謝合做

——————————————————————————————————————————

4,使用ESRally壓測ElasticSearch性能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
------------------------------------------------------
_______ __ _____
/ ____(_)___ ____ _/ / / ___/_________ ________
/ /_ / / __ \/ __ `/ / \__ \/ ___/ __ \/ ___/ _ \
/ __/ / / / / / /_/ / / ___/ / /__/ /_/ / / / __/
/_/ /_/_/ /_/\__,_/_/ /____/\___/\____/_/ \___/
------------------------------------------------------

| Metric | Task | Value | Unit |
|-------------------------------:|---------------------:|----------:|-------:|
| Total indexing time | | 28.0997 | min |
| Total merge time | | 6.84378 | min |
| Total refresh time | | 3.06045 | min |
| Total flush time | | 0.106517 | min |
| Total merge throttle time | | 1.28193 | min |
| Median CPU usage | | 471.6 | % |
| Total Young Gen GC | | 16.237 | s |
| Total Old Gen GC | | 1.796 | s |
| Index size | | 2.60124 | GB |
| Total written | | 11.8144 | GB |
| Heap used for segments | | 14.7326 | MB |
| Heap used for doc values | | 0.115917 | MB |
| Heap used for terms | | 13.3203 | MB |
| Heap used for norms | | 0.0734253 | MB |
| Heap used for points | | 0.5793 | MB |
| Heap used for stored fields | | 0.643608 | MB |
| Segment count | | 97 | |
| Min Throughput | index-append | 31925.2 | docs/s |
| Median Throughput | index-append | 39137.5 | docs/s |
| Max Throughput | index-append | 39633.6 | docs/s |
| 50.0th percentile latency | index-append | 872.513 | ms |
| 90.0th percentile latency | index-append | 1457.13 | ms |
| 99.0th percentile latency | index-append | 1874.89 | ms |
| 100th percentile latency | index-append | 2711.71 | ms |
| 50.0th percentile service time | index-append | 872.513 | ms |
| 90.0th percentile service time | index-append | 1457.13 | ms |
| 99.0th percentile service time | index-append | 1874.89 | ms |
| 100th percentile service time | index-append | 2711.71 | ms |
| ... | ... | ... | ... |
| ... | ... | ... | ... |
| Min Throughput | painless_dynamic | 2.53292 | ops/s |
| Median Throughput | painless_dynamic | 2.53813 | ops/s |
| Max Throughput | painless_dynamic | 2.54401 | ops/s |
| 50.0th percentile latency | painless_dynamic | 172208 | ms |
| 90.0th percentile latency | painless_dynamic | 310401 | ms |
| 99.0th percentile latency | painless_dynamic | 341341 | ms |
| 99.9th percentile latency | painless_dynamic | 344404 | ms |
| 100th percentile latency | painless_dynamic | 344754 | ms |
| 50.0th percentile service time | painless_dynamic | 393.02 | ms |
| 90.0th percentile service time | painless_dynamic | 407.579 | ms |
| 99.0th percentile service time | painless_dynamic | 430.806 | ms |
| 99.9th percentile service time | painless_dynamic | 457.352 | ms |
| 100th percentile service time | painless_dynamic | 459.474 | ms |

----------------------------------
[INFO] SUCCESS (took 2634 seconds)
----------------------------------

在部署完一套ES集羣以後,咱們確定想知道這套集羣性能如何?是否能夠支撐將來業務發展?存不存在性能上的瓶頸?要想有依據的回答這些問題,咱們須要經過壓力測試結果中找答案。

介紹

Rally是Elasticsearch的基準測試框架,由官方提供維護。

安裝

  1. 安裝Python3.5及以上版本,系統默承認能是2.x版本,若是須要升級請參考《在CentOS7上安裝Python3》。
  2. 安裝git1.9及以上版本
  3. 安裝esrally pip3 install esrally
  4. 配置esrally esrally configure,執行此命令後會在當前用戶根目錄下生成 .rally 目錄,能夠 ll ~/.rally這樣來確認。

使用

快速開始

若是想測試當前機器上某個版本單點ES性能,能夠像下面這樣:

1
2
3
4
esrally --distribution-version=6.5.3

# 一樣的若是你想測試其它版本
esrally --distribution-version=6.8.1   --car="4gheap" 

 

當執行上面的命令以後會自動下載對應es版本軟件,並在本地啓動,接着執行測試。這個過程在rally中被稱爲比賽,而賽道是用默認的,即geonames

 

測試遠程集羣

上面的示例不能測試存在的es集羣,下面介紹使用方法:

  1. 指定跑道和ES集羣地址後就能夠執行測試。

esrally --pipeline=benchmark-only \
--track=http_logs \
--target-hosts=192.168.1.100:9200,192.168.1.101:9200,192.168.1.102:9200 \
--report-file=/tmp/report_http_logs.md
--track-params="bulk_indexing_clients:96"
 
 --include-tasks="index-append"
--challenge=append-fast-with-no-conflicts (只測試寫)

--report-format=csv
備註:  命令能夠查看可用跑道(–track)

可使用  將此報告也保存到文件中,並使用 將其另存爲CSV。

esrally list tracks--report-file=/path/to/your/report.md--report-format=csv

修改默認跑道參數

若是直接在默認跑道上修改,會被還原,因此只能經過增長跑道的方式。

  1. 在 .rally/benchmarks/tracks 下面建立新的賽道,好比 custom

  2. 在 custom/http_logs/challenges/default.json 文件中調整賽道的配置並保存,例以下面修改default對應的操做,由10個客戶端發起,每一個用戶端發出100次操做。

    1
    2
    3
    4
    5
    6
    7
    {
    "operation": "default",
    "clients": 10,
    "warmup-iterations": 500,
    "iterations": 100,
    "target-throughput": 100
    }
  3. 在啓動時指定跑道:esrally --track=custom ....,例如:

    1
    2
    3
    4
    5
    esrally --pipeline=benchmark-only \
    --track=custom \
    --track=http_logs \
    --target-hosts=192.168.1.100:9200,192.168.1.101:9200,192.168.1.102:9200 \
    --report-file=/tmp/report_http_logs.md

 

參考文獻:

  • https://esrally.readthedocs.io/en/stable/index.html
  • https://github.com/elastic/rally
  • 比較全的壓測介紹:https://www.jianshu.com/p/c89975b50447
  • 使用docker 運行 esrally(包含離線數據集):https://www.jianshu.com/p/3a019c135e2a
  • 測試參數解釋:https://www.jianshu.com/p/979f548c233e
  • 討論爲何elasticsearch沒有被壓滿:https://discuss.elastic.co/t/es-benchmark-using-rally-to-stress-a-2-node-setup/150020/6
  • 有壓測結果對比:https://www.jianshu.com/p/e7de3b24f505

數據集:
國內下載慢,能夠先執行一遍
esrally --distribution-version=6.5.3 --track=geonames
這樣即便下載測試數據失敗,可是目錄結構都生成好了。能夠自行下載bz文件,在

http://benchmarks.elasticsearch.org.s3.amazonaws.com/corpora/geonames/documents.json.bz2
存成默認定義的:
documents-2.json.bz2
documents-2.json.offset
而後直接拷貝過去便可:~/.rally/benchmarks/data/geonames

esrally list tracks

This will show the following list:

Name        Description Documents Compressed Size Uncompressed Size Default Challenge All Challenges ---------- ------------------------------------------------- ----------- ----------------- ------------------- ----------------------- --------------------------- geonames POIs from Geonames 11396505 252.4 MB 3.3 GB append-no-conflicts append-no-conflicts,appe... geopoint Point coordinates from PlanetOSM 60844404 481.9 MB 2.3 GB append-no-conflicts append-no-conflicts,appe... http_logs HTTP server log data 247249096 1.2 GB 31.1 GB append-no-conflicts append-no-conflicts,appe... nested StackOverflow Q&A stored as nested docs 11203029 663.1 MB 3.4 GB nested-search-challenge nested-search-challenge,... noaa Global daily weather measurements from NOAA 33659481 947.3 MB 9.0 GB append-no-conflicts append-no-conflicts,appe... nyc_taxis Taxi rides in New York in 2015 165346692 4.5 GB 74.3 GB append-no-conflicts append-no-conflicts,appe... percolator Percolator benchmark based on AOL queries 2000000 102.7 kB 104.9 MB append-no-conflicts append-no-conflicts,appe... pmc Full text benchmark with academic papers from PMC 574199 5.5 GB 21.7 GB 

這個地址裏面 https://github.com/elastic/rally-tracks/tree/master/,進入子目錄有各個數據集可配置的參數:

如http_logs:

Parameters (--track-params="bulk_indexing_clients:96"

This track allows to overwrite the following parameters with Rally 0.8.0+ using --track-params:

  • bulk_size (default: 5000)
  • bulk_indexing_clients (default: 8): Number of clients that issue bulk indexing requests.

 

5,本身定義壓測:

參考:https://esrally.readthedocs.io/en/latest/adding_tracks.html

主要步驟:

1,建立目錄:~/rally-tracks/tutorial

2,手動下載 geonames 壓測數據: http://download.geonames.org/export/dump/allCountries.zip 。它裏面是用tab分開的文本文件。須要轉成json格式。

用這段python代碼轉:

import json

cols = (("geonameid", "int", True),
        ("name", "string", True),
        ("asciiname", "string", False),
        ("alternatenames", "string", False),
        ("latitude", "double", True),
        ("longitude", "double", True),
        ("feature_class", "string", False),
        ("feature_code", "string", False),
        ("country_code", "string", True),
        ("cc2", "string", False),
        ("admin1_code", "string", False),
        ("admin2_code", "string", False),
        ("admin3_code", "string", False),
        ("admin4_code", "string", False),
        ("population", "long", True),
        ("elevation", "int", False),
        ("dem", "string", False),
        ("timezone", "string", False))


def main():
    with open("allCountries.txt", "rt", encoding="UTF-8") as f:
        for line in f:
            tup = line.strip().split("\t")
            record = {}
            for i in range(len(cols)):
                name, type, include = cols[i]
                if tup[i] != "" and include:
                    if type in ("int", "long"):
                        record[name] = int(tup[i])
                    elif type == "double":
                        record[name] = float(tup[i])
                    elif type == "string":
                        record[name] = tup[i]
            print(json.dumps(record, ensure_ascii=False))


if __name__ == "__main__":
    main()

存到剛纔~/rally-tracks/tutorial目錄下,python3 toJSON.py documents.json

3,對於7.0如下的es,保持這個成index.json

{
  "settings": {
    "index.number_of_replicas": 0
  },
  "mappings": {
    "docs": {
      "dynamic": "strict",
      "properties": {
        "geonameid": {
          "type": "long"
        },
        "name": {
          "type": "text"
        },
        "latitude": {
          "type": "double"
        },
        "longitude": {
          "type": "double"
        },
        "country_code": {
          "type": "text"
        },
        "population": {
          "type": "long"
        }
      }
    }
  }
}

5,再保存一個track.json

{
  "version": 2,
  "description": "Tutorial benchmark for Rally",
  "indices": [
    {
      "name": "geonames",
      "body": "index.json",
      "types": [ "docs" ]
    }
  ],
  "corpora": [
    {
      "name": "rally-tutorial",
      "documents": [
        {
          "source-file": "documents.json",
          "document-count": 11658903,
          "uncompressed-bytes": 1544799789
        }
      ]
    }
  ],
  "schedule": [
    {
      "operation": {
        "operation-type": "delete-index"
      }
    },
    {
      "operation": {
        "operation-type": "create-index"
      }
    },
    {
      "operation": {
        "operation-type": "cluster-health",
        "request-params": {
          "wait_for_status": "green"
        }
      }
    },
    {
      "operation": {
        "operation-type": "bulk",
        "bulk-size": 5000
      },
      "warmup-time-period": 120,
      "clients": 8
    },
    {
      "operation": {
        "operation-type": "force-merge"
      }
    },
    {
      "operation": {
        "name": "query-match-all",
        "operation-type": "search",
        "body": {
          "query": {
            "match_all": {}
          }
        }
      },
      "clients": 8,
      "warmup-iterations": 1000,
      "iterations": 1000,
      "target-throughput": 100
    }
  ]
}

其中documents 屬性裏面的字段值是這麼來的:

wc -l documents.json json個數

stat -f "%z" documents.json 文件大小

7.0之後版本要去掉types 。

6,檢查創建成功沒有:esrally list tracks --track-path=~/rally-tracks/tutorial

7,執行本身的track:esrally --distribution-version=6.0.0 --track-path=~/rally-tracks/tutorial

--test-mode 來檢測配置文件對否。

這個來生成1000條數據:head -n 1000 documents.json documents-1k.json

相關文章
相關標籤/搜索