OpenStack配置文件的快速修改方法

568 阅读3分钟

这是我参与8月更文挑战的第13天,活动详情查看:8月更文挑战


初次参照官网部署OpenStack时,需要进行配置文件需要编辑修改,涉及文件众多,路径不一。为方便提高修改编辑的效率,往往会使用配置文件编辑器。下面介绍笔者在部署时使用到的2个配置文件编辑器。

Tools1:crudini

1.安装

官方下载地址: Crudini Download for Linux (deb, rpm)

  • 在Ubuntu操作系统上,可以直接命令行安装crudini:
$ sudo apt-get install crudini
  • CentOS Linux中没有这个命令行工具,可以这样安装
TypeURL
Mirrordownload-ib01.fedoraproject.org
Binary Packagecrudini-0.9-1.el7.noarch.rpm
Source Packagecrudini-0.9-1.el7.src.rpm
# Download latest epel-release rpm from
# http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/
wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/c/crudini-0.9-1.el7.noarch.rpm
# Install epel-release rpm:
rpm -Uvh *noarch.rpm
# Install crudini rpm package:
yum install crudini

2.使用

例子: 博主在部署V版本OpenStack(OpenStack Victoria版安装部署系列教程)的部署教程中使用的正是crudini安装使用

使用crudini,crudini不带参数,会有使用方法的提示。

  • 基本操作
crudini --set [--existing] config_file section [param] [value]
        --get [--format=sh|ini|lines] config_file [section] [param]
        --del [--existing] config_file section [param]
        --merge [--existing] config_file [section]
  • 作者示例
#添加/修改一个变量
crudini --set config_file section parameter value
#修改一个现有的变量
crudini --set --existing config_file section parameter value
#将shell中的变量写入配置文件
echo name="$name" | crudini --merge config_file section
#将两个ini文件合并
crudini --merge config_file < another.ini
#删除一个变量
crudini --del config_file section parameter
#删除一个配置段落
crudini --del config_file section
#输出一个参数值
crudini --get config_file section parameter
#输出一个不属于任何一个配置段落的全局变量值 
crudini --get config_file '' parameter
#输出一个配置段落
crudini --get config_file section
#以shell可以处理的格式输出一个配置段落
eval $(crudini --get --format=sh config_file section)
#以文本编辑工具可以处理的格式输出一个配置文件
crudini --get --format=lines config_file

3.介绍

A utility for easily handling ini files from the command line and shell scripts.

在OpenStack部署过程中,两个非常相像的命令:crudiniopenstack-config。它们都是Pádraig Brady用Python开发的、用来对配置文件(即.ini文件)进行编辑的工具。它们是同一个命令,有两个名字而已。

Pádraig Brady是Linux和OpenStack项目的代码贡献者。根据搜索到的资料推测,他在OpenStack项目中开发了openstack-config,后来感觉这个工具很有用,便将其改名为crudini。2013年9月27日,OpenSuse邮件列表中显示,openstack-config这个命令正式更名为crudini

我们都知道,crud是4个单词的首字母简写,即create、read、update和delete,中文译为“增删改查”。这个是数据的最常见的4类操作方法。有些软件的配置文件采用的是ini格式,如php.ini。这样的配置文件往往会成若干个段落。段落以[default]之类的格式标识。具体的配置条目则为:datadir=/var/lib/data形式。一个名叫myconfig.ini的文件可能会显示如下:

[default]
cmdline=/usr/bin/mycmd
datadir=/var/lib/mydata

如果我将datadir修改成/usr/lib/mydata,则要这样修改:

crudini --set myconfig.ini default datadir /usr/lib/mydata

介绍、官方资源位置、csdn下载、安装方法、使用方法、例子

Tools2:openstack-utils

1.安装

资源地址: RPM resource openstack-utils GitHub:openstack-utils

博主在部署T版本OpenStack(OpenStack Train版离线安装部署系列教程)时使用openstack-utils工具包,进行快速配置可以参考:安装使用

wget http://www.rpmfind.net/linux/opensuse/tumbleweed/repo/oss/noarch/openstack-utils-2017.11+git.1480685772.571a0f8-1.1.noarch.rpm

安装

rpm -ivh *.noarch.rpm
yum install openstack-utils -y

2.使用

openstack-config --set  /etc/nova/nova.conf DEFAULT enabled_apis  osapi_compute,metadata
openstack-config --set  /etc/nova/nova.conf DEFAULT my_ip 192.168.1.81【注意修改为本机管理网的IP地址】
openstack-config --set  /etc/nova/nova.conf DEFAULT use_neutron  true 
openstack-config --set  /etc/nova/nova.conf DEFAULT firewall_driver  nova.virt.firewall.NoopFirewallDriver
openstack-config --set  /etc/nova/nova.conf DEFAULT transport_url  rabbit://openstack:openstack@controller
[root@controller ~]# openstack-config --help
A utility for manipulating ini files

Usage: crudini --set [OPTION]...   config_file section   [param] [value]
  or:  crudini --get [OPTION]...   config_file [section] [param]
  or:  crudini --del [OPTION]...   config_file section   [param] [list value]
  or:  crudini --merge [OPTION]... config_file [section]

Options:

  --existing[=WHAT]  For --set, --del and --merge, fail if item is missing,
                       where WHAT is 'file', 'section', or 'param', or if
                       not specified; all specified items.
  --format=FMT       For --get, select the output FMT.
                       Formats are sh,ini,lines
  --inplace          Lock and write files in place.
                       This is not atomic but has less restrictions
                       than the default replacement method.
  --list             For --set and --del, update a list (set) of values
  --list-sep=STR     Delimit list values with "STR" instead of " ,"
  --output=FILE      Write output to FILE instead. '-' means stdout
  --verbose          Indicate on stderr if changes were made
  --help             Write this help to stdout
  --version          Write version to stdout

3.介绍

Utilities to aid the setup and configuration of OpenStack packages. - openstack-config - Manipulate the openstack ini files - openstack-db - Setup or delete the database for a specified service - openstack-status - Give an overview of the status of installed services

参考链接 [1]ini配置文件编辑器crudini [2]crudini-0.9-1.el7.noarch.rpm [3]crudini命令 – 操纵ini文件