1
mirror of https://git.dn42.dev/wiki/wiki.git synced 2024-12-14 01:49:55 +01:00
wiki/services/Distributed-Wiki.md

248 lines
6.6 KiB
Markdown
Raw Normal View History

2015-03-31 12:06:06 +02:00
The idea is to deploy mirrors across dn42 using [anycast](https://en.wikipedia.org/wiki/Anycast) addressing (BGP), thus providing redundancy, load-balancing and improved access times to the site.
2015-03-31 09:16:20 +02:00
The local webserver is monitored with a simple [[shell script|Distributed-Wiki#exabgp_watchdog-script]] working [[in conjunction|Distributed-Wiki#exabgp]] with [ExaBGP](https://github.com/Exa-Networks/exabgp), announcing/withdrawing the assigned route if the service is up/down.
2015-03-30 10:28:35 +02:00
2015-03-31 10:25:08 +02:00
## Network
2015-03-30 10:30:57 +02:00
2015-03-31 08:11:30 +02:00
- Install wiki anycast address `172.23.0.80/32` on the system
- Setup tunnel(s) to the dn42 network (routing daemon not required)
2015-03-30 11:10:41 +02:00
2015-03-31 10:25:08 +02:00
## Setup gollum
2015-03-30 11:10:41 +02:00
2015-03-31 08:11:30 +02:00
- Install [gollum](https://github.com/gollum/gollum)
- Clone the dn42 wiki repo:
2015-03-30 10:38:25 +02:00
2015-03-31 09:49:07 +02:00
`git clone ssh://git@dn42.us/dn42/wiki <path>`
2015-03-30 10:15:31 +02:00
2015-03-31 09:21:59 +02:00
- Contact [XUU-DN42](https://io.nixnodes.net?t=person&l=XUU-DN42) and ask for write access to the repo
2015-03-31 08:11:30 +02:00
- Setup cron for periodic pull/push jobs for the repo
2015-03-31 09:50:14 +02:00
- Generate a [CSR](/services/Certificate-Authority) and send to `xuu@dn42.us`. Wait for a reply containing internal.dn42/wiki.dn42 certificates.
2015-03-31 10:20:17 +02:00
- Start two gollum instances, read-only and read/write on `127.0.0.1`:
2015-03-30 10:47:19 +02:00
2015-03-31 10:20:17 +02:00
Read/write (SSL only):
2015-03-30 10:48:57 +02:00
```
2015-03-30 11:48:20 +02:00
gollum --css <path>/custom.css --gollum-path <path> --host 127.0.0.1 --port 4568
2015-03-30 10:58:13 +02:00
```
2015-03-30 12:39:45 +02:00
Read-only:
2015-03-30 10:58:13 +02:00
```
2015-03-30 11:48:20 +02:00
gollum --css <path>/custom.css --gollum-path <path> --host 127.0.0.1 --port 4567 --no-edit
2015-03-30 10:58:13 +02:00
```
2015-03-31 10:25:08 +02:00
## Nginx proxy
2015-03-30 11:10:41 +02:00
2015-03-31 10:25:08 +02:00
#### Header
2015-03-31 08:33:11 +02:00
2015-03-31 08:11:30 +02:00
A custom header `X-SiteID` identifies the site you're connecting to:
+ X-SiteID: `AS number`-`ISO country code`
2015-03-31 10:25:08 +02:00
#### Config example
2015-03-30 10:58:13 +02:00
2015-03-30 10:49:10 +02:00
```
2015-03-30 10:58:13 +02:00
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_session_cache shared:SSL:2m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
ssl_prefer_server_ciphers on;
upstream wiki { server 127.0.0.1:4567; }
server {
server_name internal.dn42 wiki.dn42;
listen 172.23.0.80:80 default;
add_header strict-transport-security "max-age=0; includeSubDomains";
2015-03-31 08:11:30 +02:00
add_header X-SiteID '<aut-num>-<cc>';
2015-03-30 10:39:53 +02:00
2015-03-30 10:58:13 +02:00
location / {
proxy_pass http://wiki;
}
}
upstream wikirw { server 127.0.0.1:4568; }
server {
server_name internal.dn42 wiki.dn42;
listen 172.23.0.80:443 ssl default;
ssl on;
ssl_certificate <path>/ssl.crt;
ssl_certificate_key <path>/ssl.key;
add_header strict-transport-security "max-age=0; includeSubDomains";
add_header Public-Key-Pins 'pin-sha256="mJ1xUCzfru8Ckq2+M6VkNKGOGgSETImRAHBF24mjalw="; pin-sha256="/gOyi7syRMR+d2jZoB/MzcSD++8ciZkSl/hZAQgzWws="; max-age=0; includeSubDomains';
2015-03-31 08:11:30 +02:00
add_header X-SiteID '<aut-num>-<cc>';
2015-03-30 10:58:13 +02:00
location / {
proxy_pass http://wikirw;
}
}
2015-03-30 11:17:26 +02:00
```
2015-03-31 10:25:08 +02:00
## [ExaBGP](https://github.com/Exa-Networks/exabgp)
2015-03-30 11:17:26 +02:00
2015-03-31 10:25:08 +02:00
#### Announcing
2015-03-31 08:22:29 +02:00
The prefix AS-PATH should show the announcement is originating from your AS. After peering ExaBGP to the nearest speaker(s), check if the prefix is routing properly inside your network. Try not to blackhole the passing traffic (e.g. no static routes to `172.23.0.80/28`). Test the whole thing by shutting down nginx/gollum and watch what happens.
2015-03-31 10:25:08 +02:00
#### Configuration
2015-03-30 11:17:26 +02:00
```
2015-03-31 08:26:22 +02:00
# exabgp.conf
2015-03-30 11:17:26 +02:00
group gollum-watchdog {
neighbor <peer1> {
router-id x.x.x.x;
local-address <source-address>;
local-as <ownas>;
peer-as <peeras>;
}
## (example) peer with one of our iBGP speakers:
neighbor <172.22.0.1> {
router-id 172.23.0.80;
2015-03-30 13:26:33 +02:00
local-address 172.22.0.2;
2015-03-30 11:17:26 +02:00
local-as 123456;
peer-as 123456;
}
## ...
process watch-gollum {
2015-03-30 11:41:28 +02:00
run <path>/gollum-watchdog.sh;
2015-03-30 11:17:26 +02:00
}
}
2015-03-30 11:10:41 +02:00
2015-03-30 10:58:13 +02:00
```
2015-03-30 10:30:57 +02:00
2015-03-31 10:25:08 +02:00
#### Watchdog script
2015-03-31 08:22:29 +02:00
2015-03-30 11:59:07 +02:00
Watchdog runs in an infinite loop, sending the appropriate commands to stdout. [ExaBGP](https://github.com/Exa-Networks/exabgp) attaches to the process' stdout and listens for instructions. Watchdog sends either a route announce or widthdraw.
2015-03-31 08:26:22 +02:00
Run `gollum-watchdog.sh` in a shell first to validate it's working:
2015-03-30 11:59:07 +02:00
2015-03-31 12:06:06 +02:00
```sh
2015-03-30 10:14:08 +02:00
#!/bin/bash
2015-03-30 11:41:28 +02:00
CURL=curl
## url's to check (all listed must be alive to send announce)
2015-03-30 10:14:08 +02:00
URL=( "http://172.23.0.80" "https://172.23.0.80" )
2015-03-30 10:28:35 +02:00
2015-03-30 11:41:28 +02:00
## the anycast route (/28 due to prefix size limits)
2015-03-30 10:14:08 +02:00
ROUTE='172.23.0.80/28'
2015-03-30 11:41:28 +02:00
## the next-hop we'll be advertising to neighbor(s)
NEXTHOP='<source-address>'
## regex match this keyword against HTTP response from curl
VALIDATE_KEYWORD='gollum'
2015-03-30 10:14:08 +02:00
INTERVAL=60
###########################
RUN_STATE=0
check_urls() {
for url in "${URL[@]}"; do
2015-03-30 11:41:28 +02:00
## workaround curl errno 23 when piping
http_response=`${CURL} --insecure -L -o - "${url}"`
echo "${http_response}" | egrep -q "${VALIDATE_KEYWORD}" || {
2015-03-30 10:14:08 +02:00
return 1
}
2015-03-30 11:41:28 +02:00
## add more checks
2015-03-30 10:14:08 +02:00
done
return 0
}
while [ 1 ]; do
if [ ${RUN_STATE} -eq 0 ]; then
check_urls && {
RUN_STATE=1
echo "announce route ${ROUTE} next-hop ${NEXTHOP}"
}
else
check_urls || {
RUN_STATE=0
echo "withdraw route ${ROUTE} next-hop ${NEXTHOP}"
}
fi
sleep ${INTERVAL}
done
exit 0
```
2015-03-19 07:47:45 +01:00
2015-03-31 10:25:08 +02:00
#### Run
2015-03-31 08:26:22 +02:00
2015-03-30 11:47:07 +02:00
Normally SIGUSR1 to the exabgp process triggers a configuration update, but at occasion the process might need to be restarted - since its gracefull shutdown can be glitchy , this might be a bit difficult. Sending SIGKILL to the child(ren) and immediately after, the parent, does the job (quick-and-dirty).
2015-03-30 11:41:28 +02:00
2015-03-30 11:47:07 +02:00
`USAGE: /etc/exabgp/run.sh [start|stop|restart]`
2015-03-30 11:41:28 +02:00
2015-03-31 12:06:06 +02:00
```sh
2015-03-30 11:41:28 +02:00
#!/bin/bash
PID_FILE=/var/run/exaBGP/exabgp_PID
######################################
EXABGP=<path>/sbin/exabgp
EXA_LOG=/var/log/exabgp.log
CONF=/etc/exabgp/exabgp.conf
start() {
[ -f ${PID_FILE} ] && {
echo "WARNING: `cat ${PID_FILE}`: exabgp already running"; return 1
}
${EXABGP} ${CONF} &> ${EXA_LOG} &
cpid=$!
[ ${cpid} -eq 0 ] && {
echo "ERROR: could not start process"; return 1
}
echo $! > ${PID_FILE}
}
stop(){
[ -f ${PID_FILE} ] || return 1
pkill -9 -P $(cat ${PID_FILE})
kill -9 $(cat ${PID_FILE})
rm -f ${PID_FILE}
}
case ${1} in
start )
start
;;
stop )
stop
;;
restart )
stop
sleep 1
start
;;
esac
exit 0
2015-03-30 11:59:07 +02:00
```
2015-03-30 12:16:25 +02:00