Virinfra's Blog


  • 首页

  • 归档

  • 标签

openvswitch命令行工具

发表于 2016-02-16

ovs-vsctl

ovs-vsctl 连接到 ovsdb-server 进程,查询或更新 ovs 数据库。如果更新数据库,则默认它会等待 ovs-vswitchd 根据数据库重新配置交换机后才返回。但使用 --no-wait 选项可不等待而立即返回。
ovs-vsctl 可在单条调用中执行多条子命令,这实现为对数据库的原子事务操作。调用格式:

1
ovs-vsctl [全局选项]... [--] [子选项]... 子命令 [子参数]... [-- [子选项]... 子命令 [子参数]...]...

可以看出,子命令间使用 – 隔开,但首条子命令前可以省略 –,除非其带子选项。

操作 bridge

  • 创建网桥:
1
2
(venv)[root@network ~]# ovs-vsctl add-br br0
(venv)[root@network ~]# ovs-vsctl add-br br1

  • 查看 ovs 数据库内容的概览:
1
2
3
4
5
6
7
8
9
10
11
(venv)[root@network ~]# ovs-vsctl show
d707388c-b65e-41ae-9091-3aee56fd6fa6
Bridge "br1"
Port "br1" # 自动创建的internal类型的本地port和interface
Interface "br1"
type: internal
Bridge "br0"
Port "br0"
Interface "br0"
type: internal
ovs_version: "2.3.1"
  • 列出网桥:
1
2
3
(venv)[root@network ~]# ovs-vsctl list-br
br0
br1

  • 删除网桥:
1
(venv)[root@network ~]# ovs-vsctl del-br br1
1
2
3
4
5
6
7
(venv)[root@network ~]# ovs-vsctl show
d707388c-b65e-41ae-9091-3aee56fd6fa6
Bridge "br0"
Port "br0"
Interface "br0"
type: internal
ovs_version: "2.3.1"
  • 操作 port

创建 system 类型(默认)的 port:

1
2
(venv)[root@network ~]# ovs-vsctl add-port br0 port0
ovs-vsctl: Error detected while setting up 'port0'. See ovs-vswitchd log for details.
1
2
(venv)[root@network ~]# cat /var/log/openvswitch/ovs-vswitchd.log | tail -1
2015-06-10T13:00:08.898Z|00020|bridge|WARN|could not open network device port0 (No such device)

上面创建 system 类型的 port 后,ovs 试图打开对应的不存在的同名网卡设备(虚拟的或物理的)时报错。如果存在同名网卡,则不会报错:

1
2
3
4
(venv)[root@network ~]# ip link show dev eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:f9:3a:14 brd ff:ff:ff:ff:ff:ff
(venv)[root@network ~]# ovs-vsctl add-port br0 eth2
  • 列出 port,默认是不显示本地 port 的:
1
2
3
(venv)[root@network ~]# ovs-vsctl list-ports br0
eth2
port0

  • 删除 port:
1
2
3
4
5
6
7
8
9
(venv)[root@network ~]# ovs-vsctl del-port eth2
(venv)[root@network ~]# ovs-vsctl del-port port0
(venv)[root@network ~]# ovs-vsctl show
d707388c-b65e-41ae-9091-3aee56fd6fa6
Bridge "br0"
Port "br0"
Interface "br0"
type: internal
ovs_version: "2.3.1"

  • 创建 bond:
1
2
3
4
5
6
7
8
9
10
11
(venv)[root@network ~]# ovs-vsctl add-bond br0 bond0 eth1 eth2
(venv)[root@network ~]# ovs-vsctl show
d707388c-b65e-41ae-9091-3aee56fd6fa6
Bridge "br0"
Port "br0"
Interface "br0"
type: internal
Port "bond0"
Interface "eth2" # 两个网卡
Interface "eth1"
ovs_version: "2.3.1"
  • 列出所有连接到网桥的 interface,默认是不显示本地 interface 的:
1
2
3
(venv)[root@network ~]# ovs-vsctl list-ifaces br0
eth1
eth2

操作 ovs 数据库

ovs 数据库目前定义的表:

表名 含义
Open_vSwitch ovs-vswitchd 的全局配置。只包含一条记录,记录标识为 ‘.’
Bridge 网桥配置。记录标识为表名
Port 端口配置。记录标识为端口名
Interface 网卡配置。记录标识为网卡名
Flow_Table 流表。记录标识为流表名
QoS 端口的 Quality-of-service 配置。记录标识为端口名
Queue QoS 配置中一个队列的配置。记录标识为 UUID
Mirror 端口镜像配置。记录标识为镜像名
Controller OpenFlow 控制器配置。记录标识为绑定的网桥名
Manager OVSDB 连接配置。记录标识为目标

操作 ovs 数据库的子命令:- 列出表 table 中的记录 record。不指定 record,则列出表 table 中的所有记录。

[--if-exists] [--columns=column[,column]...] list table [record]...

  • 查找表 table 中的其列 column 满足给定值或键值对的记录的相关列值。

[--columns=column[,column]...] find table [column[:key]=value]...

  • 获取表 table 的记录 record 中的列 column(中键 key)的值。如果指定 –id=@name,则 name 可以在同一条 ovs-vsctl 调用中用于引用此值。

[--if-exists] [--id=@name] get table record [column[:key]]...

  • 设置表 table 的记录 record 中的列 column

[--if-exists] set table record column[:key]=value...

  • 添加表 table 的记录 record 中的列 column

[--if-exists] add table record column [key=]value...

  • 清除表 table 的记录 record 中的匹配给定值(或键,或键值对)的列 column

[--if-exists] remove table record column [key=value | key | value]...

  • 清除表 table 的记录 record 中的列 column 为空。

[--if-exists] clear table record column...

  • 在表 table 中创建一条新记录,根据指定列值对初始化,没有指定的列赋默认值。输出记录的 UUID。如果指定 –id=@name,则 name 可以在同一条 ovs-vsctl 调用中用于引用此记录。

[--id=@name] create table column[:key]=value...

  • 删除表 table 中记录 record。

[--if-exists] destroy table record...

  • 删除表 table 中所有数据,只用于表 QoS 和表 Queue。

--all destroy table

  • 等待表 table 中记录 record 存在,且列值对符合给定。可不指定或指定多个列值对。可指定超时时间。

[--timeout=n] wait-until table record [column[:key]=value]...

ovs-ofctl

流语法

字段 匹配含义
in_port=port OpenFlow 端口号或端口关键字(例如 LOCAL)
dl_vlan=vlan IEEE 802.1q VLAN tag。0xffff 表示没打 tag;否则应指定 0 ~ 4095
dl_vlan_pcp=priority IEEE 802.1q Priority Code Point (PCP) 优先级,0 ~ 7
dl_src=xx:xx:xx:xx:xx:xx 以太网源地址
dl_dst=xx:xx:xx:xx:xx:xx 以太网目的地址

Hexo+GitHub+DNSPod搭建个人博客

发表于 2016-02-14

一、DNS

NameServer设定

在域名服务商页面把NameServer设为DNSPod的NS:f1g1ns1.dnspod.net 和 f1g1ns2.dnspod.net

DNSPod设定

二、GitHub

安装GIT

1
brew install git

生成SSH Key

1
2
3
4
5
$ssh-keygen -t rsa -C "姓名全拼@haodf.com"  
$git config --global user.name "姓名全拼"
$git config --global user.email "姓名全拼@haodf.com"
$cd ~/.ssh/
$cat id_rsa.pub 【注:ssh-keygen 命令默认生成 id_rsa.pub】

生成GitHub Pages

三、Hexo

安装NodeJS

1
brew install node

安装Hexo

1
2
3
4
cd hexo的安装文件夹
npm install hexo -g
hexo init
npm install

Hexo设定、更新

修改Hexo根目录下的_config.yml文件

1
2
3
4
deploy:
- type: git
repo: git@github.com:xxxx/xxxx.github.io.git
branch: master

安装hexo-deployer-git

1
npm install hexo-deployer-git --save

更新hexo到最新版

1
npm update hexo -g

Hexo命令

  • 建立新文章 hexo n "新文章名"

  • 预览文章 hexo s

  • 生成网页 hexo g

  • 发布文章 hexo d

  • 生成网页并发布文章 hexo d -g

四、主题

五、Markdown

Markdown写作APP推荐用Sublime Text 3

安装Package Control

使用快捷键 ctrl + ` 打开Sublime控制台
在控制台的命令行输入框中粘贴下面代码后,回车完成Package Control安装

1
import urllib.request,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

安装MarkdownEditing插件

MarkdownEditing是Markdown写作者必备的插件,它可以不仅可以高亮显示Markdown语法还支持很多编程语言的语法高亮显示。
使用快捷键command + shift + p进入到Sublime命令面板,输入“Install Package”。
在列表中输入“markdown ed”关键字,选择“MarkdownEditing”回车,重启Sublime Text。

插入链接 command + option + k
插入图片 command + shift + k

MarkdownEditing中的code snippet:
输入mdi + tab会自动插入下面的图片标记

1
![Alt text](/path/to/img.jpg "Optional title")

输入mdi + tab会自动生成下面的链接标记

1
[](link)

安装OmmiMarkupPreviewer

OmniMarkupPreviewer用来预览markdown编辑的效果,同样支持渲染代码高亮的样式。
使用快捷键command + shift + p进入到Sublime命令面板,输入“Install Package”。
在列表中输入“omnimarkup”关键字,选择“OmniMarkupPreviewer”回车,重启Sublime Text。

Ubuntu14.04安装OpenvSwitch

发表于 2016-02-13

1、下载安装 Ubuntu14.04 到虚拟机

2、先更新一下源,顺便装个 vim 和 ssh server

1
2
apt-get update
apt-get -y install vim openssh-server

3、安装依赖条件

1
apt-get -y install automake autoconf libssl-dev gcc uml-utilities libtool build-essential git pkg-config linux-headers-`uname -r`

4、下载 openvswitch-2.4.0.tar.gz

1
wget http://openvswitch.org/releases/openvswitch-2.4.0.tar.gz

5、解压到当前目录,然后编译安装

1
2
3
4
5
tar zxvf openvswitch-2.4.0.tar.gz
cd openvswitch-2.4.0
./boot.sh
./configure --with-linux=/lib/modules/`uname -r`/build
make && make install

6、载入内核模块

1
2
3
4
5
6
7
8
# 查看 openvswitch 依赖的模块
modinfo ./datapath/linux/openvswitch.ko
# 发现 openvswitch.ko 依赖于 libcrc32c 模块,于是先载入 libcrc32c
modprobe libcrc32c
# 载入 openvswitch 模块
insmod ./datapath/linux/openvswitch.ko
# 查看模块载入情况,可看到 openvswitch 和 libcrc32c
lsmod|grep open

7、配置 OVS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 创建 ovsdb 数据库
mkdir -p /usr/local/etc/openvswitch
ovsdb-tool create /usr/local/etc/openvswitch/conf.db ./vswitchd/vswitch.ovsschema
# 配置启动 ovsdb 数据库
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
--private-key=db:Open_vSwitch,SSL,private_key \
--certificate=db:Open_vSwitch,SSL,certificate \
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
--pidfile --detach
# 初始化数据库
ovs-vsctl --no-wait init
# 开启 openvswitch 守护进程
ovs-vswitchd --pidfile --detach

8、看到类似以下几行消息,表明 openvswitch 配置完毕

1
2
3
2015-11-27T07:41:59Z|00001|ovs_numa|INFO|Discovered 0 NUMA nodes and 0 CPU cores 
2015-11-27T07:41:59Z|00002|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connecting...
2015-11-27T07:41:59Z|00003|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connected

9、根据下载的 openvswitch 版本的不同,配置命令略有差异,附上 官网配置地址

注:以上操作是在root账户下进行,普通账户请注意切换权限

配置命令介绍

Hello World

发表于 2016-02-11

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

Virinfra

Virinfra

4 日志
3 标签
© 2016 Virinfra
由 Hexo 强力驱动
主题 - NexT.Mist