Linux系统mock环境搭建详解

Linux系统mock环境搭建详解

简介

mock是linux下创建chroot环境的工具,可以方便的进行RPM构建。

Mock和rpmbuild的区别与联系

mock编包一般是做发行版本给别人使用,当然你做的软件要能在别人机器上跑,那么在开发过程中,我们必须模拟一个纯净的用户环境(即是所谓的chroot),mock在编包前先构建一个这样的用户环境,然后里面再使用rpmbuild的机制编包。

mock环境的搭建

1.安装mock、rpm-build

[root@localhost ~]# yum install mock rpm-build -y

2、将root用户加入mock组

[root@localhost ~]# usermod -a -G mock root

3、mock的使用,需要准备相应的cfg文件,该文件会定义mock系统的规格。
在默认的路径/etc/mock下会存在众多的mock配置文件,如果需要在mock用户下执行的时候,需要将文件加入到mock组中。

[root@localhost mock]# chown root:mock /etc/mock/mock_leaning.cfg

4、生成配置文件/etc/mock/mock_learning.cfg(已对接阿里的yum镜像源)

[root@localhost mock]# cat /etc/mock/mock_leaning.cfg
config_opts['root'] = 'mock_learning_centos7-x86_64'
config_opts['target_arch'] = 'x86_64'
config_opts['legal_host_arches'] = ('x86_64',)
config_opts['chroot_setup_cmd'] = 'install basesystem rpm-build python2-devel gcc make python-sqlalchemy python-webob ghostscript graphviz python-sphinx python-eventlet python-six python-pbr python3-pbr openstack-macros git yum-plugin-priorities rubygems'
config_opts['dist'] = 'el7'  # only useful for --resultdir variable subst
config_opts['releasever'] = '7'
config_opts['plugin_conf']['ccache_enable'] = False
config_opts['priorities.conf'] = """
[main]
enabled = 1
check_obsoletes = 1
"""
 
config_opts['yum.conf'] = """
[main]
keepcache=1
debuglevel=2
reposdir=/dev/null
logfile=/var/log/yum.log
retries=20
obsoletes=1
gpgcheck=0
assumeyes=1
plugins=1
syslog_ident=mock
syslog_device=
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
"""

5、生成mock系统

[root@localhost mock]# cd /etc/mock/
[root@localhost mock]# ll | grep mock_leaning
-rw-r--r-- 1 root root  3399 Sep 15 09:15 mock_leaning.cfg
[root@localhost mock]# mock -r mock_leaning.cfg --init
INFO: mock.py version 1.2.17 starting (python version = 2.7.5)...
Start: init plugins
INFO: selinux disabled
Finish: init plugins
Start: run
Start: clean chroot
Finish: clean chroot
Start: chroot init
INFO: calling preinit hooks
... ... (中间略)
  zip.x86_64 0:3.0-11.el7                                                                                 
  zlib.x86_64 0:1.2.7-17.el7                                                                              
 
Complete!
Finish: yum install
Start: creating cache
Finish: creating cache
Finish: chroot init
INFO: Installed packages:
Finish: run

6、查看生成的mock os:

[root@localhost root]# cd /var/lib/mock/
[root@localhost mock]# du * -sh | grep mock_learning
693M	mock_learning_centos7-x86_64

7、退出时使用exit,或者执行ctrl+d

8、mock构建RPM包详细命令请参考博客:链接地址

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值