公司有需求要求加密redis,原本是有个配置文件选项requirepass 能够设置密码,可是公司以为能够经过修改配置文件使密码失效,因而乎直接修改源码(强制设置requirepass为固定密码),作成rpm包就很是安全了html
1.下载redis源码包nginx
http://redis.googlecode.com/files/redis-2.6.14.tar.gzweb
2.修改源码编译redis
tar zxvf redis-2.6.14.tar.gzvim
cd redis-2.6.14安全
vim src/config.cide
把331行给删除,移到else语句结束后,无论为不为空都设置requirepasspost
server.requirepass = zstrdup("123456");
保存退出,而后接下来编译google
make
\cp src/redis-server /usr/local/bin/
\cp src/redis-cli /usr/local/bin/
3.制做rpm包
mv redis-2.6.14.tar.gz /usr/src/redhat/SOURCES
cd /usr/src/redhat/SPECS/
vim redis.spec
Summary:the first rpm package
Name:redis
Version:2.6.14
Release:2
Vendor:zhangrenfang@gmail.com
License:Share
Group:Applications/Text
Source:redis-2.6.14.tar.gz
% description
my test redis crypto
%prep
tar -zxvf /usr/src/redhat/SOURCES/redis-2.6.14.tar.gz
%build
cd /usr/src/redhat/BUILD/redis-2.6.14
make
%clean
rm -rf /usr/src/redhat/BUILD/redis-2.6.14
%files
% defattr(-,root,root)
/usr/local/bin/redis-cli
/usr/local/bin/redis-server
[root@localhost SPECS]# rpmbuild -ba redis.spec
若运行没有错误,则产生,/usr/src/redhat/SRPMS/redis-2.6.14-2.src.rpm和/usr/src/redhat/RPMS/x86_64/redis-2.6.14-2.x86_64.rpm
rpm -qpi redis-2.6.14-2.x86_64.rpm能够查看到包的信息
relocations:若是非空,表示包能够安装到新的目录。在安装包的时候,使用--relocate=/usr/loca/=/home/cyx/ 这样来修改包的安装位置。
不过可能不能使用,由于包是二进制的,可能程序编译的时候使用了绝对路径。
rpm包制做由rpmbuild来生成。rpmbuild用到了几个目录:
BUILD
BUILD:build过程执行的目录
RPMS:最后生成的RPM包的位置
SOURCES:源文件位置
SPECS:spec文件的位置,rpmbuild使用spec文件的描述信息来build包
SRPMS:源代码rpm包的位置
spec文件是指导rpmbuild生成包的关键文件。放在SPECS目录下面:
----------------------------------example------------------------------------------------------------------
[root@v092019 SPECS]# cat nginx-0.8.54.spec
Name:nginx
Summary:nginx-server!
Version:0.8.54
Release:1
Group:taobao.com
License:GPL
URL:http://www.nginx.com/
BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root
Source:%{name}-%{version}.tar.gz
Prefix:%{_prefix}
Packager:nginx
% description
nginx-httpd-server
%prep
%setup -q
%build
CFLAGS="-g"
make -j `cat /proc/cpuinfo | grep processor | wc -l`
%install
make DESTDIR=$RPM_BUILD_ROOT install
%files
% defattr(755,daemon,daemon)
/usr/local/%{name}
%pre
echo nginx,preinstall
%post
echo nginx,afterinstall,done
%preun
echo nginx,uninstall
%postun
echo nginx,uninstall,done
---------------------------------------------end-----------------------------------------------------------------
这样咱们就能够定制本身的rpm包了
参考连接:http://zhumeng8337797.blog.163.com/blog/static/100768914201110185456104/