控制节点部署见:OpenStack Rocky(R版) 部署手册 - 控制节点

部署环境

主机名IP系统部署模块
controller192.168.31.11CentOS 7 x86_64MySQL-server RabbitMQ-server memcached
etcd keystone glance nova-api placement neutron
node2192.168.31.12CentOS 7 x86_64nova-compute neutron-linuxbridge
node3192.168.31.13CentOS 7 x86_64nova-compute neutron-linuxbridge

环境准备

关闭防火墙

[root@node2 ~]# systemctl disable firewalld
[root@node2 ~]# systemctl stop firewalld

关闭 SELinux

[root@node2 ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled' /etc/selinux/config
[root@node2 ~]# setenforce 0

时间同步

[root@node2 ~]# yum install -y chrony
[root@node2 ~]# systemctl enable chronyd
[root@node2 ~]# systemctl start chronyd

Host 解析

192.168.31.11    controller
192.168.31.12    node2
192.168.31.13    node3

更新系统

[root@node2 ~]# yum upgrade -y

以 node2 为例,加入其它计算节点操作一样。

- 阅读剩余部分 -

部署环境

主机名IP系统部署模块
controller192.168.31.11CentOS 7 x86_64MySQL-server RabbitMQ-server memcached
etcd keystone glance nova-api placement neutron horizon
node2192.168.31.12CentOS 7 x86_64nova-compute neutron-linuxbridge
node3192.168.31.13CentOS 7 x86_64nova-compute neutron-linuxbridge

环境准备

关闭防火墙

[root@controller ~]# systemctl disable firewalld
[root@controller ~]# systemctl stop firewalld

关闭 SELinux

[root@controller ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@controller ~]# setenforce 0

时间同步

[root@controller ~]# yum install -y chrony
[root@controller ~]# systemctl enable chronyd
[root@controller ~]# systemctl start chronyd

Host 解析

192.168.31.11    controller
192.168.31.12    node2
192.168.31.13    node3

更新系统

[root@controller ~]# yum upgrade -y

- 阅读剩余部分 -

概述

关于XtraBackup

XtraBackup是由Percona公司开发的一款基于InnoDB的MySQL数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对InnoDB和XtraDB数据库进行热备的工具。其有如下特点:

  1. 备份过程快速、可靠;
  2. 备份过程不会打断正在执行的事务;
  3. 能够基于压缩等功能节约磁盘空间和流量;
  4. 自动实现备份检验;
  5. 还原速度快;

XtraBackup功能

  • 热备份
  • 增量备份
  • 备份到另一台MySQL服务器
  • 在MySQL服务器之间在线迁移表
  • 轻松创建新的从服务器
  • 备份时,不占用服务器资源

XtraBackup工作原理

XtraBackup是基于InnoDB的crash恢复功能。复制InnoDB数据文件,但是数据是不一致的,然后使用crash恢复让数据文件一致。当InnoDB启动时会去检查数据文件和日志文件,然后重做已提交事务,执行未提交事务。

XtraBackup记下LSN(Log Sequence Number),然后启动,复制数据文件。同时XtraBackup启动一个后台进程用来监控日志文件,然后复制修改,这个进程在备份期间一直是运行的,因为日志文件时回绕的,避免数据被覆盖无法恢复。直到备份完成。

第二阶段就是预备阶段,XtraBackup通过执行crash恢复,应用日志文件到数据文件上。等待复制InnoDB结束,然后执行FLUSH TABLES WITH READ LOCK,停止对mysql数据的修改。复制非innodb引擎表,直到复制完成,然后释放锁。

这样在prepare阶段后,InnoDB和非InnoDB相互保持了一致性。InnoDB会一直redo,直到备份完成。这个时间刚刚好和FLUSH TABLES WITH READ LOCK时间一直,所以InnoDB和非InnoDB是保持同步的。

- 阅读剩余部分 -

很有必要先说下注意事项:

  1. 严重声明大家在升级glibc时一定要特别特别特别的谨慎和小心,除非确定升级的必要,否则不要随意升级glibc,因为会带来很大的麻烦。
  2. 金牛座是在升级glibc后【姿势基本正确,但是这是不够的】,经过各种折腾,最后把系统玩死了【好在是虚拟机】,经过血的教训【不过,折腾有折腾的好,学到了很多LINUX动态库的有趣玩法,比如 pathelf 这个神器】,金牛座通过完全重装系统,梳理出了升级glibc的正确正确姿势,并分享给大家以防走弯路,请大家务必按严格按照本文的指令效仿操作。
  3. 很多人任性的升级glbc之后,普遍都会遇到一个类似问题就是:"......误删了/lib64/libc.so.6......",然后一番折腾虽然也能解决问题,但是事实上里面的痛苦谁折腾谁知道,根本原因就是安装姿势不正确,那么要是误删了怎么办,请自行google关键字【LD_PRELOAD】,它可以帮你起死回生。
  4. 不要在 glibc源码包里直接执行 ./configure 指令,否则你就等着被KO吧,假如安装包位置是: /path/to/glibc-2.15,正确的姿势是:

    mkdir -pv /path/to/glibc-2.15/build
    cd /path/to/glibc-2.15/build
    ../configure  参数1.... 参数2 ... 参数3...
  5. 不要将 glibc 安装到默认的目录【/usr/local】或者 【任何自定义的目录】,请务必安装到【/usr】目录,否则你就等着被KO吧。
  6. 最后建议大家每安装一个软件包,都要仔细阅读下源码包里的 README 以及 INSTALL 文档,很重要不解释。

查看系统默认的glibc版本:

[root@node1 ~]# /lib64/libc.so.6
GNU C Library stable release version 2.15, by Roland McGrath et al.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.7 20120313 (Red Hat 4.4.7-18).
Compiled on a Linux 2.6.32 system on 2018-06-30.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

编译安装glibc-2.15:

[root@node1 ~]# mkdir -pv /path/to/glibc-2.15/build
[root@node1 ~]# cd /path/to/glibc-2.15/
[root@node1 ~]# wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gz
[root@node1 ~]# tar xzvf glibc-2.15.tar.gz
[root@node1 ~]# cd /path/to/glibc-2.15/build
[root@node1 ~]# ../glibc-2.15/configure  --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
[root@node1 ~]# make
[root@node1 ~]# make install

shadow文件的格式就不说了。就说说它的第二列——密码列。

通常,passwd直接为用户指定密码就ok了。但在某些情况下,要为待创建的用户事先指定密码,还要求是加密后的密码,例如kickstart文件中的rootpw指令,ansible创建用户时提前指定密码等,这时候不得不手动生成合理的密码。

先说说shadow文件中第二列的格式,它是加密后的密码,它有些玄机,不同的特殊字符表示特殊的意义:

  • ①.该列留空,即"::",表示该用户没有密码。
  • ②.该列为"!",即":!:",表示该用户被锁,被锁将无法登陆,但是可能其他的登录方式是不受限制的,如ssh公钥认证的方式,su的方式。
  • ③.该列为"",即"::",也表示该用户被锁,和"!"效果是一样的。
  • ④.该列以"!"或"!!"开头,则也表示该用户被锁。
  • ⑤.该列为"!!",即":!!:",表示该用户从来没设置过密码。
  • ⑥.如果格式为"$id$salt$hashed",则表示该用户密码正常。其中$id$的id表示密码的加密算法,$1$表示使用MD5算法,$2a$表示使用Blowfish算法,"$2y$"是另一算法长度的Blowfish,"$5$"表示SHA-256算法,而"$6$"表示SHA-512算法,

目前基本上都使用sha-512算法的,但无论是md5还是sha-256都仍然支持。$salt$是加密时使用的salt,hashed才是真正的密码部分。

下文都以生成明文"123456"对应的加密密码为例。

要生成md5算法的密码,使用openssl即可。

[root@server1 ~]# openssl passwd -1 '123456'
[root@server1 ~]# openssl passwd -1 -salt 'abcdefg' '123456'

生成密码后,直接将其拷贝或替换到shadow文件的第二列即可。例如:替换root用户的密码

shell> field=$(awk -F ':' '/^root/{print $2}' /etc/shadow)
shell> password=$(openssl passwd -1 123456)
shell> sed -i '/^root/s%'$field'%'$password'%' /etc/shadow

但openssl passwd不支持生成sha-256和sha-512算法的密码。在CentOS 6上,可以借助grub提供的密码生成工具grub-crypt生成。

[root@server1 ~]# grub-crypt -h
Usage: grub-crypt [OPTION]...
Encrypt a password.

  -h, --help              Print this message and exit
  -v, --version           Print the version information and exit
  --md5                   Use MD5 to encrypt the password
  --sha-256               Use SHA-256 to encrypt the password
  --sha-512               Use SHA-512 to encrypt the password (default)

Report bugs to <[email protected]>.
EOF
[root@server1 ~]# grub-crypt --sha-512
Password: 
Retype password: 
$6$nt4hMDAYqYjudvfo$AKIZ3Z0o6/6HV6GKXqq21VEmh.ADFAZUQw2mvbIlplKx7gu9MQiEWjdmHnF2YPnYzgce1cP/bzDguVnUkMg/N.

grub-crypt其实是一个python脚本,交互式生成密码。以下是grub-crypt文件的内容。

[root@server1 ~]# cat /sbin/grub-crypt
#! /usr/bin/python

'''Generate encrypted passwords for GRUB.'''

import crypt
import getopt
import getpass
import sys

def usage():
    '''Output usage message to stderr and exit.'''
    print >> sys.stderr, 'Usage: grub-crypt [OPTION]...'
    print >> sys.stderr, 'Try `$progname --help\' for more information.'
    sys.exit(1)

def gen_salt():                      # 生成随机的salt
    '''Generate a random salt.'''
    ret = ''
    with open('/dev/urandom', 'rb') as urandom:
        while True:
            byte = urandom.read(1)
            if byte in ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
                        './0123456789'):
                ret += byte
                if len(ret) == 16:
                    break
    return ret

def main():
    '''Top level.'''
    crypt_type = '$6$' # SHA-256
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'hv',
                                   ('help', 'version', 'md5', 'sha-256',
                                    'sha-512'))
    except getopt.GetoptError, err:
        print >> sys.stderr, str(err)
        usage()
    if args:
        print >> sys.stderr, 'Unexpected argument `%s\'' % (args[0],)
        usage()
    for (opt, _) in opts:
        if opt in ('-h', '--help'):
            print (
'''Usage: grub-crypt [OPTION]...
Encrypt a password.

  -h, --help              Print this message and exit
  -v, --version           Print the version information and exit
  --md5                   Use MD5 to encrypt the password
  --sha-256               Use SHA-256 to encrypt the password
  --sha-512               Use SHA-512 to encrypt the password (default)

Report bugs to <[email protected]>.
EOF''')
            sys.exit(0)
        elif opt in ('-v', '--version'):
            print 'grub-crypt (GNU GRUB 0.97)'
            sys.exit(0)
        elif opt == '--md5':
            crypt_type = '$1$'
        elif opt == '--sha-256':
            crypt_type = '$5$'
        elif opt == '--sha-512':
            crypt_type = '$6$'
        else:
            assert False, 'Unhandled option'
    password = getpass.getpass('Password: ')
    password2 = getpass.getpass('Retype password: ')
    if not password:
        print >> sys.stderr, 'Empty password is not permitted.'
        sys.exit(1)
    if password != password2:
        print >> sys.stderr, 'Sorry, passwords do not match.'
        sys.exit(1)
    salt = crypt_type + gen_salt()
    print crypt.crypt(password, salt)      # 生成最终的加密密码

if __name__ == '__main__':
    main()

很不幸,CentOS 7上默认安装的是grub2,它不提供grub-crypt。因此参照grub-crypt内容,使用下面的python语句简单代替grub-crypt,这同样也是交互式的。

python -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())'

如果不想交互式,再改成如下形式:

[root@server1 ~]# python -c 'import crypt,getpass;pw="123456";print(crypt.crypt(pw))'

现在就方便多了,直接将结果赋值给变量即可。

[root@server1 ~]# a=$(python -c 'import crypt,getpass;pw="123456";print(crypt.crypt(pw))')
[root@server1 ~]# echo $a
$6$uKhnBg5A4/jC8KaU$scXof3ZwtYWl/6ckD4GFOpsQa8eDu6RDbHdlFcRLd/2cDv5xYe8hzw5ekYCV5L2gLBBSfZ.Uc166nz6TLchlp.

例如,ansible创建用户并指定密码:

a=$(python -c 'import crypt,getpass;pw="123456";print(crypt.crypt(pw))')
ansible  192.168.100.55 -m user -a 'name=longshuai5 password="$a" update_password=always'