OpenStack之OVS网络使用

1. OpenStack使用OVS

1.1 控制节点

  • 配置内核转发
cat >> /etc/sysctl.conf << EOF
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
EOF

modprobe br_netfilter 

sysctl -p
  • 安装
# centos系统
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch
# ubuntu系统
apt install neutron-server neutron-plugin-ml2  neutron-l3-agent neutron-dhcp-agent  neutron-metadata-agent neutron-openvswitch-agent -y
  • 修改neutron配置文件(控制节点)
cp /etc/neutron/neutron.conf{,.bak}

grep -Ev "^$|#" /etc/neutron/neutron.conf.bak > /etc/neutron/neutron.conf

vim /etc/neutron/neutron.conf
[DEFAULT]
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = true
auth_strategy = keystone
state_path = /var/lib/neutron
dhcp_agent_notification = true
allow_overlapping_ips = true
notify_nova_on_port_status_changes = true
notify_nova_on_port_data_changes = true
transport_url = rabbit://openstack:000000@controller

[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron

[database]
connection = mysql+pymysql://neutron:neutron123@controller/neutron

[nova]
auth_url = http://controller:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = nova
password = nova

[oslo_concurrency]
lock_path = /var/lib/neutron/tmp





cp  /etc/neutron/plugins/ml2/ml2_conf.ini{,.bak}

grep -Ev "^$|#" /etc/neutron/plugins/ml2/ml2_conf.ini.bak > /etc/neutron/plugins/ml2/ml2_conf.ini

vim /etc/neutron/plugins/ml2/ml2_conf.ini
[DEFAULT]

[ml2]
type_drivers = flat,vlan,vxlan,gre
tenant_network_types = vxlan
mechanism_drivers = openvswitch,l2population
extension_drivers = port_security

[ml2_type_flat]
flat_networks = physnet1

[ml2_type_vxlan]
vni_ranges = 1:1000

[securitygroup]
enable_ipset = true
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver





cp /etc/neutron/plugins/ml2/openvswitch_agent.ini{,.bak}

grep -Ev "^$|#" /etc/neutron/plugins/ml2/openvswitch_agent.ini.bak > /etc/neutron/plugins/ml2/openvswitch_agent.ini

vim /etc/neutron/plugins/ml2/openvswitch_agent.ini
[agent]
l2_population = True
tunnel_types = vxlan
prevent_arp_spoofing = True

[ovs]
local_ip = 10.0.0.12
bridge_mappings = physnet1:br-eth1







cp /etc/neutron/l3_agent.ini{,.bak}

grep -Ev "^$|#" /etc/neutron/l3_agent.ini.bak > /etc/neutron/l3_agent.ini

vim /etc/neutron/l3_agent.ini
[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
external_network_bridge =




cp /etc/neutron/dhcp_agent.ini{,.bak}

grep -Ev "^$|#" /etc/neutron/dhcp_agent.ini.bak > /etc/neutron/dhcp_agent.ini

vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = True







cp  /etc/neutron/metadata_agent.ini{,.bak}

grep -Ev "^$|#" /etc/neutron/metadata_agent.ini.bak > /etc/neutron/metadata_agent.ini

vim /etc/neutron/metadata_agent.ini
[DEFAULT]
nova_metadata_host = controller
metadata_proxy_shared_secret = xier
  • 修改nova配置文件
vim /etc/nova/nova.conf
[default]
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSlnterfaceDriver

[neutron]
auth_url = http://controller:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
service_metadata_proxy = true
metadata_proxy_shared_secret = xier
  • 创建软连接
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
  • 同步数据库
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
  • 重启nova服务
systemctl restart openstack-nova-api
  • 启动neutron服务
systemctl enable --now neutron-server neutron-metadata-agent neutron-openvswitch-agent openvswitch neutron-l3-agent neutron-dhcp-agent
  • 新建一个外部网络桥接
ovs-vsctl add-br br-eth1
  • 将外部网络桥接映射到网卡
    • 这里第二块网卡是连接外网的
ovs-vsctl add-port br-eth1 eth1
  • 重启neutron服务
systemctl restart neutron-server neutron-metadata-agent neutron-openvswitch-agent openvswitch neutron-l3-agent neutron-dhcp-agent

1.2 计算节点

  • 配置内核转发
cat >> /etc/sysctl.conf << EOF
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
EOF

modprobe br_netfilter 

sysctl -p
  • 安装服务并配置neutron文件
# centos系统
yum install -y openstack-neutron-openvswitch
# Ubuntu系统
apt install -y neutron-openvswitch-agent





cp /etc/neutron/neutron.conf{,.bak}

grep -Ev "^$|#" /etc/neutron/neutron.conf.bak > /etc/neutron/neutron.conf

vim /etc/neutron/neutron.conf
[DEFAULT]
core_plugin = ml2
service_plugins = router
auth_strategy = keystone
state_path = /var/lib/neutron
allow_overlapping_ips = true
transport_url = rabbit://openstack:000000@controller

[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron

[oslo_concurrency]
lock_path = /var/lib/neutron/tmp






cp /etc/neutron/plugins/ml2/openvswitch_agent.ini{,.bak}

grep -Ev "^$|#" /etc/neutron/plugins/ml2/openvswitch_agent.ini.bak > /etc/neutron/plugins/ml2/openvswitch_agent.ini


vim /etc/neutron/plugins/ml2/openvswitch_agent.ini
[agent]
l2_population = True
tunnel_types = vxlan
prevent_arp_spoofing = True

[ovs]
local_ip = 10.0.0.11
bridge_mappings = physnet1:br-eth1

[securitygroup]
enable_security_group = True
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver



systemctl restart neutron-openvswitch-agent
  • 配置nova文件
vim /etc/nova/nova.conf
[DEFAULT]
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSlnterfaceDriver
vif_plugging_is_fatal = true
vif_pligging_timeout = 300

[neutron]
auth_url = http://controller:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
  • 启动ovs
systemctl enable --now openvswitch
  • 新建一个外部网络桥接
ovs-vsctl add-br br-eth1
  • 将外部网络桥接映射到网卡
    • 这里第二块网卡是连接外网的
ovs-vsctl add-port br-eth1 eth1
  • 启动服务
systemctl restart openstack-nova-compute

systemctl enable --now neutron-openvswitch-agent

1.3 创建一个实例

  • 控制节点操作

  • 创建网络

# 加载openstack环境变量
source /etc/keystone/admin-openrc.sh

# 创建路由器
openstack router create router01

# 创建vxlan网络
openstack network create --provider-network-type vxlan intnet

# 创建子网
openstack subnet create intsubnet --network intnet --subnet-range 166.66.66.0/24 --gateway 166.66.66.1 --dns-nameserver 114.114.114.114

# 将内部网络添加到路由器上
openstack router add subnet router01 intsubnet


# 创建flat网络
openstack network create --provider-physical-network physnet1 --provider-network-type flat  --external extnet

# 创建子网
openstack subnet create extsubnet --network extnet --subnet-range 10.0.0.0/24  --allocation-pool start=10.0.0.20,end=10.0.0.200 --gateway 10.0.0.254 --dns-nameserver 114.114.114.114 --no-dhcp

# 设置路由器网关接口
openstack router set router01 --external-gateway extnet
  • 开放安全组
openstack security group rule create --proto icmp default

openstack security group rule create --proto tcp --dst-port 22:22 default

openstack security group rule list
  • 上传镜像
openstack image create cirros04 --disk-format qcow2  --file  cirros-0.4.0-x86_64-disk.img
  • 创建云主机
# 创建ssh-key密钥
ssh-keygen -N ""

# 创建密钥
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey


# 创建flavor
openstack flavor create --vcpus 1 --ram 512 --disk 1 test


# 创建虚拟机
openstack server create --flavor test --image cirros04 --security-group default --nic net-id=7f6957e5-ef33-493e-9e03-a1f75fe25c28 --key-name mykey vm1


# 分配浮动IP
openstack floating ip create extnet

# 分配的浮动IP绑定云主机
openstack server add floating ip vm1 10.0.0.36


# vnc查看实例
openstack console url show vm1

1.4 ovs命令

ovs-vsctl show

ovs-ofctl dump-flows br-eth1

ovs-vsctl list-br 

ovs-vsctl add-br demo-br

ovs-vsctl list-ifaces br-eth1

ovs-vsctl get-manager

ovs-vsctl list-ports br-eth1

2 NFS的cinder后端存储

  • 控制节点
    • 配置nfs后端存储
yum install -y nfs-utils

# 创建输出目录
mkdir /opt/cinder-nfs

chmod 777 -R /opt/cinder-nfs/

# 配置nfs共享目录,“no_root_squash 不将root映射成匿名用户”
vim /etc/exports
/opt/cinder-nfs 10.0.0.0/24(rw,no_root_squash)

# 启动nfs
systemctl restart nfs
  • 计算节点
    • cinder存储节点安装软件包
# 安装服务
yum install -y nfs-utils

systemctl enable --now rpcbind

# 修改配置文件
vim /etc/cinder/cinder.conf
[DEFAULT]
'''
enabled_backends = lvm,nfs

[lvm]
volume_backend_name = lvm

[nfs]
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs_shares
volume_backend_name = nfs
'''

# 告诉cinder,nfs服务器是哪一台
vim /etc/cinder/nfs_shares
10.0.0.10:/opt/cinder-nfs/

# 更改属性
chown -R cinder. /var/lib/cinder/mnt/

systemctl restart openstack-cinder-volume
  • 控制节点
    • 使用nfs
============================nfs存储类型=================================
# 创建nfs卷类型
openstack volume type create nfs

# 配置nfs存储类型用于创建选项
cinder --os-username admin --os-tenant-name admin type-key nfs set volume_backend_name=nfs

# 查看存储类型
openstack volume type list





============================lvm存储类型==================================
openstack volume type create lvm

cinder --os-username admin --os-tenant-name admin type-key lvm set volume_backend_name=lvm

openstack volume type list
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值