自动化部署必备技能-定制 RPM 包
记录 rpm 制作过程。
开始
https://www.zyops.com/autodeploy-rpm/
https://www.zyops.com/autodeploy-yum/
http://192.168.1.20/rpmsrc/#%E4%BD%BF%E7%94%A8rpmbuild%E6%9E%84%E5%BB%BArpm%E5%8C%85
https://www.jianshu.com/p/50ff4ecf3530
https://cache.echoxu.cn/blogimg/max-rpm.pdf
https://fpm.readthedocs.io/en/latest/
https://juejin.cn/post/6844903895873880077
https://blog.csdn.net/zyhse/article/details/111356756
https://www.xiexianbin.cn/linux/rpm/2017-12-16-rpm-mock/index.html 介绍 mock + rpmbuild
https://yanyixing.github.io/2018/09/25/rpm-mock/
https://wizardforcel.gitbooks.io/vbird-linux-basic-4e/content/197.html
spec: https://juejin.cn/post/6844903987896909837?share_token=4219407e-f747-4b7f-af4f-25f530bbc1b5
rpm: https://juejin.cn/post/7024098015895879716?share_token=66c2c12a-7ffe-45ce-8ac7-2e9e988a910c
通常我们都是在现有系统的环境中,对当前硬件平台的软件进行编译为RPM 的工作。但由于各种原因,例如硬件不支持,机器不够,磁盘空间问题等,我们可能需要进行跨平台编译的工作。类似的,为不同发行版进行编译也是常有的问题。Mock 是一套在Fedora 上用于实现跨平台、跨版本编译RPM的工具,其支持Build FC1-6、RH7.3、RH9、RHEL3-5、CentOS 1-5 等平台工作。我现用于在Asianux 3.0 上。
一、关于Mock
Mock 是Fedora Projects 其中一个项目,主要用于实现chroot 环境下,编译RPM 的工作。其原理是通过Yum 获取指定发行版、指定平台的rpm 包,解压后,以chroot 的环境进行编译。因此,可以实现在x86_64 环境下,编译i386 平台软件的功能。
官网地址:这里
下载地址:点击,从此地址可知,1.0 以下版本适用于FC1-6、 EL5平台,1.1 支持F-13+ 和 EL-6 环境。
Linux 手册
https://docs.centos.org/en-US/docs/
https://wiki.centos.org/
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7
https://access.redhat.com/products/
- Linux 安装手册
- Linux ISO 制作
- https://wiki.centos.org/HowTos
- https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-virtualization/
systemed 开机服务
[iechoxu@localhost-live system]$ more sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
# https://blog.csdn.net/z1026544682/article/details/93473876
# https://cloud.tencent.com/developer/article/1516125
# https://wizardforcel.gitbooks.io/vbird-linux-basic-4e/content/150.html
# https://juejin.cn/post/6970548014804893726
# https://cloud.tencent.com/developer/article/1392120
# https://www.jianshu.com/p/c999eefbc197
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Systemd/
fpm:
centos7.9 上需要通过 sci repo 来安装更高版本的 ruby
- 安装 sci repo 获得更新的 ruby
- sudo yum install centos-release-scl
- sudo yum install rh-ruby23 rh-ruby23-rubygems-devel rh-ruby23-rubygems rh-ruby23-ruby-devel
- scl enable rh-ruby23 bash
- 默认安装的 ruby 是 2.0 版本,和 gem install fpm 安装的 fpm 1.14 不兼容,打开 fpm --version 会报错,所以才有上面的方法来安装更新的 ruby
- 查找默认源:gem sources
- 添加新源并移除默认源:gem sources -a https://mirrors.aliyun.com/rubygems/ --remove https://rubygems.org/
- 移除默认源:gem sources --remove https://rubygems.org/ (此处可忽略)
- 更新gem版本:
gem update --system
- gem install fpm
- yum install rpm-build squashfs-tools
- 如果是 centos8 可通过
sudo yum install ruby rubygems ruby-devel rubygems-devel gcc rpm-build make -y
- gem install fpm
rpmbuild:
# create the makerpm account for building rpms only:
sudo useradd makerpm
sudo groupadd mock
sudo usermod -a -G mock makerpm sudo passwd makerpm
# install rpm build tools:
sudo yum install rpm-build redhat-rpm-config rpmdevtools
# install nginx's build requirements:
sudo yum install openssl-devel zlib-devel pcre-devel gcc make
# login as makerpm:
sudo su - makerpm
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
# make spec template
cd ~/rpmbuild/SPECS
rpmdev-newspec nginx
cp /path/to/openresty-packaging/rpm/SOURCES/* ~/rpmbuild/SOURCES/
cd ~/rpmbuild/SPECS
cp /path/to/openresty-packaging/rpm/SPECS/*.spec ./
for file in *.spec; do
spectool -g -R $file
rpmbuild -ba $file
done
# https://wiki.centos.org/HowTos/SetupRpmBuildEnvironment