Centos下用tar源碼包製作rpm包

來源:互聯網
上載者:User

公司有需求要求加密redis,本來是有個設定檔選項requirepass 可以設定密碼,但是公司覺得可以通過修改設定檔使密碼失效,感覺不安全,於是乎直接修改源碼(強制設定requirepass為固定密碼),做成rpm包就非常安全了

1.下載redis源碼包

http://redis.googlecode.com/files/redis-2.6.14.tar.gz

2.修改源碼編譯

tar zxvf redis-2.6.14.tar.gz

cd redis-2.6.14

vim src/config.c

把331行給刪除,移到else語句結束後,不管為不為空白都設定requirepass

server.requirepass = zstrdup("123456");  #加到426行

儲存退出,然後接下來編譯

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  RPMS  SOURCES  SPECS  SRPMS

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                                   build的目錄,會在這裡build出二進位

Source:%{name}-%{version}.tar.gz                                                                             源碼檔案的名稱,放在SOURCES目錄下 

Prefix:%{_prefix}                                                                                                          首碼,有這個值,包產生時候就有relocations。

Packager:nginx                                                                                                           包名稱

%description                                                                                                               下面是對包的描述

nginx-httpd-server        

%prep                                                                                                                          下面是準備工作

%setup -q                                                                                                                     這裡使用了內建命令,解開源碼包到BUILD目錄

%build                                                                                                                          開始建立包,對應於configure和make,在BUILD目錄

CFLAGS="-g"  ./configure  

make -j `cat /proc/cpuinfo | grep processor | wc -l`

%install                                                                                                                         安裝包到Buildroot

make DESTDIR=$RPM_BUILD_ROOT install 

%files                                                                                                                            最後,把檔案打包進rpm包,這裡指定要打包進去的檔案,許可權和屬主,這裡的目錄是相對於Buildroot的目錄,但是要以'/'開頭。

%defattr(755,daemon,daemon)

/usr/local/%{name}

%pre                                                                                                                             在用rpm命令安裝包前執行這裡的動作

echo nginx,preinstall

%post                                                                                                                             在用rpm命令安裝完後執行這裡的動作

echo nginx,afterinstall,done

%preun                                                                                                                           在卸載前執行這裡的動作

echo nginx,uninstall

%postun                                                                                                                          在卸載後執行這裡的動作

echo nginx,uninstall,done

---------------------------------------------end-----------------------------------------------------------------


這樣我們就可以定製自己的rpm包了

參考連結:http://zhumeng8337797.blog.163.com/blog/static/100768914201110185456104/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.