Skip to content

Commit c7f311d

Browse files
committed
Merge branch 'main' into sshj
2 parents 010c502 + 8bfd889 commit c7f311d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+864
-516
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,10 @@ this is because (I think) SSHJ tries to verify only the ed25519 key and
180180
ssh-keyscan -t ed25519 n1 >> ~/.ssh/known_hosts
181181
...
182182
```
183+
184+
## Other Projects
185+
186+
Additional projects that may be of interest:
187+
188+
- [Jecci](https://github.com/michaelzenz/jecci): A wrapper framework around Jepsen
189+
- [Porcupine](https://github.com/anishathalye/porcupine): a linearizability checker written in Go.

doc/lxc.md

Lines changed: 65 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
# How to set up nodes via LXC
2-
## Debian Testing:
32

4-
(refer to https://wiki.debian.org/LXC)
3+
## Debian Buster
54

6-
```sh
7-
aptitude install lxc bridge-utils ebtables libvirt-bin debootstrap dnsmasq
8-
```
9-
10-
Add this line to /etc/fstab:
5+
(Refer to https://wiki.debian.org/LXC)
116

127
```
13-
cgroup /sys/fs/cgroup cgroup defaults 0 0
14-
```
15-
16-
Mount ze cgroup
17-
18-
```
19-
mount /sys/fs/cgroup
8+
apt install lxc debootstrap bridge-utils libvirt-clients libvirt-daemon-system iptables ebtables dnsmasq-base libxml2-utils iproute2
209
```
2110

2211
Apply google and kernel parameters until checkconfig passes:
@@ -25,157 +14,112 @@ Apply google and kernel parameters until checkconfig passes:
2514
lxc-checkconfig
2615
```
2716

28-
Create a VM or five
17+
Create VMs:
2918

3019
```
31-
lxc-create -n n1 -t debian -- --release jessie
32-
lxc-create -n n2 -t debian -- --release jessie
33-
lxc-create -n n3 -t debian -- --release jessie
34-
lxc-create -n n4 -t debian -- --release jessie
35-
lxc-create -n n5 -t debian -- --release jessie
20+
for i in {1..10}; do sudo lxc-create -n n$i -t debian -- --release buster; done
3621
```
3722

38-
Note the root passwords.
39-
40-
Edit /var/lib/lxc/n1/config and friends, changing the network hwaddr to something unique. I suggest using sequential mac addresses for n1, n2, n3, ....
23+
Add network configuration to each node. We assign each a sequential MAC
24+
address.
4125

4226
```
43-
# Template used to create this container: /usr/share/lxc/templates/lxc-debian
44-
# Parameters passed to the template:
45-
# For additional config options, please look at lxc.conf(5)
46-
47-
lxc.rootfs = /var/lib/lxc/n1/rootfs
27+
for i in {1..10}; do
28+
sudo cat >>/var/lib/lxc/n${i}/config <<EOF
4829
49-
# Common configuration
50-
lxc.include = /usr/share/lxc/config/debian.common.conf
51-
52-
# Container specific configuration
53-
lxc.mount = /var/lib/lxc/n1/fstab
54-
lxc.utsname = n1
55-
lxc.arch = amd64
56-
57-
# Stuff to add:
58-
lxc.network.type = veth
59-
lxc.network.flags = up
60-
lxc.network.link = virbr0
61-
lxc.network.ipv4 = 0.0.0.0/24
62-
lxc.network.hwaddr = 00:1E:62:AA:AA:AA
30+
# Network config
31+
lxc.net.0.type = veth
32+
lxc.net.0.flags = up
33+
lxc.net.0.link = virbr0
34+
lxc.net.0.hwaddr = 00:1E:62:AA:AA:$(printf "%02x" $i)
35+
EOF
36+
done
6337
```
6438

65-
Set up libvirt network, and assign MAC->IP bindings for the LXC node mac addrs
39+
Set up the virsh network bindings mapping those MAC addresses to hostnames and
40+
IP addresses:
6641

67-
```sh
68-
virsh net-edit default
6942
```
70-
71-
```xml
72-
<network>
73-
<name>default</name>
74-
<uuid>08063db9-38f4-4c9c-8887-08000f13ce80</uuid>
75-
<forward mode='nat'/>
76-
<bridge name='virbr0' stp='on' delay='0'/>
77-
<mac address='52:54:00:8e:29:d2'/>
78-
<ip address='192.168.122.1' netmask='255.255.255.0'>
79-
<dhcp>
80-
<range start='192.168.122.11' end='192.168.122.100'/>
81-
<host mac='00:1E:62:AA:AA:AA' name='n1' ip='192.168.122.11'/>
82-
<host mac='00:1E:62:AA:AA:AB' name='n2' ip='192.168.122.12'/>
83-
<host mac='00:1E:62:AA:AA:AC' name='n3' ip='192.168.122.13'/>
84-
<host mac='00:1E:62:AA:AA:AD' name='n4' ip='192.168.122.14'/>
85-
<host mac='00:1E:62:AA:AA:AE' name='n5' ip='192.168.122.15'/>
86-
</dhcp>
87-
</ip>
88-
</network>
43+
for i in {1..10}; do
44+
virsh net-update --current default add-last ip-dhcp-host "<host mac=\"00:1E:62:AA:AA:$(printf "%02x" $i)\" name=\"n${i}\" ip=\"192.168.122.1$(printf "%02d" $i)\"/>"
45+
done
8946
```
9047

91-
Drop an entry in `/etc/resolv.conf` to read from the libvirt network dns:
48+
Start the network, and set it to start at boot so the dnsmasq will be
49+
available.
9250

9351
```
94-
nameserver 192.168.122.1 # Local libvirt dnsmasq
95-
nameserver 192.168.1.1 # Regular network resolver
52+
virsh net-autostart default;
53+
virsh net-start default
9654
```
9755

98-
Kill the system default dnsmasq (if you have one), and start the network (which
99-
in turn will start a replacement dnsmasq with the LXC config. Then, start up
100-
all the nodes. I have this in a bash script called `jepsen-start`:
56+
If you configure resolv.conf by hand, add the libvirt local dnsmasq to
57+
resolv.conf:
10158

102-
```sh
103-
#!/bin/sh
104-
sudo service dnsmasq stop
105-
sudo virsh net-start default
106-
sudo lxc-start -d -n n1
107-
sudo lxc-start -d -n n2
108-
sudo lxc-start -d -n n3
109-
sudo lxc-start -d -n n4
110-
sudo lxc-start -d -n n5
11159
```
112-
113-
Fire up each VM:
114-
115-
```sh
116-
jepsen-start
60+
echo -e "nameserver 192.168.122.1\n$(cat /etc/resolv.conf)" > /etc/resolv.conf
11761
```
11862

119-
Log into the containers, (may have to specify tty 0 to use console correctly) e.g.,:
63+
If you're letting dhclient manage it, then:
12064

121-
```sh
122-
lxc-console --name n1 -t 0
12365
```
124-
125-
(Optional?) In the containers, update keys used by apt to verify packages:
126-
127-
```sh
128-
apt-key update
129-
apt-get update
66+
echo "prepend domain-name-servers 192.168.122.1;" >>/etc/dhcp/dhclient.conf
67+
sudo service networking restart
13068
```
13169

132-
And set your root password--I use `root`/`root` by default in Jepsen.
70+
Slip your preferred SSH key into each node's `.authorized-keys`:
13371

134-
```sh
135-
passwd
13672
```
137-
138-
Copy your SSH key (on host):
139-
140-
```sh
141-
cat ~/.ssh/id_rsa.pub
73+
for i in {1..10}; do
74+
mkdir -p /var/lib/lxc/n${i}/rootfs/root/.ssh
75+
chmod 700 /var/lib/lxc/n${i}/rootfs/root/.ssh/
76+
cp ~/.ssh/id_rsa.pub /var/lib/lxc/n${i}/rootfs/root/.ssh/authorized_keys
77+
chmod 644 /var/lib/lxc/n${i}/rootfs/root/.ssh/authorized_keys
78+
done
14279
```
14380

144-
and add it to root's `authorized_keys` (in containers):
81+
And start the nodes:
14582

146-
```sh
147-
apt-get install -y sudo vim
148-
mkdir ~/.ssh
149-
chmod 700 ~/.ssh
150-
touch ~/.ssh/authorized_keys
151-
chmod 600 ~/.ssh/authorized_keys
152-
vim ~/.ssh/authorized_keys
15383
```
154-
155-
Enable password-based login for root (used by jsch):
156-
```sh
157-
sed -i 's,^PermitRootLogin .*,PermitRootLogin yes,g' /etc/ssh/sshd_config
158-
systemctl restart sshd
159-
apt install sudo
84+
for i in {1..10}; do
85+
lxc-start -d -n n$i
86+
done
16087
```
16188

162-
[Remove systemd](http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installation). After you install sysvinit-core and sysvinit-utils, you may have to restart the container with /lib/sysvinit/init argument to lxc-start before apt will allow you to remove systemd.
89+
To stop them:
16390

164-
Detach from the container with Control+a q, and repeat for the remaining nodes.
91+
```
92+
for i in {1..10}; do
93+
lxc-stop -n n$i
94+
done
95+
```
16596

166-
On the control node, drop entries in `~/.ssh/config` for nodes:
97+
Reset the root passwords to whatever you like. Jepsen uses `root` by default,
98+
and allow root logins with passwords on each container. If you've got an SSH
99+
agent set up, Jepsen can use that instead.
167100

168101
```
169-
Host n*
170-
User root
102+
for i in {1..10}; do
103+
lxc-attach -n n${i} -- bash -c 'echo -e "root\nroot\n" | passwd root';
104+
lxc-attach -n n${i} -- sed -i 's,^#\?PermitRootLogin .*,PermitRootLogin yes,g' /etc/ssh/sshd_config;
105+
lxc-attach -n n${i} -- systemctl restart sshd;
106+
done
171107
```
172108

173109
Store the host keys unencrypted so that jsch can use them. If you already have
174110
the host keys, they may be unreadable to Jepsen--remove them from .known_hosts
175111
and rescan.
176112

177113
```
178-
for n in $(seq 1 5); do ssh-keyscan -t rsa n$n; done >> ~/.ssh/known_hosts
114+
for n in {1..10}; do ssh-keyscan -t rsa n$n; done >> ~/.ssh/known_hosts
115+
```
116+
117+
Install `sudo`:
118+
119+
```sh
120+
for i in {1..10}; do
121+
lxc-attach -n n${i} -- apt install -y sudo
122+
done
179123
```
180124

181125
And check that you can SSH to the nodes
@@ -184,8 +128,6 @@ And check that you can SSH to the nodes
184128
cssh n1 n2 n3 n4 n5
185129
```
186130

187-
And that should mostly do it, I think.
188-
189131
## Ubuntu 14.04 / trusty
190132

191133
Follow generally the same steps as for Debian, but the process is easier. Reference: https://help.ubuntu.com/lts/serverguide/lxc.html

doc/plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Knossos: Better error messages when users pass models that fail on the
66
first op (I think there's a ticket about this? Null pointer exception for i?)
7+
- When users enter a node multiple times into :nodes, complain early
78

89
## Visualizations
910

doc/tutorial/03-client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ value in for the completion op.
3636

3737
Now we need to take these operations and *apply* them to etcd. We'll use
3838
the [Verschlimmbessergung](https://github.com/aphyr/verschlimmbesserung)
39-
library to talk to etcd. We'll start by requireing Verschlimmbesserung, and
39+
library to talk to etcd. We'll start by requiring Verschlimmbesserung, and
4040
writing an empty implementation of Jepsen's Client protocol:
4141

4242
```clj

docker/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
secret/*
22
!.gitkeep
3-
3+
./docker-compose.yml

docker/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ It is intended to be used by a CI tool or anyone with Docker who wants to try Je
55

66
It contains all the jepsen dependencies and code. It uses [Docker
77
Compose](https://github.com/docker/compose) to spin up the five containers used
8-
by Jepsen.
8+
by Jepsen. A script builds a `docker-compose.yml` file out of fragments in
9+
`template/`, because this is the future, and using `awk` to generate YAML to
10+
generate computers is *cloud native*.
911

1012
## Quickstart
1113

@@ -26,6 +28,8 @@ results.
2628

2729
## Advanced
2830

31+
You can change the number of DB nodes by running (e.g.) `bin/up -n 9`.
32+
2933
If you need to log into a DB node (e.g. to debug a test), you can `ssh n1` (or n2, n3, ...) from inside the control node, or:
3034

3135
```

docker/bin/build-docker-compose

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Builds a docker-compose file. You'd THINK we could do this with `replicas`
4+
# but nooooooo, down that path lies madness. Instead we're going to do some
5+
# janky templating with sed and awk. I am so, so sorry.
6+
7+
# Takes a number of nodes to generate a file for, and emits a file
8+
# `docker-compose.yml`.
9+
10+
NODE_COUNT=$1
11+
12+
DEPS=""
13+
DBS=""
14+
15+
# For each node
16+
for ((n=1;n<=NODE_COUNT;n++)); do
17+
# Build up deps for control
18+
LINE=`cat template/depends.yml | sed s/%%N%%/${n}/g`
19+
DEPS="${DEPS}${LINE}"$'\n'
20+
21+
# Build up DB service
22+
DB=`cat template/db.yml | sed s/%%N%%/${n}/g`
23+
DBS="${DBS}${DB}"$'\n'
24+
done
25+
26+
# Build docker-compose file
27+
export DEPS
28+
export DBS
29+
cat template/docker-compose.yml |
30+
awk ' {gsub(/%%DEPS%%/, ENVIRON["DEPS"]); print} ' |
31+
awk ' {gsub(/%%DBS%%/, ENVIRON["DBS"]); print} ' \
32+
> docker-compose.yml

docker/bin/up

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pushd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."
3232

3333
HELP=0
3434
INIT_ONLY=0
35+
NODE_COUNT=5
3536
DEV=""
3637
COMPOSE=${COMPOSE:-""}
3738
RUN_AS_DAEMON=0
@@ -70,6 +71,11 @@ do
7071
RUN_AS_DAEMON=1
7172
shift # past argument
7273
;;
74+
-n|--node-count)
75+
NODE_COUNT=$2
76+
shift
77+
shift
78+
;;
7379
*)
7480
POSITIONAL+=("$1")
7581
ERROR "unknown option $1"
@@ -116,6 +122,10 @@ else
116122
INFO "No need to generate key pair"
117123
fi
118124

125+
126+
## Build dockerfile
127+
bin/build-docker-compose $NODE_COUNT
128+
119129
# Make sure folders referenced in control Dockerfile exist and don't contain leftover files
120130
rm -rf ./control/jepsen
121131
mkdir -p ./control/jepsen/jepsen
@@ -141,17 +151,21 @@ exists docker-compose ||
141151

142152
INFO "Running \`docker-compose build\`"
143153
# shellcheck disable=SC2086
144-
docker-compose -f docker-compose.yml ${COMPOSE} ${DEV} build
154+
docker-compose --compatibility -p jepsen -f docker-compose.yml ${COMPOSE} ${DEV} build
155+
156+
# We need a fresh share volume each time we start, so we have a correct set of
157+
# DB hosts. Why does Docker make sharing state SO hard
158+
docker run --rm -v jepsen_jepsen-shared:/data/ debian:buster rm /data/nodes || true
145159

146160
INFO "Running \`docker-compose up\`"
147161
if [ "${RUN_AS_DAEMON}" -eq 1 ]; then
148162
# shellcheck disable=SC2086
149-
docker-compose -f docker-compose.yml ${COMPOSE} ${DEV} up -d
163+
docker-compose --compatibility -p jepsen -f docker-compose.yml ${COMPOSE} ${DEV} up -d
150164
INFO "All containers started! Run \`docker ps\` to view, and \`bin/console\` to get started."
151165
else
152166
INFO "Please run \`bin/console\` in another terminal to proceed"
153167
# shellcheck disable=SC2086
154-
docker-compose -f docker-compose.yml ${COMPOSE} ${DEV} up
168+
docker-compose --compatibility -p jepsen -f docker-compose.yml ${COMPOSE} ${DEV} up
155169
fi
156170

157171
popd

0 commit comments

Comments
 (0)