「CockroachDB」:修訂間差異
跳至導覽
跳至搜尋
(未顯示同一使用者於中間所作的 18 次修訂) | |||
第1行: | 第1行: | ||
'''CockroachDB'''是一個分散式的資料庫軟體,目標是與[[PostgreSQL]]相容但可以提供橫向擴充的能力。 | '''CockroachDB'''是一個分散式的資料庫軟體,目標是與[[PostgreSQL]]相容但可以提供橫向擴充的能力。 | ||
== 安裝 == | |||
CockroachDB的設計是單一執行檔,沒有複雜的安裝包,所以下載複製到目錄裡即可: | |||
<syntaxhighlight lang="bash"> | |||
cd /tmp | |||
wget -qO- https://binaries.cockroachdb.com/cockroach-v2.1.3.linux-amd64.tgz | tar xvz | |||
cp -i cockroach-v2.1.3.linux-amd64/cockroach /usr/local/bin | |||
</syntaxhighlight> | |||
== 設定 == | |||
設定分成兩塊,一塊是初始第一台機器: | |||
<syntaxhighlight lang="bash"> | |||
cockroach start --background --insecure --listen-addr=0.0.0.0 --advertise-addr=$(ifconfig eth0 | grep inet | awk '{print $2}') | |||
</syntaxhighlight> | |||
另外一塊是後續的機器,多了<code>--join</code>要設定: | |||
<syntaxhighlight lang="bash"> | |||
cockroach start --background --insecure --listen-addr=0.0.0.0 --join=192.168.x.x --advertise-addr=$(ifconfig eth0 | grep inet | awk '{print $2}') | |||
</syntaxhighlight> | |||
可以用以下指令確認機器都有連上cluster: | |||
<syntaxhighlight lang="bash"> | |||
cockroach node ls --insecure | |||
</syntaxhighlight> | |||
然後用PostgreSQL的client連上測試: | |||
<syntaxhighlight lang="bash"> | |||
psql -h 192.168.x.x -p 26257 -U root | |||
</syntaxhighlight> | |||
另外可能要修改<code>replica</code>的數量(預設是5): | |||
<syntaxhighlight lang="sql"> | |||
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 3; | |||
</syntaxhighlight> | |||
== 測試 == | == 測試 == | ||
使用一台<code>c5.2xlarge</code>與五台<code>r5.large</code>架設[[Kubernetes]]後在裡面建立六個Pod測試。 | |||
=== Kubernetes === | === Kubernetes === | ||
使用[[Kubernetes]]時的設定檔如下: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
第11行: | 第55行: | ||
kind: StatefulSet | kind: StatefulSet | ||
metadata: | metadata: | ||
name: poc- | name: poc-c5 | ||
spec: | spec: | ||
replicas: | replicas: 1 | ||
serviceName: cockroachdb- | serviceName: cockroachdb-c5 | ||
selector: | selector: | ||
matchLabels: | matchLabels: | ||
app: cockroachdb- | app: cockroachdb-c5 | ||
template: | template: | ||
metadata: | metadata: | ||
labels: | labels: | ||
app: cockroachdb- | app: cockroachdb-c5 | ||
spec: | spec: | ||
containers: | containers: | ||
- name: cockroachdb- | - name: cockroachdb-c5 | ||
image: ubuntu:18.04 | image: ubuntu:18.04 | ||
command: ["/bin/sh", "-c"] | command: ["/bin/sh", "-c"] | ||
第31行: | 第75行: | ||
sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list; | sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list; | ||
apt update; | apt update; | ||
apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata vim-nox wget; | apt install -y ant default-jdk git iproute2 iputils-ping locales mtr-tiny net-tools openjdk-8-jdk postgresql-client sysbench tzdata vim-nox wget; | ||
update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java; | |||
locale-gen en_US.UTF-8; | locale-gen en_US.UTF-8; | ||
cd / | cd /root; | ||
git clone https://github.com/oltpbenchmark/oltpbench.git; | |||
cd oltpbench; | |||
sed -i -e 's/^ALTER TABLE/-- ALTER TABLE/' src/com/oltpbenchmark/benchmarks/tpcc/ddls/tpcc-postgres-ddl.sql; | |||
ant clean; | |||
ant; | |||
cp config/tpcc_config_postgres.xml config/tpcc.xml; | |||
sed -i -e 's/localhost:5432/cockroachdb-port.default.svc.cluster.local:26257/' config/tpcc.xml; | |||
sed -i -e 's/<username>tpcc/<username>root/' config/tpcc.xml; | |||
sed -i -e 's/<password>tpcc/<password>' config/tpcc.xml; | |||
sed -i -e 's/TRANSACTION_READ_COMMITTED/TRANSACTION_SERIALIZABLE/' config/tpcc.xml; | |||
sleep 3153600000 | sleep 3153600000 | ||
env: | env: | ||
- name: LC_ALL | - name: LC_ALL | ||
value: en_US.UTF-8 | value: en_US.UTF-8 | ||
nodeSelector: | nodeSelector: | ||
instancetype: | instancetype: c5 | ||
--- | --- | ||
apiVersion: apps/v1 | apiVersion: apps/v1 | ||
kind: StatefulSet | kind: StatefulSet | ||
metadata: | metadata: | ||
name: poc- | name: poc-r5 | ||
spec: | spec: | ||
replicas: | replicas: 5 | ||
serviceName: cockroachdb- | serviceName: cockroachdb-r5 | ||
selector: | selector: | ||
matchLabels: | matchLabels: | ||
app: cockroachdb- | app: cockroachdb-r5 | ||
template: | template: | ||
metadata: | metadata: | ||
labels: | labels: | ||
app: cockroachdb- | app: cockroachdb-r5 | ||
spec: | spec: | ||
containers: | containers: | ||
- name: cockroachdb- | - name: cockroachdb-r5 | ||
image: ubuntu:18.04 | image: ubuntu:18.04 | ||
command: ["/bin/sh", "-c"] | command: ["/bin/sh", "-c"] | ||
第69行: | 第119行: | ||
sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list; | sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list; | ||
apt update; | apt update; | ||
apt install -y | apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata vim-nox wget; | ||
locale-gen en_US.UTF-8; | locale-gen en_US.UTF-8; | ||
cd / | cd /tmp; | ||
wget -qO- https://binaries.cockroachdb.com/cockroach-v2.1.3.linux-amd64.tgz | tar xvz; | |||
cp -i cockroach-v2.1.3.linux-amd64/cockroach /usr/local/bin; | |||
sleep 3153600000 | sleep 3153600000 | ||
env: | env: | ||
- name: LC_ALL | - name: LC_ALL | ||
value: en_US.UTF-8 | value: en_US.UTF-8 | ||
nodeSelector: | nodeSelector: | ||
instancetype: c5 | instancetype: r5 | ||
--- | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: cockroachdb-port | |||
spec: | |||
selector: | |||
app: cockroachdb-r5 | |||
ports: | |||
- protocol: TCP | |||
port: 26257 | |||
targetPort: 26257 | |||
</syntaxhighlight> | |||
後續的測試都需要先連入<code>poc-c5-0</code>的terminal: | |||
<syntaxhighlight lang="bash"> | |||
kubectl exec -it poc-c5-0 /bin/bash | |||
</syntaxhighlight> | |||
=== oltpbenchmark === | |||
{{See also|oltpbenchmark}} | |||
這邊是拿[[oltpbenchmark]]測試。 | |||
==== 指令 ==== | |||
<syntaxhighlight lang="sql"> | |||
CREATE DATABASE tpcc; | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash"> | |||
cd /root/oltpbench | |||
./oltpbenchmark -b tpcc -c config/tpcc.xml --create=true --load=true | |||
./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true | |||
</syntaxhighlight> | |||
=== Sysbench === | |||
{{See also|sysbench}} | |||
這邊是拿[[sysbench]]測試。 | |||
==== 指令 ==== | |||
<syntaxhighlight lang="sql"> | |||
CREATE DATABASE sbtest; | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash"> | |||
sysbench --db-driver=pgsql --pgsql-host=cockroachdb-port.default.svc.cluster.local --pgsql-port=26257 --pgsql-user=root --pgsql-password= --time=0 --events=10000000 --report-interval=1 --threads=128 /usr/share/sysbench/oltp_insert.lua prepare | |||
sysbench --db-driver=pgsql --pgsql-host=cockroachdb-port.default.svc.cluster.local --pgsql-port=26257 --pgsql-user=root --pgsql-password= --time=0 --events=10000000 --report-interval=1 --threads=128 /usr/share/sysbench/oltp_insert.lua run | |||
</syntaxhighlight> | </syntaxhighlight> | ||
於 2019年1月7日 (一) 05:47 的最新修訂
CockroachDB是一個分散式的資料庫軟體,目標是與PostgreSQL相容但可以提供橫向擴充的能力。
安裝
CockroachDB的設計是單一執行檔,沒有複雜的安裝包,所以下載複製到目錄裡即可:
cd /tmp
wget -qO- https://binaries.cockroachdb.com/cockroach-v2.1.3.linux-amd64.tgz | tar xvz
cp -i cockroach-v2.1.3.linux-amd64/cockroach /usr/local/bin
設定
設定分成兩塊,一塊是初始第一台機器:
cockroach start --background --insecure --listen-addr=0.0.0.0 --advertise-addr=$(ifconfig eth0 | grep inet | awk '{print $2}')
另外一塊是後續的機器,多了--join
要設定:
cockroach start --background --insecure --listen-addr=0.0.0.0 --join=192.168.x.x --advertise-addr=$(ifconfig eth0 | grep inet | awk '{print $2}')
可以用以下指令確認機器都有連上cluster:
cockroach node ls --insecure
然後用PostgreSQL的client連上測試:
psql -h 192.168.x.x -p 26257 -U root
另外可能要修改replica
的數量(預設是5):
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 3;
測試
使用一台c5.2xlarge
與五台r5.large
架設Kubernetes後在裡面建立六個Pod測試。
Kubernetes
使用Kubernetes時的設定檔如下:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: poc-c5
spec:
replicas: 1
serviceName: cockroachdb-c5
selector:
matchLabels:
app: cockroachdb-c5
template:
metadata:
labels:
app: cockroachdb-c5
spec:
containers:
- name: cockroachdb-c5
image: ubuntu:18.04
command: ["/bin/sh", "-c"]
args:
- export DEBIAN_FRONTEND=noninteractive;
sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list;
apt update;
apt install -y ant default-jdk git iproute2 iputils-ping locales mtr-tiny net-tools openjdk-8-jdk postgresql-client sysbench tzdata vim-nox wget;
update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java;
locale-gen en_US.UTF-8;
cd /root;
git clone https://github.com/oltpbenchmark/oltpbench.git;
cd oltpbench;
sed -i -e 's/^ALTER TABLE/-- ALTER TABLE/' src/com/oltpbenchmark/benchmarks/tpcc/ddls/tpcc-postgres-ddl.sql;
ant clean;
ant;
cp config/tpcc_config_postgres.xml config/tpcc.xml;
sed -i -e 's/localhost:5432/cockroachdb-port.default.svc.cluster.local:26257/' config/tpcc.xml;
sed -i -e 's/<username>tpcc/<username>root/' config/tpcc.xml;
sed -i -e 's/<password>tpcc/<password>' config/tpcc.xml;
sed -i -e 's/TRANSACTION_READ_COMMITTED/TRANSACTION_SERIALIZABLE/' config/tpcc.xml;
sleep 3153600000
env:
- name: LC_ALL
value: en_US.UTF-8
nodeSelector:
instancetype: c5
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: poc-r5
spec:
replicas: 5
serviceName: cockroachdb-r5
selector:
matchLabels:
app: cockroachdb-r5
template:
metadata:
labels:
app: cockroachdb-r5
spec:
containers:
- name: cockroachdb-r5
image: ubuntu:18.04
command: ["/bin/sh", "-c"]
args:
- export DEBIAN_FRONTEND=noninteractive;
sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list;
apt update;
apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata vim-nox wget;
locale-gen en_US.UTF-8;
cd /tmp;
wget -qO- https://binaries.cockroachdb.com/cockroach-v2.1.3.linux-amd64.tgz | tar xvz;
cp -i cockroach-v2.1.3.linux-amd64/cockroach /usr/local/bin;
sleep 3153600000
env:
- name: LC_ALL
value: en_US.UTF-8
nodeSelector:
instancetype: r5
---
apiVersion: v1
kind: Service
metadata:
name: cockroachdb-port
spec:
selector:
app: cockroachdb-r5
ports:
- protocol: TCP
port: 26257
targetPort: 26257
後續的測試都需要先連入poc-c5-0
的terminal:
kubectl exec -it poc-c5-0 /bin/bash
oltpbenchmark
這邊是拿oltpbenchmark測試。
指令
CREATE DATABASE tpcc;
cd /root/oltpbench
./oltpbenchmark -b tpcc -c config/tpcc.xml --create=true --load=true
./oltpbenchmark -b tpcc -c config/tpcc.xml --execute=true
Sysbench
這邊是拿sysbench測試。
指令
CREATE DATABASE sbtest;
sysbench --db-driver=pgsql --pgsql-host=cockroachdb-port.default.svc.cluster.local --pgsql-port=26257 --pgsql-user=root --pgsql-password= --time=0 --events=10000000 --report-interval=1 --threads=128 /usr/share/sysbench/oltp_insert.lua prepare
sysbench --db-driver=pgsql --pgsql-host=cockroachdb-port.default.svc.cluster.local --pgsql-port=26257 --pgsql-user=root --pgsql-password= --time=0 --events=10000000 --report-interval=1 --threads=128 /usr/share/sysbench/oltp_insert.lua run