1,CentOS 7.5 安裝 Python3.7
1、安裝開發者工具
yum -y groupinstall "Development Tools"
2、安裝Python編譯依賴包
yum -y install openssl-devel zlib-devel bzip2-devel sqlite-devel readline-devel libffi-devel systemtap-sdt-devel
3、下載安裝包
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
4、解壓&編譯
tar zvxf Python-3.7.0.tgz
cd Python-3.7.0
./configure --prefix=/usr/local/python3.7 --enable-optimizations
make && make install
# 編譯完成后,創建軟鏈接文件到執行文件路徑:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
# 我們可以清除之前編譯的可執行文件及配置文件 && 清除所有生成的文件:
make clean && make distclean
5、配置環境變量
文件: /etc/profile.d/python37.sh
if [ -z ${PYTHON37_HOME} ]; then
export PYTHON37_HOME=/usr/local/python3.7
export PATH=${PYTHON37_HOME}/bin:${PATH}
fi
6、加載環境變量
source /etc/profile.d/python37.sh
7、測試
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版本過低,於是用源碼編譯的方式進行升級.
安裝流程
1、第一步卸載原有的git。
yum remove git
2、安裝相關依賴
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc yum install gcc perl-ExtUtils-MakeMaker
3、安裝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中的內容
問題解決
正常的流程就是按照上面的流程進行安裝即可,下面總結一些在安裝過程中遇到的幾個問題.
1、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
2、在安裝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編譯的時候發生報錯:
- [root@localhost git-2.4.5]# make
- SUBDIR perl
- /usr/bin/perl Makefile.PL PREFIX='/usr/local/git' INSTALL_BASE='' --localedir='/usr/local/git/share/locale'
- 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.
- BEGIN failed--compilation aborted at Makefile.PL line 3.
- make[1]: *** [perl.mak] Error 2
- make: *** [perl/perl.mak] Error 2
解決辦法如下:
yum install perl-ExtUtils-Embed -y
安裝完以后重新編譯解決問題
如果有其他的問題,可以參考公眾干號:浪子編程走四方
作者:一介布衣q
鏈接:https://www.imooc.com/article/275738
來源:慕課網
本文原創發布於慕課網 ,轉載請注明出處,謝謝合作
——————————————————————————————————————————
4,使用ESRally壓測ElasticSearch性能
1 |
------------------------------------------------------ |
在部署完一套ES集群之后,我們肯定想知道這套集群性能如何?是否可以支撐未來業務發展?存不存在性能上的瓶頸?要想有依據的回答這些問題,我們需要通過壓力測試結果中找答案。
介紹
Rally是Elasticsearch的基准測試框架,由官方提供維護。
安裝
- 安裝Python3.5及以上版本,系統默認可能是2.x版本,如果需要升級請參考《在CentOS7上安裝Python3》。
- 安裝git1.9及以上版本
- 安裝esrally
pip3 install esrally
- 配置esrally
esrally configure
,執行此命令后會在當前用戶根目錄下生成.rally
目錄,可以ll ~/.rally
這樣來確認。
使用
快速開始
如果想測試當前機器上某個版本單點ES性能,可以像下面這樣:
1 |
esrally --distribution-version=6.5.3 |
當執行上面的命令之后會自動下載對應es版本軟件,並在本地啟動,接着執行測試。這個過程在rally中被稱為比賽,而賽道是用默認的,即geonames。
測試遠程集群
上面的示例不能測試存在的es集群,下面介紹使用方法:
-
指定跑道和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
備注: esrally list tracks
命令可以查看可用跑道(–track)
可以使用 --report-file=/path/to/your/report.md
將此報告也保存到文件中,並使用 --report-format=csv
將其另存為CSV。
修改默認跑道參數
如果直接在默認跑道上修改,會被還原,所以只能通過增加跑道的方式。
-
在
.rally/benchmarks/tracks
下面創建新的賽道,比如custom
。 -
在
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
} -
在啟動時指定跑道:
esrally --track=custom ....
,例如:1
2
3
4
5esrally --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