Redis packaging (FPM tool)

1. Download the redis source code package

wget https://download.redis.io/releases/redis-6.2.5.tar.gz

2. Download the compilation tools and dependencies (gcc version must be 9 or above, the default installed gcc version is 4.8.5)

#1、安装scl,它可以在不覆盖原有软件包的情况下与其共存,缺点就是仅支持64位
yum -y install centos-release-scl
 
#2、安装gcc,其中的9表示大版本号,默认安装大版本下的最新稳定版本
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
 
#3、使用以下命令临时启动gcc,这种方式适用于临时切换系统的gcc版本,即开即用,仅在当前bash中有效,重启虚拟机就又变成4.8.5了
scl enable devtoolset-9 bash
 
#4、使用以下命令永久启动gcc,这种方式适用于长期使用该版本进行编译,切换bash依然有效
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
 
#查看gcc环境
gcc -v

3. Unzip the source code package

tar -zxvf redis-6.2.5.tar.gz -C ~/

4. Enter the decompressed directory and compile

cd ~/redis-6.2.5/
make

5. Compile and install

make PREFIX=/opt/redis install

6. Configure redis

Copy the conf file to the compiled bin directory

cp ~/redis-6.2.5/redis.conf /opt/redis/bin/

Modify the redis conf file

vim /opt/redis/bin/redis.conf

Modify the following:

#daemonize no 改为yes,开启后台运行,默认是前台运行
daemonize yes
 
#把这一行注释,监听所有IP
#bind 127.0.0.1
 
#protected-mode yes 如果改为no,则是关闭保护模式,这种模式下不能配置系统服务,建议还是开启
protected-mode yes
 
#requirpass,保护模式开启的时候要配置密码或者bind ip
requirepass 123456
 
#修改本参数,指定数据目录
dir /opt/redis/data/
 
#修改本参数,指定日志目录
logfile /opt/redis/logs/redis_6379.log

7.Install RAM Key

command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

8. Install RAM

curl -L get.rvm.io | bash -s stable

9. Update RAM configuration file

source /etc/profile.d/rvm.sh

10.Install Ruby2.6

rvm install 2.6

11. Check whether ruby ​​is installed successfully

ruby -v

12. Install fpm dependent modules

yum -y install rubygems ruby-devel

13. Replace rubygems warehouse

gem sources -a  http://mirrors.aliyun.com/rubygems/
gem sources --remove https://rubygems.org/
gem source list

14.Install fpm tool

gem install fpm

15. Check whether fpm is installed correctly

fpm --help

16.Write shell file

Write shell files according to your own needs,
such as: register redis files

vim ~/redis_RPM_Building.sh
#!/bin/bash
cat>/lib/systemd/system/redis.service<<-EOF
[Unit]
Description=Redis
After=network.target
 
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/redis/bin/redis-server /opt/redis/bin/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload

17. Packing

Packaging format:
fpm -s 源文件类型 -t 目标文件类型 -n 打包后名称 -v 打包后版本号 -d 所需要依赖 --post-install 安装完后执行的脚本 -f 源文件地址

fpm -s dir -t rpm -n redis -v 1.0.0 --post-install ~/redis_RPM_Building.sh -f /opt/redis

This code means to package the dir file type into an rpm type, with the generated name redis and version number 1.0.0. After the packaging is completed, the redis_RPM_Building.sh script is executed. After packaging, there is an rpm package with the same name in the current directory, and forced overwriting is performed to package the file source. For the /opt/redis directory.

Parameter Description:

1.-s specifies the source type
2.-t specifies the target type, that is, what package you want to make
3.-n specifies the name of the package
4.-v specifies the version number of the package
5.-d specifies which packages it depends on
6.- f If there is an installation package with the same name in the directory during the second packaging, it will be overwritten.
7. –post-install script to be run after the software package is installed; the same as –after-install

Possible errors:
●Need executable 'rpmbuild' to convert dir to rpm {:level=>:error}
Solution: Install rpm-build

yum install rpm-build -y

Guess you like

Origin blog.csdn.net/u013611126/article/details/124429895