LoginSignup
0
0

More than 3 years have passed since last update.

CentOS6.10にlocustのインストール(メモ)

Posted at

概要

サーバの負荷テストにjmeterの代わりにlocustというツールを利用できるのでそれについて勉強中です。このツールにおいてpythonの言語でテスト内容を作成します。

ソフトウェアのバージョン

locust: 1.4.2(python3.6以上が必要)
python: 3.7
pip: 21.0
setuptools: 52.0.0

インストール手順

yumの設定

2020/11/30にcentos6のサポートが終了したため、yumを使用する時に下記のエラーが発生しました。
YUMREPO ERROR: ALL MIRROR URLS ARE NOT USING FTP, HTTP[S] OR FILE

・「解決方法」
1)yumのreposのmirrorlistをコメントアウトし、新しいbaseurlを追加します。

/etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=https://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=https://vault.centos.org/6.10/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=https://vault.centos.org/6.10/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

2) ファイルの修正が完了したら、下記のコマンドを実行します。

# yum clean all

python3.7のインストール(時間がかかります)

下記の方のサイトを参考し、python3.7のインストールを行います。
https://benad.me/blog/2018/07/17/python-3.7-on-centos-6/

# yum install -y xz
# yum groupinstall -y 'Development Tools'
# cd /tmp
# curl -LO 'https://www.openssl.org/source/openssl-1.1.0h.tar.gz'
# tar -xf openssl-1.1.0h.tar.gz
# cd openssl-1.1.0h
# ./config shared --prefix=/usr/local/openssl11 --openssldir=/usr/local/openssl11 && make && make install
# cd ..
# curl -LO 'https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz'
# tar -xf Python-3.7.0.tar.xz
# cd Python-3.7.0
In Modules/Setup.dist, edit the following, making sure you remove the leading pound characters:
SSL=/usr/local/openssl11
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
# yum install -y libffi-devel bzip2-devel ncurses-devel gdbm-devel xz-devel sqlite-devel readline-devel zlib-devel libuuid-devel
# LDFLAGS="-Wl,-rpath=/usr/local/openssl11/lib" ./configure --prefix=/usr/local/python37 --with-openssl=/usr/local/openssl11 --with-system-ffi && make && make install
# ln -s /usr/local/python37/bin/*3.7* /usr/local/bin

pipとsetuptoolsのバージョンアップ

1) setuptoolsのバージョンアップ
下記のコマンドを実行します。

# pip3.7 install setuptools==52.0.0

2) pipのバージョンアップ

# pip3.7 install pip==21.0

locustのインストール

下記のコマンドを実行します。

# pip3.7 install locust==1.4.2

locustのスクリプトの作成

1) 下記のパスにlocustというファイルを作成します。

# cd /usr/local/bin/
# touch locust

2) locustのファイル内に下記の内容を入力します。

#!/usr/local/bin/python3.7
# -*- coding: utf-8 -*-
import re
import sys
from locust.main import main
if __name__ == '__main__':
  sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
  sys.exit(main())

3) locustのファイルに実行権限を付与します。

# chmod +x locust

動作確認

1) locustfile.pyを作成します。

locustfile.py
from locust import HttpUser, between, task

class WebsiteUser(HttpUser):
  wait_time = between(5,15)

  @task
  def index(self):
    self.client.get("/")

2) locustを起動します。
作成したlocust.pyのディレクトリに下記のコマンドを実行します。
※locustのweb画面のホストIPを--web-hostで指定できます。指定がなければ、localhostがデフォルトとなります。

$ locust

3) locustのweb画面にアクセスします。
http://localhost:8089
example.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0