Author: Jin
Date: 20140610
System: CentOS release 6.5 (Final)html
06-09-2014c零:問題
配置文件問題,不打包使用的配置文件參考配置文件後綴.default
有個不替換操做 %config(noreplace) %{etcdir}/%{configfile} 新的安裝爲 /usr/local/redis/etc/redis.conf.rpmnew
版本號更改: :%s/2.8.7/2.8.10/g 通常軟件,遊戲代碼使用另外的python
1、基本流程
1.環境
yum -y install gcc-c++ gperf ncurses-devel readline-devel time zlib-devel cmake libaio-devel autoconf make
yum -y install rpm-buildmysql
2.基本目錄
會安裝到每一個用戶的home目錄下,指定到其餘地方,build的時候也會到home
cd ~
mkdir rpmbuild/SOURCES
mkdir rpmbuild/RPMSlinux
3.HttpServer提供yum源
# yum -y install nginx
# vim /etc/nginx/conf.d/default.conf
location /RPMS {
index index.htm index.html;
autoindex on;
autoindex_localtime on;
access_log /var/log/nginx/rpms-access.log;
}
# ln -s /usr/share/nginx/html/RPMS /root/rpmbuild/RPMS
# /etc/init.d/nginx start
# chkconfig nginx onnginx
4.源碼
[root@kdc ~]# ls -1 rpmbuild/SOURCES/
mysql-5.5.38.tar.gz
redis-2.8.10.tar.gz
redis-2.8.7.tar.gc++
5.SPEC文件
# ls -1 rpmbuild/SPECS/
mysql.spec
redis.specgit
6.建立
rpmbuild -ba rpmbuild/SPECS/redis.specgithub
7.更新repo
createrepo rpmbuild/RPMS/x86_64/
# createrepo rpmbuild/RPMS 錯誤
建立的目錄別弄錯了web
8.client配置repo
# cat /etc/yum.repos.d/jincom.repo
[jincom]
name=jincomgames
baseurl=http://192.168.201.254/RPMS/$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-releaseredis
9.client安裝更新回滾
yum --enablerepo=jincom install redis-2.8.7
yum --enablerepo=jincom install redis-2.8.10
yum --enablerepo=jincom downgrade redis-2.8.7
yum --enablerepo=jincom clean metadata
yum --enablerepo=jincom cleanall
yum --enablerepo=jincom makecache
http://192.168.201.254/RPMS/x86_64/redis-2.8.7-1.x86_64.rpm: [Errno -1] Package does not match intended download. Suggestion: run yum --enablerepo=jincom clean metadata
Trying other mirror.
包裝不符合預期下載
Error Downloading Packages:
redis-2.8.7-1.x86_64: failure: redis-2.8.7-1.x86_64.rpm from jincom: [Errno 256] No more mirrors to try.
緣由
[root@kdc ~]# ll rpmbuild/RPMS/x86_64/
total 21096
-rw-r--r-- 1 root root 20028619 Jun 6 2014 mysql-5.5.38-0.x86_64.rpm
-rw-r--r-- 1 root root 795230 Jun 6 15:13 redis-2.8.10-1.x86_64.rpm
-rw-r--r-- 1 root root 769191 Jun 6 15:18 redis-2.8.7-1.x86_64.rpm
drwxr-xr-x 2 root root 4096 Jun 6 12:57 repodata
[root@kdc ~]# ll rpmbuild/RPMS/
total 8
drwxr-xr-x 2 root root 4096 Jun 6 15:19 repodata
drwxr-xr-x 3 root root 4096 Jun 6 15:18 x86_64
[root@kdc ~]# rm -rf rpmbuild/RPMS/repodata/
個人源指向http://192.168.201.254/RPMS/x86_64/
因此應該在RPMS/x86_64/建立依賴
# createrepo rpmbuild/RPMS/x86_64/
2、 SPEC文件
1.解釋
###按期全局變量
%global pkgname redis
%define binfile redis-server redis-cli redis-check-aof redis-check-dump redis-sentinel redis-benchmark
###信息部分
Name: %{pkgname}
Version: 2.8.10
Release: 1
Summary: %{pkgname}-%{version} on centos6.5 for jincomgames
Group: Databases
License: GPL
URL: http://download.redis.io/releases/redis-2.8.10.tar.gz
Packager: diege@foxmail.com
BuildArch: x86_64
Source: redis-2.8.10.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: %{distro_buildreq} #構建包時候一塊兒來的軟件
Requires: %{distro_requires} # 該rpm包所依賴的軟件包名稱,能夠用>=或<=表示大於或小於某一特定版本,例如:libpng-devel >= 1.0.20 zlib
###本身作好放在rpmbuild/SOURCES/目錄下的文件,後面能夠install -p -m 0644 %{Source0}%
Source1: redis.conf-jincomgames
%description
redis for jincomgames
#預先準備工做
%prep
# 把源碼包解壓並放好,從rpmbuild/SOURCES解壓到rpmbuild/BUILD 注意源碼包是否有Releas
#%setup -n %{name}-%{version}-%{release}
%setup -n %{name}-%{version} #將軟件包解壓%{name}-%{version}目錄
###編譯
%build
#cmake或者./configure #mysql5.5沒有使用configue來配置了和make
#make MALLOC=libc
make -j 8
###安裝到rpmbuild/BUILDROOT/目錄,rpmbuild/BUILDROOT爲模擬的根目錄
%install
mkdir -p $RPM_BUILD_ROOT
#cd %{_builddir}/%{name}-%{version}-%{release}
cd %{_builddir}/%{name}-%{version}
make install
##build dir
install -p -d -m 0755 %{buildroot}%{bindir}
install -p -d -m 0755 %{buildroot}%{etcdir}
##build config file
install -p -m 0644 %{configfile} %{buildroot}%{etcdir}/%{configfile}.default
install -p -m 0644 %{Source1}% {buildroot}%{etcdir} #存放到SOURCE下面的文件
##build binary file
cd src
install -p -m 0750 %{binfile} %{buildroot}%{bindir} #多個文件
###安裝前作的工做,建立用戶,建立目錄等
%pre
#getent group %{group} > /dev/null || groupadd -r %{group}
##getent group %{pkggroup} > /dev/null || groupadd -g %{gid} %{pkggroup}
##getent passwd %{user} > /dev/null || \
# useradd -r -d ${userhome} -g %{pkggroup} \
## useradd -u %{uid} -g %{pkggroup} -d %{userhome} \
## -s /sbin/nologin -c %{comment} %{user}
###安裝以後建立datadir目錄,啓動腳本,建立用戶等操做
%post
test ! -d %{datadir} && mkdir -p %{datadir}
#test -d %{datadir} && chown -R %{user}:%{pkggroup} %{datadir}
#cd %{installdir}
#cp share/mysql/mysql.server /etc/rc.d/init.d/%{servicename}
#chmod 755 /etc/rc.d/init.d/%{servicename}
#chkconfig --add %{servicename
###卸載前作的操做,好比服務還在開啓的話關閉
%preun
#/etc/rc.d/init.d/%{servicename} stop
###卸載後作的操做,好比刪除開啓啓動,刪除啓動腳本,刪除用戶
%postun
#chkconfig --del %{servicename}
#rm /etc/rc.d/init.d/%{servicename} -f
#userdel -rf %{user} && groupdel %{pkggroup}
###清理rpmbuild/BUILDROOT 和 rpmbuild/BUILD下的解壓包
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT;
#[ -d %{_builddir}/%{name}-%{version}-%{release} ] && rm -rf %{_builddir}/%{name}-%{version}-%{release}
[ -d %{_builddir}/%{name}-%{version} ] && rm -rf %{_builddir}/%{name}-%{version}
#打包成rpm包,%file中用的是相對目錄,$RPM_BUILD_ROOT爲模擬的根目錄,沒有指定文件的話,默認所有打包
%files
%{installdir}/* #安裝目錄下所有打包
%config(noreplace) %{etcdir}/%{configfile} #不替換
#%dir %{nginx_confdir} #目錄
%defattr(-, root, root)
#%attr(700,%{nginx_user},%{nginx_group}) %dir %{nginx_home} 修改文件屬性,分別是(mode,owner,group),-表示默認值,對文本文件是0644,可執行文件是0755
%defattr(-, root, root) #默認權限
#列出不想打包到rpm中的文件當心,若是%exclude指定的文件不存在,也會出錯的。
#%exclude
#文檔
%doc
#變動日誌
%changelog
3、python的包
(一)pyhon
[root@kdc ~]# rpm -ivh rpmbuild/RPMS/x86_64/Python-2.7.7-1.x86_64.rpm
^C[root@kdc ~]# rpm -ivh rpmbuild/RPMS/x86_64/Python-2.7.7-1.x86_64.rpm
error: Failed dependencies:
/usr/local/bin/python is needed by Python-2.7.7-1.x86_64
(二)pypy
用2.7
1.pypy
依賴包
yum install \
gcc make python-devel libffi-devel lib-sqlite3-devel pkgconfig \
zlib-devel bzip2-devel ncurses-devel expat-devel \
openssl-devel gc-devel python-sphinx python-greenlet
2.編譯安裝
bunzip -d pypy-2.2.1-src.tar.bz2 |tar -xvf -D
cd pypy/goal
python ../../rpython/bin/rpython --opt=jit targetpypystandalone.py
要用2.7.3
暫時不去研究,
使用原來的
[root@gs01 ~]# yum --enablerepo=jincom install pypy
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pypy.x86_64 0:0.0.1-1 will be installed
--> Processing Dependency: /usr/local/bin/python for package: pypy-0.0.1-1.x86_64
--> Processing Dependency: /opt/pypy/bin/pypy for package: pypy-0.0.1-1.x86_64
--> Processing Dependency: /opt/pypy-2.2.1-linux_x86_64-portable/bin/pypy for package: pypy-0.0.1-1.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: pypy-0.0.1-1.x86_64
--> Processing Dependency: /opt/pypy/bin/pypy for package: pypy-0.0.1-1.x86_64
--> Processing Dependency: /opt/pypy-2.2.1-linux_x86_64-portable/bin/pypy for package: pypy-0.0.1-1.x86_64
--> Processing Dependency: /usr/local/bin/python for package: pypy-0.0.1-1.x86_64
--> Finished Dependency Resolution
Error: Package: pypy-0.0.1-1.x86_64 (jincom)
Requires: libX11.so.6()(64bit)
Error: Package: pypy-0.0.1-1.x86_64 (jincom)
Requires: /usr/local/bin/python
Error: Package: pypy-0.0.1-1.x86_64 (jincom)
Requires: /opt/pypy/bin/pypy
Error: Package: pypy-0.0.1-1.x86_64 (jincom)
Requires: /opt/pypy-2.2.1-linux_x86_64-portable/bin/pypy
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@gs01 ~]#
在用的版本
[root@localhost omg_serverpackage_201404]# ./pypy/bin/pypy
Python 2.7.6 (394146e9bb673514c61f0150ab2013ccf78e8de7, May 13 2014, 05:56:41)
[PyPy 2.3.0 with GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information
# cp -a pypy pypy-2.3.0
# tar -zcvf pypy-2.3.0.tgz pypy-2.3.0
[root@gs01 ~]# yum --enablerepo=jincom install pypy
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pypy.x86_64 0:2.3.0-1 will be installed
--> Processing Dependency: /opt/omg_serverpackage_201404/pypy/bin/pypy for package: pypy-2.3.0-1.x86_64
--> Processing Dependency: /opt/omg_serverpackage_201404/pypy/bin/pypy for package: pypy-2.3.0-1.x86_64
--> Finished Dependency Resolution
Error: Package: pypy-2.3.0-1.x86_64 (jincom)
Requires: /opt/omg_serverpackage_201404/pypy/bin/pypy
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@gs01 ~]#
[root@kdc pypy]# pwd
/root/rpmbuild/BUILDROOT/pypy-2.3.0-1.x86_64/usr/local/pypy
# grep -r -n 'opt/omg_serverpackage_201404' *
包含了路徑
仍是得另外編譯啊
注意,Linux二進制程序都是動態連接的,像往常同樣,所以可能不會使用Linux二進制兼容性的悲慘的故事。這意味着Linux二進制程序只適用在發行版寫旁邊,除非你準備攻擊你的系統庫添加符號連接,它試圖打開。通常來講,咱們建議經過源代碼構建或下載你PyPy從你的供應商。家釀,Ubuntu(PPA),Debian MacPorts,Fedora,Gentoo和拱包PyPy,不一樣程度的是最新的。你可能有更多的運氣在吱吱做響的便攜式Linux二進制程序
pypy-2.3-linux_x86_64-portable.tar.bz2
https://bbuseruploads.s3.amazonaws.com/squeaky/portable-pypy/downloads/pypy-2.3-linux_x86_64-portable.tar.bz2?Signature=RKD4KYAN4B6M0OGppFstNsQDzg8%3D&Expires=1402114176&AWSAccessKeyId=0EMWEFSGA12Z1HF1TZ82
這個版本是移動版
根據提示
[root@kdc ~]# ./pypy-2.3-linux_x86_64-portable/bin/pypy
Python 2.7.6 (394146e9bb673514c61f0150ab2013ccf78e8de7, May 09 2014, 08:05:14)
[PyPy 2.3.0 with GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>>
[root@localhost omg_serverpackage_201404]# ./pypy/bin/pypy
Python 2.7.6 (394146e9bb673514c61f0150ab2013ccf78e8de7, May 13 2014, 05:56:41)
[PyPy 2.3.0 with GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>>
[PyPy 2.3.0 with GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
[PyPy 2.3.0 with GCC 4.8.2] on linux2
不一樣之處
在1.4上面解壓該包,而後看一下
# tar -xvf pypy-2.3-linux_x86_64-portable.tar
[root@localhost ~]# ./pypy-2.3-linux_x86_64-portable/bin/pypy
Python 2.7.6 (394146e9bb673514c61f0150ab2013ccf78e8de7, May 09 2014, 08:05:14)
[PyPy 2.3.0 with GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
GCC編譯版本不同
先測試能不能打包安裝模塊,有時間再去找版本
#%setup -n %{Source} 能夠解壓,可是要cd過去
Requires: /bin/sh /usr/bin/env /usr/local/bin/python libX11.so.6()(64bit) libbz2.so.1()(64bit) libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.2)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libcrypt.so.1()(64bit) libcrypt.so.1(GLIBC_2.2.5)(64bit) libdl.so.2()(64bit) libdl.so.2(GLIBC_2.2.5)(64bit) libgcc_s.so.1()(64bit) libgcc_s.so.1(GCC_3.0)(64bit) libgcc_s.so.1(GCC_3.3.1)(64bit) libm.so.6()(64bit) libm.so.6(GLIBC_2.2.5)(64bit) libncurses.so.5()(64bit) libpanel.so.5()(64bit) libpthread.so.0()(64bit) libpthread.so.0(GLIBC_2.2.5)(64bit) libpthread.so.0(GLIBC_2.3.2)(64bit) librt.so.1()(64bit) librt.so.1(GLIBC_2.2.5)(64bit) libsqlite3.so.0()(64bit) libtcl.so()(64bit) libtk.so()(64bit) libutil.so.1()(64bit) libutil.so.1(GLIBC_2.2.5)(64bit) libz.so.1()(64bit)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/pypy-2.3.0-1.x86_64
Wrote: /root/rpmbuild/SRPMS/pypy-2.3.0-1.src.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/pypy-2.3.0-1.x86_64.rpm
Error: Package: pypy-2.3.0-1.x86_64 (jincom)
Requires: libX11.so.6()(64bit)
Error: Package: pypy-2.3.0-1.x86_64 (jincom)
Requires: /usr/local/bin/python
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
[root@kdc ~]# rpm -qf /usr/lib64/libX11.so.6
libX11-1.5.0-4.el6.x86_6
#%define distro_buildreq gcc-c++ ncurses-devel perl readline-devel time zlib-devel cmake libaio-devel
%define distro_requires libX11 /usr/bin/python
Requires: %{distro_requires}
http://smilejay.com/2011/11/denpendency_need_python/
[root@kdc rpmbuild]# grep -r '/usr/local/bin/python' BUILD/pypy-2.3-linux_x86_64-portable/
BUILD/pypy-2.3-linux_x86_64-portable/lib-python/2.7/cgi.py:#! /usr/local/bin/python
BUILD/pypy-2.3-linux_x86_64-portable/lib-python/2.7/cgi.py:# NOTE: the above "/usr/local/bin/python" is NOT a mistake. It is
修改
BUILD/pypy-2.3-linux_x86_64-portable/lib-python/2.7/cgi.py
#! /usr/bin/python
打包Requires: /bin/sh /usr/bin/env /usr/bin/python變過了
%define distro_requires libX11
Requires: %{distro_requires}
yum --enablerepo=jincom install pypy
依賴解決
######################################
2.pypy
https://bbuseruploads.s3.amazonaws.com/squeaky/portable-pypy/downloads/pypy-2.3-linux_x86_64-portable.tar.bz2?Signature=RKD4KYAN4B6M0OGppFstNsQDzg8%3D&Expires=1402114176&AWSAccessKeyId=0EMWEFSGA12Z1HF1TZ82
這個版本是移動版
pypy-2.3-linux_x86_64-portable.tar.bz2
pypy-2.3-linux_x86_64-portable.tar
[root@kdc ~]# ./pypy-2.3-linux_x86_64-portable/bin/pypy
Python 2.7.6 (394146e9bb673514c61f0150ab2013ccf78e8de7, May 09 2014, 08:05:14)
[PyPy 2.3.0 with GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
#補充說明
修改文件BUILD/pypy-2.3-linux_x86_64-portable/lib-python/2.7/cgi.py中 #! /usr/local/bin/python 爲#! /usr/bin/python、
故解壓操做註釋
%prep
#tar -xvf %{pkgfile} ###if update
故清除操做也註釋
%clean
#[ -d %{_builddir}/%{name}-%{version} ] && rm -rf %{_builddir}/%{name}-%{version}
rpmbuild -ba rpmbuild/SPECS/pypy.spec && createrepo ./rpmbuild/RPMS/x86_64/
3.各個模塊
py-redis 2.10 .1 redis-2.9.0-py2.7.egg-info
py-tornado 3.2.1 tornado-3.2-py2.7.egg-info
pip-1.5.6-py2.7.egg-info
1)python-redis
__version__ = '2.9.0'
最新版本
https://codeload.github.com/andymccurdy/redis-py/zip/master
master.zip
redis-py-master
/usr/local/Python27/bin/python setup.py build
build/lib/redis/
使用版本
https://github.com/andymccurdy/redis-py/releases/tag/2.9.0
https://github.com/andymccurdy/redis-py/archive/2.9.0.tar.gz
rpmbuild -ba rpmbuild/SPECS/python-redis.spec && createrepo ./rpmbuild/RPMS/x86_64/
yum --enablerepo=jincom install python-redis
注意 由於安裝到其餘包的文件中,卸載文件沒有刪除
2)mysql-connector-python 1.2.2
對比了python26.python27,pypy setup buid的文件都同樣,都是源碼, 不改變mysql-connector-python-1.2.2-1.el6.noarch
https://pypi.python.org/pypi/mysql-connector-python/1.2.2
http://dev.mysql.com/doc/connector-python/en/index.html
http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-1.2.2.zip#md5= 5d72eedb06d2dcae258fe1e5fa93fc8a
代碼修改部分
vim rpmbuild/BUILD/mysql-connector-python-1.2.2/build/lib/mysql/connector/cursor.py
359
def _row_to_python(self, rowdata, desc=None):
"""Convert the row from MySQL to Python types"""
to_python = self._connection.converter.to_python
try:
if not desc:
desc = self.description
res = dict([(flddsc[0], to_python(flddsc, val)) for flddsc, val in zip(desc, rowdata) ])
except StandardError, e:
raise errors.InterfaceError("Failed converting row to Python types; %s" % e)
else:
return res
return None
返回列表修改返回字典了
#補充說明
有修代碼因此,第一運行以後,修改代碼後,而後
%prep
#%setup -n %{name}-%{version}
%build
#%{python27} setup.py build
%clean
#[ -d %{_builddir}/%{name}-%{version} ] && rm -rf %{_builddir}/%{name}-%{version} #一直關着
而後在運行一次
rpmbuild -ba rpmbuild/SPECS/mysql-connector-python.spec && createrepo ./rpmbuild/RPMS/x86_64/
yum --enablerepo=jincom makecache yum --enablerepo=jincom install mysql-connector-python.
3)simplejson
__version__ = '3.4.0'
https://github.com/simplejson/simplejson/releases/tag/v3.4.0
https://github.com/simplejson/simplejson/archive/v3.4.0.zip
rpmbuild -ba rpmbuild/SPECS/python-simplejson.spec && createrepo ./rpmbuild/RPMS/x86_64/
4)python-tornado tornado-3.2-py2.7.egg-info
http://www.tornadoweb.org/en/stable/
rpmbuild -ba rpmbuild/SPECS/python-tornado.spec && createrepo ./rpmbuild/RPMS/x86_64/
要依賴python-simplejson
4.測試
yum --enablerepo=jincom makecache
yum --enablerepo=jincom install pypy
yum --enablerepo=jincom install python-redis
yum --enablerepo=jincom install mysql-connector-python
yum --enablerepo=jincom install python-tornado
注意源碼包和rpm包不同的,不要修改原來的name,修改rpm包的名字爲newname
不對 name使用的是Name: %{pkgname} newname同樣變化
Summary: %{pkgname}-%{version} on centos6.x for jincomgamesGroup: jincomGAMES