openstack入门搭建
计算 网络 存储
操作最低配
server1 4G内存
server2 2G 内存
网络参考
https://www.cnblogs.com/shhnwangjian/p/6379640.html
server1 两块网卡 桥接
eth1
BOOTPROTO=none
DEVICE=eth1
ONBOOT=yes
ifup eth1
hostnamectl set-hostname controller
解析
172.25.11.1 controller
172.25.11.2 compute1
172.25.11.3 block1
server2
hostnamectl set-hostname compute1
做好与真机的时间同步 chronyd
vim /etc/chrony.conf
server 172.25.11.250 iburst
allow 172.25/16
chronyc sources -v
server 1 2
server1
yum upgrade
这里禁用了 selinux
yum install mariadb mariadb-server python2-PyMySQL
/etc/my.cnf.d/openstack.cnf
[mysqld]
bind-address = 172.25.11.1
default-storage-engine = innodb
innodb_file_per_table
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8
systemctl enable mariadb.service
systemctl start mariadb.service
mysql_secure_installation
mongodb 是用来计算流量收费的 这里不需要安装
消息队列的安装
yum install rabbitmq-server -y
systemctl start rabbitmq-server.service
systemctl enable rabbitmq-server.service
rabbitmqctl add_user openstack openstack
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
rabbitmq-plugins
rabbitmq-plugins enable rabbitmq_management
帐号密码 guest guest
memcached 作认证服务的缓存令牌
可以定义缓存时间,不用占用
yum install memcached python-memcached -y
vim /etc/sysconfig/memcached
注释最后一行
systemctl enable memcached
systemctl start memcached
openstack keystone
使用 mysql创建
mysql -pwestos
CREATE DATABASE keystone;
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' \
IDENTIFIED BY 'keystone';
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' \
IDENTIFIED BY 'keystone';
将上面localhost 还为 % 在一次
openssl rand -hex 10
初始化admin token
yum install openstack-keystone httpd mod_wsgi
vim /etc/keystone/keystone.conf
[defalut]
admin_token = 99b18dca176a77a7b4b5
[database]
connection = mysql+pymysql://keystone:[email protected]/keystone
[token]
provider = fernet
su -s /bin/sh -c "keystone-manage db_sync" keystone
mysql -pwestos
use keystone
show tables;
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
ll /etc/keystone/
有下面就会成功
fernet-keys
启动服务apache
vim /etc/httpd/conf/httpd.conf
/ServerName
ServerName controller
vim /etc/httpd/conf.d/wsgi-keystone.conf
Listen 5000
Listen 35357
<VirtualHost *:5000>
WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-public
WSGIScriptAlias / /usr/bin/keystone-wsgi-public
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
ErrorLogFormat "%{cu}t %M"
ErrorLog /var/log/httpd/keystone-error.log
CustomLog /var/log/httpd/keystone-access.log combined
<Directory /usr/bin>
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:35357>
WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-admin
WSGIScriptAlias / /usr/bin/keystone-wsgi-admin
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
ErrorLogFormat "%{cu}t %M"
ErrorLog /var/log/httpd/keystone-error.log
CustomLog /var/log/httpd/keystone-access.log combined
<Directory /usr/bin>
Require all granted
</Directory>
</VirtualHost>
systemctl enable httpd
systemctl start httpd
配置服务
yum install python-openstackclient -y
先决条件
less keystone.conf
export OS_TOKEN=99b18dca176a77a7b4b5
export OS_URL=http://controller:35357/v3
export OS_IDENTITY_API_VERSION=3
openstack service create \
--name keystone --description "OpenStack Identity" identity
openstack endpoint create --region RegionOne \
identity public http://controller:5000/v3
openstack endpoint create --region RegionOne \
identity internal http://controller:5000/v3
openstack endpoint create --region RegionOne \
identity admin http://controller:35357/v3
openstack --help
openstack endpoint list
openstack user list
openstack service list
openstack domain create --description "Default Domain" default
openstack project create --domain default \
--description "Admin Project" admin
openstack user create --domain default \
--password admin admin
openstack role create admin
openstack role add --project admin --user admin admin
openstack project create --domain default \
--description "Service Project" service
openstack project create --domain default \
--description "Demo Project" demo
openstack user create --domain default \
--password demo demo
openstack role create user
openstack role add --project demo --user demo user
参考
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/keystone-users.html
下面参考桑面的 -verify
unset OS_TOKEN OS_URL
openstack --os-auth-url http://controller:35357/v3 \
--os-project-domain-name default --os-user-domain-name default \
--os-project-name admin --os-username admin token issue
admin
vim admin-openrc
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_AUTH_URL=http://controller:35357/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
vim demo-openrc
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=demo
export OS_USERNAME=demo
export OS_PASSWORD=demo
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
grep -v ^# /etc/keystone/keystone.conf |uniq
/\[token]
下面看你如何使用 如果用管理员使用下面第一个命令
source admin-openrc
source demo-openrc
##############################
. admin-openrc
[[email protected] ~]# openstack token issue
+------------+----------------------------------------------------------------------------------+
| Field | Value |
+------------+----------------------------------------------------------------------------------+
| expires | 2019-04-14T04:43:56.179535Z |
| id | gAAAAABcsqx8nWMvP64e9qV6MuFh5Xx02GXnC8iavmPpEGoBJ3wlvqo7UOIbjWGILuPbXBOQAWuZT41O |
| | AnDY7b1C1VPZ9fe1-FbhXU8aE_C6aMSuZX6xvo3CHBc2mYprjTn5eJ5BIuibXidvMNkM0UtzEoYIMZsq |
| | rz_S_bYYGwXmv1A01z6DU1g |
| project_id | 384460d6ae4d4c69b598262b081836d0 |
| user_id | 54dd35e3bed048b995994371d7d4ba93
创建glance
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance'; Query OK, 0 rows affected (0.00 sec)
openstack user create --domain default --password glance glance
openstack role add --project service --user glance admin
openstack role add --project service --user glance admin
openstack service create --name glance \
--description "OpenStack Image" image
openstack endpoint create --region RegionOne \
image public http://controller:9292
openstack endpoint create --region RegionOne \
image internal http://controller:9292
openstack endpoint create --region RegionOne \
image admin http://controller:9292
yum install openstack-glance -y
vim /etc/glance/glance-api.conf
[database]
connection = mysql+pymysql://glance:[email protected]/glance
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
[paste_deploy]
flavor = keystone
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
vim /etc/glance/glance-registry.conf
[database]
connection = mysql+pymysql://glance:[email protected]/glance
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
[paste_deploy]
flavor = keystone
su -s /bin/sh -c "glance-manage db_sync" glance
get cirros-0.3.5-x86_64-disk.img
systemctl enable openstack-glance-api.service \
openstack-glance-registry.service
systemctl start openstack-glance-api.service \
openstack-glance-registry.service
openstack image create "cirros" \
--file cirros-0.3.5-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--public
[[email protected] ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| c9c2e3bb-c108-4655-9074-6554f14fa587 | cirros | active |
+--------------------------------------+--------+--------+
计算节点
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/common/get_started_compute.html
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/nova-controller-install.html
mysql -u root -p
CREATE DATABASE nova_api;
CREATE DATABASE nova;
MariaDB [(none)]> CREATE DATABASE nova_api;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> CREATE DATABASE nova;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'nova';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'nova';
Query OK, 0 rows affected (0.00 sec)
. admin-openrc
openstack user create --domain default --password nova nova
openstack role add --project service --user nova admin
openstack service create --name nova \
--description "OpenStack Compute" compute
openstack endpoint create --region RegionOne \
compute public http://controller:8774/v2.1/%\(tenant_id\)s
openstack endpoint create --region RegionOne \
compute internal http://controller:8774/v2.1/%\(tenant_id\)s
openstack endpoint create --region RegionOne \
compute admin http://controller:8774/v2.1/%\(tenant_id\)s
yum install openstack-nova-api openstack-nova-conductor \
openstack-nova-console openstack-nova-novncproxy \
openstack-nova-scheduler
-y
vim /etc/nova/nova.conf
[vnc]
vncserver_listen = $my_ip
vncserver_proxyclient_address = $my_ip
[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = openstack
[oslo_concurrency]
lock_path = /var/lib/nova/tmp
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = nova
[glance]
api_servers = http://controller:9292
[database]
connection = mysql+pymysql://nova:[email protected]/nova
[api_database]
connection = mysql+pymysql://nova:[email protected]/nova_api
[DEFAULT]
enabled_apis = osapi_compute,metadata
rpc_backend = rabbit
auth_strategy = keystone
my_ip = 172.25.11.1
su -s /bin/sh -c "nova-manage api_db sync" nova
su -s /bin/sh -c "nova-manage db sync" nova
systemctl enable openstack-nova-api.service \
openstack-nova-consoleauth.service openstack-nova-scheduler.service \
openstack-nova-conductor.service openstack-nova-novncproxy.service
systemctl start openstack-nova-api.service \
openstack-nova-consoleauth.service openstack-nova-scheduler.service \
openstack-nova-conductor.service openstack-nova-novncproxy.service
安装和配置计算节点
server2 (compute1) 进行如下操作
yum install openstack-nova-compute -y
yum upgrade
vim /etc/nova/nova.conf
[DEFAULT]
rpc_backend = rabbit
auth_strategy = keystone
my_ip = 172.25.11.2 #自身compute1的IP
use_neutron = True
firewall_driver = nova.virt.firewall.NoopFirewallDriver
[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = openstack
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = nova
[vnc]
...
enabled = True
vncserver_listen = 0.0.0.0
vncserver_proxyclient_address = $my_ip
novncproxy_base_url = http://controller:6080/vnc_auto.html
[glance]
...
api_servers = http://controller:9292
[oslo_concurrency]
...
lock_path = /var/lib/nova/tmp
egrep -c '(vmx|svm)' /proc/cpuinfo
如果这个命令返回了 one or greater 的值,那么你的计算节点支持硬件加速且不需要额外的配置。
如果这个命令返回了 zero 值,那么你的计算节点不支持硬件加速。你必须配置 libvirt 来使用 QEMU 去代替 KVM
-
在 /etc/nova/nova.conf 文件的 [libvirt] 区域做出如下的编辑:
[libvirt]
...
virt_type = qemu
systemctl enable libvirtd.service openstack-nova-compute.service
systemctl start libvirtd.service openstack-nova-compute.service
[[email protected] ~]# . admin-openrc
[[email protected] ~]# openstack compute service list
网络服务
参考
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/common/get_started_networking.html
controller上
CREATE DATABASE neutron;
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' \
IDENTIFIED BY 'neutron';
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' \
IDENTIFIED BY 'neutron';
. admin-openrc
openstack user create --domain default --password neutron neutron
openstack role add --project service --user neutron admin
openstack service create --name neutron \
--description "OpenStack Networking" network
openstack endpoint create --region RegionOne \
network public http://controller:9696
openstack endpoint create --region RegionOne \
network internal http://controller:9696
openstack endpoint create --region RegionOne \
network admin http://controller:9696
yum install openstack-neutron -y
vim /etc/neutron/metadata_agent.ini
[DEFAULT]
...
nova_metadata_ip = controller
metadata_proxy_shared_secret = westos
这里选择公共网络
yum install openstack-neutron openstack-neutron-ml2 \
openstack-neutron-linuxbridge ebtables -y
vim /etc/neutron/neutron.conf
[database]
...
connection = mysql+pymysql://neutron:[email protected]/neutron
[DEFAULT]
core_plugin = ml2
service_plugins =
rpc_backend = rabbit
auth_strategy = keystone
notify_nova_on_port_status_changes = True
notify_nova_on_port_data_changes = True
[oslo_messaging_rabbit]
...
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = openstack
[keystone_authtoken]
...
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron
[nova]
...
auth_url = http://controller:35357
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
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan
tenant_network_types =
mechanism_drivers = linuxbridge
extension_drivers = port_security
[ml2_type_flat]
...
flat_networks = provider
[securitygroup]
...
enable_ipset = True
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = provider:eth1 #这里选择eth1
[vxlan]
enable_vxlan = False
[securitygroup]
...
enable_security_group = True
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
...
interface_driver = neutron.agent.linux.interface.BridgeInterfaceDriver
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = True
为计算节点配置网络服务
compute1
vim /etc/nova/nova.conf
[neutron]
url = http://controller:9696
auth_url = http://controller:35357
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 = westos
controller
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
systemctl restart openstack-nova-api.service
systemctl enable neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.service
systemctl start neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.service
neutron agent-list
neutron ext-list
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/launch-instance-networks-selfservice.html
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/launch-instance-networks-provider.html
计算节点的网络配置
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/neutron-compute-install.html
yum install openstack-neutron-linuxbridge ebtables ipset -y
yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables -y
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = provider:eth1
[vxlan]
enable_vxlan = False
[securitygroup]
...
enable_security_group = True
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
vim /etc/neutron/neutron.conf
[DEFAULT]
...
rpc_backend = rabbit
[oslo_messaging_rabbit]
...
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = openstack
[DEFAULT]
...
auth_strategy = keystone
[keystone_authtoken]
...
auth_uri = http://controller:5000
auth_url = http://controller:35357
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
vim /etc/nova/nova.conf
[neutron]
...
url = http://controller:9696
auth_url = http://controller:35357
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
systemctl restart openstack-nova-compute.service
# systemctl enable neutron-linuxbridge-agent.service
# systemctl start neutron-linuxbridge-agent.service
控制节点上
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/launch-instance-networks-provider.html
neutron net-create --shared --provider:physical_network provider \
--provider:network_type flat provider
neutron subnet-create --name provider \
--allocation-pool start=172.25.11.100,end=172.25.11.200 \
--dns-nameserver 114.114.114.114 --gateway=172.25.11.250 \
provider 172.25.11.0/24
openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
. demo-openrc
ssh-****** -q -N ""
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
openstack keypair list
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22 default
openstack flavor list
[[email protected] ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| c9c2e3bb-c108-4655-9074-6554f14fa587 | cirros | active |
+--------------------------------------+--------+--------+
[[email protected] ~]# openstack network list
+--------------------------------------+----------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+----------+--------------------------------------+
| 3404c6a4-0fea-4e1a-9da9-a229001ae746 | provider | fcc4e120-5673-478a-a43b-ad5cc39f1d6b |
+--------------------------------------+----------+--------------------------------------+
[[email protected] ~]# openstack security group list
+--------------------------------------+---------+------------------------+----------------------------------+
| ID | Name | Description | Project |
+--------------------------------------+---------+------------------------+----------------------------------+
| 1bec09c1-4fc9-4092-b14d-40ca612b5a42 | default | Default security group | b5df2514678d41f58b20788d14968f93 |
+--------------------------------------+---------+------------------------+----------------------------------+
更新虚拟机qemu版本
[[email protected] qemu]# ls
libcacard-2.5.2-2.1.el7.x86_64.rpm qemu-kvm-common-ev-2.6.0-28.el7.10.1.x86_64.rpm
qemu-img-ev-2.6.0-28.el7.10.1.x86_64.rpm qemu-kvm-ev-2.6.0-28.el7.10.1.x86_64.rpm
compute1:
vim /etc/nova/nova.conf
[libvirt]
cpu_mode = none
systemctl restart openstack-nova-compute
net-id选择 openstack network list 的
openstack server create --flavor m1.nano --image cirros --nic net-id=1bec09c1-4fc9-4092-b14d-40ca612b5a42 --security-group default --key-name mykey server1
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/launch-instance.html
openstack server stop server1
openstack console url show server1
openstack server list
帐号密码
cirros
cubswin:)
controller上免密
使用图形 dashboard
参考
https://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/horizon-install.html
里面的timezoen 改为 Asia/Shanghai
这里不能添加网络,修改下面即可
[[email protected] ~]# vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2_type_vxlan]
#
vni_ranges = 1:1000 #在配置文件中增加vni_ranges = 1:1000
然后访问
http://172.25.11.1/dashboard/auth/login/?next=/dashboard/
计算节点
etc/neutron/plugins/ml2/linux...
[vxlan]
enable_vxlan = True
local_ip = 172.25.11.2
l2_population = True
[[email protected] ~]# systemctl restart neutron-server neutron-linuxbridge-agent neutron-dhcp-agent neutron-metadata-agent neutron-l3-agent
首先admin 建立公网 public
demo下建立vm1云主机
然后 建立私网 192.168.0.0
然后建立路由 添加私网端口
再把私有网络在admin下共享出去
再次添加虚拟主机,使用私有网端
再绑定浮动ip即可
systemctl restart neutron-server neutron0linuxbridge-agent netron-dhcp-agent neutron-metadata-agent