2018年10月15日月曜日

VagrantでsysbenchとPostgreSQL10をインストールした仮想マシン(Debian Stretch/9.5)を構築する

sysbenchでホストマシンやデータベースのベンチマークを行うことができます。

〇構築方法
以下のVagrantfileを使用して、sysbenchとPostgreSQL10がインストールされた仮想マシン(Debian Stretch/9.5)を構築します。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.5"
  config.vm.hostname = "db95sysbenchpg"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db95sysbenchpg"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.107", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.107", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
timedatectl set-timezone Asia/Tokyo
apt-get update
timedatectl set-timezone Asia/Tokyo
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install postgresql
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
apt-get -y install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
apt-get upgrade
apt-get -y install postgresql-10

echo "listen_addresses='*'" >> /etc/postgresql/10/main/postgresql.conf

#sed -i 's/host.*all.*all.*127.0.0.1/#host    all             all             127.0.0.1/g' /etc/postgresql/10/main/pg_hba.conf

echo "host    all         all         127.0.0.1/32          password" >> /etc/postgresql/10/main/pg_hba.conf
echo "host    all         all         192.168.1.0/24          password" >> /etc/postgresql/10/main/pg_hba.conf
echo "host    all         all         192.168.55.0/24          password" >> /etc/postgresql/10/main/pg_hba.conf

su - postgres << EOF
createdb -T template0 --locale=ja_JP.UTF-8 --encoding=UTF8 sysbench
psql -c "
alter user postgres with password 'postgres';
create user sysbench with password 'sysbench';
grant all privileges on database sysbench to sysbench;
"
EOF
echo "postgres:postgres" | chpasswd


# install and execute sysbench.
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
apt-get -y install sysbench
sysbench cpu run --threads=2
sysbench memory run --threads=2
sysbench fileio run --file-test-mode=seqwr --threads=2
sysbench fileio run --file-test-mode=rndwr --threads=2

sysbench /usr/share/sysbench/oltp_read_write.lua prepare --db-driver=pgsql --pgsql-host=localhost --pgsql-port=5432 --pgsql-user=sysbench --pgsql-password=sysbench --pgsql-db=sysbench
sysbench /usr/share/sysbench/oltp_read_write.lua run --db-driver=pgsql --pgsql-host=localhost --pgsql-port=5432 --pgsql-user=sysbench --pgsql-password=sysbench --pgsql-db=sysbench --threads=2

SHELL
end


○関連情報
・sysbenchに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿