• rpm管理环境包和代码包


    Author: Jin
    Date: 20140610
    System: CentOS release 6.5 (Final)

    06-09-2014c零:问题
    配置文件问题,不打包使用的配置文件参考配置文件后缀.default
    有个不替换操作 %config(noreplace) %{etcdir}/%{configfile} 新的安装为 /usr/local/redis/etc/redis.conf.rpmnew
    版本号更改: :%s/2.8.7/2.8.10/g 一般软件,游戏代码使用另外的

    一、基本流程
    1.环境
    yum -y install gcc-c++ gperf ncurses-devel readline-devel time zlib-devel cmake libaio-devel autoconf make
    yum -y install rpm-build

    2.基本目录
    会安装到每个用户的home目录下,指定到其他地方,build的时候也会到home
    cd ~
    mkdir rpmbuild/SOURCES
    mkdir rpmbuild/RPMS

    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 on

    4.源码
    [root@kdc ~]# ls -1 rpmbuild/SOURCES/
    mysql-5.5.38.tar.gz
    redis-2.8.10.tar.gz
    redis-2.8.7.tar.g

    5.SPEC文件
    # ls -1 rpmbuild/SPECS/
    mysql.spec
    redis.spec

    6.创建
    rpmbuild -ba rpmbuild/SPECS/redis.spec

    7.更新repo
    createrepo rpmbuild/RPMS/x86_64/
    # createrepo rpmbuild/RPMS 错误
    创建的目录别弄错了

    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-release

    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/

    二、 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

    三、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 jincomgames
    Group: jincomGAMES

  • 相关阅读:
    79.Word Search
    78.Subsets
    77.Combinations
    75.Sort Colors
    74.Search a 2D Matrix
    73.Set Matrix Zeroes
    71.Simplify Path
    64.Minimum Path Sum
    63.Unique Paths II
    Docker 拉取 oracle 11g镜像配置
  • 原文地址:https://www.cnblogs.com/diege/p/3948888.html
Copyright © 2020-2023  润新知