mirror of
https://github.com/luscis/openlan.git
synced 2025-10-05 00:32:59 +08:00
docker: add ovsdb-server and ovs-vswitch
This commit is contained in:
13
Makefile
13
Makefile
@@ -1,7 +1,7 @@
|
|||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
|
|
||||||
.ONESHELL:
|
.ONESHELL:
|
||||||
.PHONY: linux linux-rpm darwin darwin-zip windows windows-zip test vendor
|
.PHONY: docker linux linux-rpm darwin darwin-zip windows windows-zip test vendor
|
||||||
|
|
||||||
## version
|
## version
|
||||||
LSB = $(shell lsb_release -i -s)$(shell lsb_release -r -s)
|
LSB = $(shell lsb_release -i -s)$(shell lsb_release -r -s)
|
||||||
@@ -38,15 +38,10 @@ bin: linux windows darwin ## build all platform binary
|
|||||||
## docker run --network host --privileged \
|
## docker run --network host --privileged \
|
||||||
## -v /var/run:/var/run -v /etc/openlan/switch:/etc/openlan/switch \
|
## -v /var/run:/var/run -v /etc/openlan/switch:/etc/openlan/switch \
|
||||||
## openlan-switch:5.8.13
|
## openlan-switch:5.8.13
|
||||||
docker: docker-switch docker-confd
|
docker: pkg
|
||||||
|
cp $(SD)/docker/openlan.docker $(BD)
|
||||||
|
cd $(BD) && docker build -t openlan:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan.docker .
|
||||||
|
|
||||||
docker-switch: pkg
|
|
||||||
cp $(SD)/docker/openlan-switch.docker $(BD)
|
|
||||||
cd $(BD) && docker build -t openlan-switch:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan-switch.docker .
|
|
||||||
|
|
||||||
docker-confd: pkg
|
|
||||||
cp $(SD)/docker/openlan-confd.docker $(BD)
|
|
||||||
cd $(BD) && docker build -t openlan-confd:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan-confd.docker .
|
|
||||||
|
|
||||||
clean: ## clean cache
|
clean: ## clean cache
|
||||||
rm -rvf ./build
|
rm -rvf ./build
|
||||||
|
4
dist/resource/openlan-confd.service
vendored
4
dist/resource/openlan-confd.service
vendored
@@ -9,8 +9,8 @@ PIDFile=/var/openlan/confd/confd.pid
|
|||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
EnvironmentFile=-/etc/sysconfig/openlan/confd
|
EnvironmentFile=-/etc/sysconfig/openlan/confd
|
||||||
|
|
||||||
ExecStart=/var/openlan/script/confd start --detach
|
ExecStart=/var/openlan/script/confd.sh start --detach
|
||||||
ExecStop=/var/openlan/script/confd stop
|
ExecStop=/var/openlan/script/confd.sh stop
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
11
dist/script/confd → dist/script/confd.sh
vendored
11
dist/script/confd → dist/script/confd.sh
vendored
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -ex
|
||||||
|
|
||||||
command=$1; shift
|
command=$1; shift
|
||||||
options=$@;
|
options=$@;
|
||||||
@@ -8,6 +8,8 @@ options=$@;
|
|||||||
dir=$(dirname $0)
|
dir=$(dirname $0)
|
||||||
|
|
||||||
OVSDB_SERVER_BIN="/usr/bin/env ovsdb-server"
|
OVSDB_SERVER_BIN="/usr/bin/env ovsdb-server"
|
||||||
|
OVSDB_TOOL_BIN="/usr/bin/env ovsdb-tool"
|
||||||
|
[ "$OVSDB_DATABASE_SCH" == "" ] && OVSDB_DATABASE_SCH="/etc/openlan/switch/confd.schema.json"
|
||||||
[ "$OVSDB_DATABASE" == "" ] && OVSDB_DATABASE="/etc/openlan/switch/confd.db"
|
[ "$OVSDB_DATABASE" == "" ] && OVSDB_DATABASE="/etc/openlan/switch/confd.db"
|
||||||
[ "$OVSDB_LOG_FILE" == "" ] && OVSDB_LOG_FILE="/var/openlan/confd/confd.log"
|
[ "$OVSDB_LOG_FILE" == "" ] && OVSDB_LOG_FILE="/var/openlan/confd/confd.log"
|
||||||
[ "$OVSDB_SOCK" == "" ] && OVSDB_SOCK="/var/openlan/confd/confd.sock"
|
[ "$OVSDB_SOCK" == "" ] && OVSDB_SOCK="/var/openlan/confd/confd.sock"
|
||||||
@@ -18,14 +20,17 @@ function stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
[ -e "$OVSDB_DATABASE" ] || {
|
||||||
|
$OVSDB_TOOL_BIN create $OVSDB_DATABASE $OVSDB_DATABASE_SCH
|
||||||
|
}
|
||||||
set $OVSDB_SERVER_BIN $OVSDB_DATABASE
|
set $OVSDB_SERVER_BIN $OVSDB_DATABASE
|
||||||
set "$@" -vconsole:emer -vsyslog:err -vfile:info
|
set "$@" -vconsole:info -vsyslog:off -vfile:off
|
||||||
set "$@" --remote=punix:"$OVSDB_SOCK"
|
set "$@" --remote=punix:"$OVSDB_SOCK"
|
||||||
set "$@" --log-file="$OVSDB_LOG_FILE"
|
set "$@" --log-file="$OVSDB_LOG_FILE"
|
||||||
set "$@" --pidfile="$OVSDB_PID_FILE"
|
set "$@" --pidfile="$OVSDB_PID_FILE"
|
||||||
[ "$OVSDB_OPTIONS" != "" ] && set "$@" $OVSDB_OPTIONS
|
[ "$OVSDB_OPTIONS" != "" ] && set "$@" $OVSDB_OPTIONS
|
||||||
for opt in $options; do
|
for opt in $options; do
|
||||||
set "$@" $opt
|
set "$@" $opt
|
||||||
done
|
done
|
||||||
OVS_RUNDIR="/var/openlan/confd" "$@"
|
OVS_RUNDIR="/var/openlan/confd" "$@"
|
||||||
}
|
}
|
7
dist/script/ovs-vswitchd.sh
vendored
Executable file
7
dist/script/ovs-vswitchd.sh
vendored
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
/usr/sbin/ovs-vswitchd unix:/run/openvswitch/db.sock \
|
||||||
|
-vconsole:info -vsyslog:off -vfile:off --mlockall \
|
||||||
|
--pidfile
|
15
dist/script/ovsdb-server.sh
vendored
Executable file
15
dist/script/ovsdb-server.sh
vendored
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
if [ ! -f "/etc/openvswitch/conf.db" ]; then
|
||||||
|
ovsdb-tool create /etc/openvswitch/conf.db
|
||||||
|
elif ovsdb-tool needs-conversion /etc/openvswitch/conf.db | grep -s -w yes; then
|
||||||
|
ovsdb-tool convert /etc/openvswitch/conf.db
|
||||||
|
fi
|
||||||
|
|
||||||
|
/usr/sbin/ovsdb-server /etc/openvswitch/conf.db \
|
||||||
|
-vconsole:info -vsyslog:off -vfile:off \
|
||||||
|
--remote=punix:/run/openvswitch/db.sock \
|
||||||
|
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
|
||||||
|
--pidfile
|
32
dist/script/switch.sh
vendored
Executable file
32
dist/script/switch.sh
vendored
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
if [ ! -e "/etc/openlan/switch/switch.json" ]; then
|
||||||
|
cat >> /etc/openlan/switch/switch.json << EOF
|
||||||
|
{
|
||||||
|
"cert": {
|
||||||
|
"directory": "/var/openlan/cert"
|
||||||
|
},
|
||||||
|
"http": {
|
||||||
|
"public": "/var/openlan/public"
|
||||||
|
},
|
||||||
|
"crypt": {
|
||||||
|
"secret": "cb2ff088a34d"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e "/etc/openlan/switch/network/example.json" ]; then
|
||||||
|
cat >> /etc/openlan/switch/network/example.json << EOF
|
||||||
|
{
|
||||||
|
"name": "example",
|
||||||
|
"bridge": {
|
||||||
|
"address": "172.32.100.40/24"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
/usr/bin/openlan-switch -conf:dir /etc/openlan/switch -log:level 20
|
@@ -1,16 +1,38 @@
|
|||||||
version: "2.3"
|
version: "2.3"
|
||||||
services:
|
services:
|
||||||
|
ovsdb-server:
|
||||||
|
image: "openlan:latest"
|
||||||
|
entrypoint: ["/var/openlan/script/ovsdb-server.sh", "start"]
|
||||||
|
volumes:
|
||||||
|
- /opt/openlan/run/openvswitch:/run/openvswitch
|
||||||
|
- /opt/openlan/etc/openvswitch:/etc/openvswitch
|
||||||
|
ovs-vswitchd:
|
||||||
|
image: "openlan:latest"
|
||||||
|
privileged: true
|
||||||
|
entrypoint: ["/var/openlan/script/ovs-vswitchd.sh", "start"]
|
||||||
|
volumes:
|
||||||
|
- /opt/openlan/run/openvswitch:/run/openvswitch
|
||||||
|
depends_on:
|
||||||
|
- ovsdb-server
|
||||||
confd:
|
confd:
|
||||||
image: "openlan-confd:latest"
|
image: "openlan:latest"
|
||||||
|
entrypoint: ["/var/openlan/script/confd.sh", "start"]
|
||||||
volumes:
|
volumes:
|
||||||
- /opt/openlan/confd:/var/openlan/confd
|
- /opt/openlan/confd:/var/openlan/confd
|
||||||
|
- /opt/openlan/etc/openlan:/etc/openlan
|
||||||
switch:
|
switch:
|
||||||
image: "openlan-switch:latest"
|
image: "openlan:latest"
|
||||||
privileged: true
|
privileged: true
|
||||||
|
entrypoint: ["/var/openlan/script/switch.sh", "start"]
|
||||||
ports:
|
ports:
|
||||||
- 10000:10000
|
- 10000:10000
|
||||||
- 10002:10002
|
- 10002:10002
|
||||||
volumes:
|
volumes:
|
||||||
- /opt/openlan/confd:/var/openlan/confd
|
- /opt/openlan/confd:/var/openlan/confd
|
||||||
|
- /opt/openlan/run/openvswitch:/run/openvswitch
|
||||||
|
- /opt/openlan/etc/openvswitch:/etc/openvswitch
|
||||||
|
- /opt/openlan/etc/openlan:/etc/openlan
|
||||||
depends_on:
|
depends_on:
|
||||||
- confd
|
- confd
|
||||||
|
- ovsdb-server
|
||||||
|
- ovs-vswitchd
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
FROM centos:7
|
|
||||||
|
|
||||||
ARG BIN
|
|
||||||
|
|
||||||
WORKDIR /root
|
|
||||||
|
|
||||||
ADD ${BIN} /tmp
|
|
||||||
|
|
||||||
RUN yum install -y epel-release centos-release-openstack-train \
|
|
||||||
&& yum install -y rdma-core libibverbs
|
|
||||||
RUN DOCKER=yes /tmp/${BIN}
|
|
||||||
|
|
||||||
RUN rm -rf /tmp/* && rm -rf /var/cache/yum/*
|
|
||||||
|
|
||||||
LABEL application="OpenLAN Switch Application"
|
|
||||||
LABEL maintainer="danieldin95@163.com"
|
|
||||||
|
|
||||||
EXPOSE 10000/tcp
|
|
||||||
EXPOSE 10002/tcp
|
|
||||||
EXPOSE 10002/udp
|
|
||||||
EXPOSE 4500/udp
|
|
||||||
|
|
||||||
CMD ["/usr/bin/openlan-switch", "-conf:dir", "/etc/openlan/switch", "-log:level", "20"]
|
|
@@ -15,4 +15,4 @@ RUN rm -rf /tmp/* && rm -rf /var/cache/yum/*
|
|||||||
LABEL application="OpenLAN Switch Application"
|
LABEL application="OpenLAN Switch Application"
|
||||||
LABEL maintainer="danieldin95@163.com"
|
LABEL maintainer="danieldin95@163.com"
|
||||||
|
|
||||||
CMD ["/var/openlan/script/confd", "start"]
|
CMD ["/var/openlan/script/switch.sh", "start"]
|
@@ -246,6 +246,6 @@ func IptInit() {
|
|||||||
}
|
}
|
||||||
__iptablesInit__ = true
|
__iptablesInit__ = true
|
||||||
if err := iptables.FirewalldInit(); err != nil {
|
if err := iptables.FirewalldInit(); err != nil {
|
||||||
libol.Info("IptInit %s", err)
|
libol.Debug("IptInit %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user