说明: 实现用systemctl管理应用程序
安装包目录结构:
└── redis
├── install.sh
├── readme.txt
├── redis-cli
├── redis.conf
├── redis-server
└── redis.service
下面这三个是编译 redis 6.2.6 所得,在源码src目录下
├── redis-cli
├── redis.conf
├── redis-server
源码地址:https://github.com/redis/redis/archive/refs/tags/6.2.6.tar.gz
编译:
CentOS下编译使用systemd先安装 systemd-devel:yum install systemd-devel 然后: make USE_SYSTEMD=yes 然后: 从src目录中摘取出来
install.sh:
#!/bin/sh
d=`date "+%Y%m%d%S"`
InstallDir="/usr/local/redis"
chmod +x redis-server
if [ "$(id -u)" -ne 0 ] ; then
echo "You must run this script as root. Sorry!"
exit 1
fi
if [ -d $InstallDir ];then
echo "save old..."
mv $InstallDir $InstallDir.backup.$d
fi
echo "install..."
mkdir $InstallDir
mv ./* $InstallDir
cd $InstallDir
mv redis.service /etc/systemd/system/redis.service
echo "clean.."
if [ -f dump.rdb ];then
rm -rf dump.rdb
fi
rm -rf install.sh
cd - && cd .. && rm -rf redis
echo "init.."
systemctl daemon-reload
systemctl start redis
systemctl enable redis
echo
echo "redis 6.2.6 installed : $InstallDir"
redis.service:
[unit]
Description=redis-server
After=network.target
[Service]
Type=
ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf
PrivateTmp=true
Restart=always
RestartSec=1
[Install]
WantedBy=multi-user.target
readme.txt
service of Redis 6.2.6
start: systemctl start redis
stop: systemctl stop redis
restart: systemctl restart redis
然后压缩:
tar -zcvf redisInstall.tar.gz redis
使用(不要放到/usr/local目录安装):
tar -xvf redisInstall.tar.gz
cd redis
./install.sh
结果: 设置了systemctl管理,安装程序到 /usr/local/redis,查看状态如下,然后就是关注配置了
[root@localhost redisInstallPackageMake]
● redis.service
Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2021-10-18 21:10:01 CST; 17s ago
Main PID: 354333 (redis-server)
CGroup: /system.slice/redis.service
└─354333 /usr/local/redis/redis-server 127.0.0.1:6379
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.497 * Running mode=standalone, port=6379.
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.497
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.497
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.497
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.497 * Loading RDB produced by version 6.2.6
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.498 * RDB age 0 seconds
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.498 * RDB memory usage when created 0.77 Mb
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.498
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.498 * DB loaded from disk: 0.000 seconds
10月 18 21:10:01 localhost.localdomain redis-server[354333]: 354333:M 18 Oct 2021 21:10:01.498 * Ready to accept connections
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost redisInstallPackageMake]
原创内容,转载请附带原文地址:https://blog.csdn.net/weixin_44328568/article/details/120834549。
|