1.安装mock、rpm-build
[root@localhost ~]# yum install mock rpm-build -y
2.创建用户mockbuild、并加入mock组
[root@localhost ~]# useradd mockbuild
[root@localhost ~]# usermod -a -G mock mockbuild
3.切换到mockbuild组,并编译出centos7下的rpm包
mock初始环境的配置文件在/etc/mock下; 新创建的环境在/var/lib/mock/下
[root@localhost ~]# su mockbuild
[mockbuild@localhost SPECS]$ mock -r centos-7-x86_64 --init //创建新的mock环境/etc/mock下有配置文件
[mockbuild@localhost SPECS]$ mock -r centos-7-x86_64 --rebuild ~/ntfs-3g-2017.3.23-11.isoft.src.rpm //编译
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/
buildroot.lock result root
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/result/
build.log ntfs-3g-2017.3.23-11.el7.x86_64.rpm ntfs-3g-devel-2017.3.23-11.el7.x86_64.rpm root.log
ntfs-3g-2017.3.23-11.el7.src.rpm ntfs-3g-debuginfo-2017.3.23-11.el7.x86_64.rpm ntfsprogs-2017.3.23-11.el7.x86_64.rpm state.log
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/root/
bin boot builddir dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/root/builddir/
build
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/root/builddir/build/
BUILD BUILDROOT originals RPMS SOURCES SPECS SRPMS
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/root/builddir/build/RPMS/
ntfs-3g-2017.3.23-11.el7.x86_64.rpm ntfs-3g-devel-2017.3.23-11.el7.x86_64.rpm
ntfs-3g-debuginfo-2017.3.23-11.el7.x86_64.rpm ntfsprogs-2017.3.23-11.el7.x86_64.rpm
[mockbuild@localhost SPECS]$ ls /var/lib/mock/centos-7-x86_64/root/builddir/build/SRPMS/
ntfs-3g-2017.3.23-11.el7.src.rpm
***mock环境已经搭好,可以chroot . 到里面操作。保证系统的干净