码迷,mamicode.com
首页 > 其他好文 > 详细

Subversion基本操作,制作nginx的RPM包

时间:2018-01-11 20:28:27      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:body   std   path   svn add   pms   pat   change   append   ict   

Subversion基本操作

1.1 问题

本案例要求先快速搭建好一台Subversion服务器,并测试该版本控制软件:

  • 创建版本库
  • 导入初始化数据
  • 检出数据至用户本地副本
  • 对本地副本进行增删改查等操作

1.2 方案

使用YUM安装subversion软件,使用svn客户端工具连接svnserver服务器并测试版本控制软件。

使用svn命令测试svnserver服务时可以使用的命令列表如表-1所示。

表-1 svn命令列表

技术分享图片

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:安装Subversion服务器

1)YUM安装subversion软件

  1. [root@svr5 ~]# yum -y install subversion
  2. [root@svr5 ~]# rpm -q subversion

2)创建版本库

  1. [root@svr5 ~]# mkdir /var/svn/
  2. [root@svr5 ~]# svnadmin create /var/svn/project
  3. [root@svr5 ~]# ls /var/svn/project/
  4. conf/ db/ format hooks/ locks/ README.txt

3)修改配置文件,创建账户与密码

  1. [root@svr5 ~]# vim /var/svn/project/conf/svnserve.conf
  2. [general]
  3. ### These options control access to the repository for unauthenticated
  4. ### and authenticated users. Valid values are "write", "read",
  5. ### and "none". The sample settings below are the defaults.
  6. anon-access = none        //匿名无任何权限
  7. auth-access = write        //有效账户可写
  8. ### The password-db option controls the location of the password
  9. ### database file. Unless you specify a path starting with a /,
  10. ### the file‘s location is relative to the directory containing
  11. ### this configuration file.
  12. ### If SASL is enabled (see below), this file will NOT be used.
  13. ### Uncomment the line below to use the default password file.
  14. password-db = passwd    //密码文件
  15. ### The authz-db option controls the location of the authorization
  16. ### rules for path-based access control. Unless you specify a path
  17. ### starting with a /, the file‘s location is relative to the the
  18. ### directory containing this file. If you don‘t specify an
  19. ### authz-db, no path-based access control is done.
  20. ### Uncomment the line below to use the default authorization file.
  21. authz-db = authz        //ACL访问控制列表文件
  22. ### This option specifies the authentication realm of the repository.
  23. ### If two repositories have the same authentication realm, they should
  24. ### have the same password database, and vice versa. The default realm
  25. ### is repository‘s uuid.
  26. # realm = My First Repository
  27. [root@srv5 ~]# vim /var/svn/project/conf/passwd
  28. … …
  29. [users]
  30. harry = pass            //用户名和密码
  31. tom= pass                //用户名和密码
  32. [root@svr5 ~]# cat /var/svn/project/conf/authz
  33. [aliases]
  34. # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
  35. [groups]
  36. harry_and_tom = harry,tom            //定义组账户,组成员为harry和tom
  37. [/]                                //定义ACL访问控制
  38. harry = rw                        //用户对项目根路径可读可写
  39. tom = rw
  40. * = r                            //其他人只读

4)启动服务

  1. [root@svr5 ~]# systemctl start svnserve
  2. [root@svr5 ~]# netstat -nutlp |grep svnserve
  3. tcp 0 0 0.0.0.0:3690    0.0.0.0:*    LISTEN 4043/svnserve

步骤二:客户端测试

1)本地导入初始化数据

  1. [root@srv5 ~]# cd /usr/lib/system/system/
  2. [root@srv5 ~]# svn import . file:///var/svn/project/ -m "Init Data"
  3. [root@srv5 ~]# cd /var/tmp
  4. [root@srv5 ~]# svn --username harry --password pass \
  5. co svn://127.0.0.1/var/svn/project harry        //harry账户检查数据,建立本地副本
  6. -----------------------------------------------------------------------
  7. ATTENTION! Your password for authentication realm:
  8. <svn://127.0.0.1:3690> b72f45f0-bbe5-4a0c-ad4a-37f52704f0b1
  9. can only be stored to disk unencrypted! You are advised to configure
  10. your system so that Subversion can store passwords encrypted, if
  11. possible. See the documentation for details.
  12. You can avoid future appearances of this warning by setting the value
  13. of the ‘store-plaintext-passwords‘ option to either ‘yes‘ or ‘no‘ in
  14. ‘/root/.subversion/servers‘.
  15. -----------------------------------------------------------------------
  16. Store password unencrypted (yes/no)? yes            //提示是否保存密码
  17. [root@srv5 ~]# cd /var/tmp/harry
  18. [root@srv5 harry]# ls
  19. [root@srv5 harry]# vim test.sh             //新建脚本文件
  20. #!/bin/bash
  21. case $1 in
  22. start)
  23.     echo start;;
  24. stop)
  25.     echo stop;;
  26. *)
  27.     echo Error
  28. esac
  29. [root@srv5 harry]# chmod +x test.sh
  30. [root@srv5 harry]# svn add test.sh            //将文件或目录加入版本控制
  31. [root@srv5 harry]# svn mkdir subdir        //创建子目录
  32. [root@srv5 harry]# svn status                //检查状态,结果为两个添加append
  33. A test.sh
  34. A subdir
  35. [root@srv5 harry]# svn del cups            //删除版本库中的文件
  36. [root@srv5 harry]# svn move test.sh test    //脚本重命名
  37. A test
  38. D test.sh
  39. [root@srv5 harry]# svn commit -m "add a file and subdir,remove cups file"    
  40.                                             //将本地副本的修改提交版本库
  41. Deleting cups
  42. Adding subdir
  43. Adding test
  44. Transmitting file data .
  45. Committed revision 2.
  46. [root@srv5 harry]# sed -i ‘1a##test###‘ sshd.service    //修改本地副本中的代码文件
  47. [root@srv5 harry]# sed -i ‘2a###test###‘ sshd.service
  48. [root@srv5 harry]# svn diff sshd.service        //查看单个文件本地副本与版本库的差异
  49. [root@srv5 harry]# svn diff                    //查看所有本地副本与版本库的差异
  50. [root@srv5 harry]# svn log svn://127.0.0.1/var/svn/project    //查看修改历史
  51. [root@srv5 harry]# svn update                //更新本地副本文件,从版本库下载更新数据
  52. [root@srv5 harry]# cd /var/tmp
  53. [root@srv5 tmp]# svn –r2 co svn://127.0.0.1/var/svn/project code2 //下载历史版本
  54. [root@srv5 tmp]# cd harry
  55. [root@srv5 harry]# svn merge –r10:5 sshd.service

2 案例2:使用Subversion协同工作

2.1 问题

沿用练习一,通过svn工具,对subversion版本库进行多人协同工作测试,要求如下:

  • 使用subversion管理公司的shell脚本
  • 脚本包括/etc/rc.d/init.d/目录下的启动脚本
  • 以及任何用户自己编写的脚本
  • 创建脚本版本库
  • 该版本库支持多个账户同时协作编辑脚本
  • 测试演示多人协作编辑的具体操作
  • 手动解决版本冲突问题
  • 备份版本库数据

2.2 方案

使用svn客户端工具连接subversion服务器并测试多人协同工作以及如何手动解决冲突问题,账户名称分别为harry和tom,最后使用svnadmin dump指令对版本库进行备份工作。

2.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:多人协同工作

1)远程连接两个终端,每个人下载代码本地副本,注意user1和user2代表了两个不同的主机,看清楚操作是在哪一台计算机上执行!

  1. [user1@srv5 ~]# svn --username harry --password pass co svn://127.0.0.1/project harry
  2. [user2@srv5 ~]# svn --username tom --password pass co svn://127.0.0.1/project tom
  3. [user1@srv5 ~]# ls harry
  4. [user2@srv5 ~]# ls tom

2) harry和tom修改不同的文件

  1. [user1@srv5 ~]# cd harry
  2. [user1@srv5 harry]# sed -i "3a###harry\‘s modify#####" vmtoolsd.service
  3. [user1@srv5 harry]# svn commit -m "vmtoolsd has modified"
  4. [user2@srv5 ~]# cd tom
  5. [user2@srv5 tom]# sed -i "3a###tom\‘s modify#####" sshd.servie
  6. [user2@srv5 tom]# svn commit -m "sshd has modified"
  7. [user1@srv5 harry]# svn update
  8. [user2@srv5 tom]# svn update

3)harry和tom修改相同文件的不同行

  1. [user1@srv5 ~]# cd harry
  2. [user1@srv5 harry]# sed -i "3a###harry\‘s modify#####" user.slice
  3. [user1@srv5 harry]# svn commit -m "user.slice has modified"
  4. [user2@srv5 ~]# cd tom
  5. [user2@srv5 tom]# sed -i "6a###tom\‘s modify#####" user.slice
  6. [user2@srv5 tom]# svn commit -m "user.slice has modified"
  7. Sending svnserve
  8. Transmitting file data .svn: Commit failed (details follow):
  9. svn: File ‘/user.slice‘ is out of date
  10. [user2@srv5 tom]# svn update            //提示失败后,先更新再提交即可
  11. [user2@srv5 tom]# svn commit -m "user.slice has modified"
  12. Sending user.slice
  13. Transmitting file data .

4) harry和tom修改相同文件的相同行

  1. [user1@srv5 ~]# cd harry
  2. [user1@srv5 harry]# sed -i "8c###harry\‘s modify#####" zram.service
  3. [user1@srv5 harry]# svn commit -m "zram.service has modified"
  4. [user2@srv5 ~]# cd tom
  5. [user2@srv5 tom]# sed -i "8c###tom\‘s modify#####" zram.service
  6. [user2@srv5 tom]# svn commit -m "zram.service has modified"
  7. svn commit -m "zram.service has modified"
  8. Sending zram.service
  9. Transmitting file data .svn: Commit failed (details follow):
  10. svn: File ‘/zram.service‘ is out of date
  11. [user2@srv5 tom]# svn update                    //出现冲突,需要解决
  12. Conflict discovered in ‘zram.service‘.
  13. Select: (p) postpone, (df) diff-full, (e) edit,
  14. (mc) mine-conflict, (tc) theirs-conflict,
  15. (s) show all options:p                    //选择先标记,随后解决
  16. [user2@srv5 tom]# ls
  17. zram.service zram.service.mine        zram.service.r10        zram.service.r9
  18. [user2@srv5 tom]# vm zram.service.mine zram.service
  19. [user2@srv5 tom]# rm zram.service.mine zram.service.r10 zram.service.r9
  20. [user2@srv5 tom]# svn commit -m "zram.service has modified"    //解决冲突

步骤二:使用dump指令备份版本库数据

  1. [root@srv5 ~]# svnadmin dump /var/svn/project > project.bak
  2. * Dumped revision 0.
  3. * Dumped revision 1.
  4. * Dumped revision 2.
  5. * Dumped revision 3.
  6. * Dumped revision 4.
  7. * Dumped revision 5.
  8. * Dumped revision 6.
  9. * Dumped revision 7.
  10. * Dumped revision 8.
  11. * Dumped revision 9.
  12. * Dumped revision 10.
  13. * Dumped revision 11.

3 案例3:制作nginx的RPM包

3.1 问题

本案例使用nginx-1.8.0版本的源码软件,生产对应的RPM包软件,具体要求如下:

  • 软件名称为nginx
  • 软件版本为1.8.0
  • RPM软件包可以查询描述信息
  • RPM软件包可以安装及卸载

3.2 方案

安装rpm-build软件包,编写SPEC配置文件,创建新的RPM软件包。

配置文件中的描述信息如表-2:

表-2 SPEC描述信息

技术分享图片

3.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:安装rpm-build软件

1)安装rpm-build软件包

  1. [root@svr5 ~]# yum -y install rpm-build

2)生成rpmbuild目录结构

  1. [root@svr5 ~]# rpmbuild -ba nginx.spec
  2. [root@svr5 ~]# ls /root/rpmbuild
  3. BUILD BUILDROOT RPMS SOURCES SPECS SRPMS

3)准备工作,将源码软件复制到SOURCES目录

  1. [root@svr5 ~]# cp nginx-1.8.0.tar.gz /root/rpmbuild/SOURCES/

4)创建并修改SPEC配置文件

  1. [root@svr5 ~]# vim SPECS/nginx.spec
  2. Name:nginx        
  3. Version:1.8.0
  4. Release:    1%{?dist}
  5. Summary:test    
  6. License:GPL    
  7. URL:    www.test.com    
  8. Source0:nginx-1.8.0.tar.gz
  9. #BuildRequires:    
  10. #Requires:    
  11. %description
  12. test too
  13. %prep
  14. %setup -q
  15. %build
  16. ./configure
  17. make %{?_smp_mflags}
  18. %install
  19. make install DESTDIR=%{buildroot}
  20. mkdir -p %{buildroot}/etc/init.d/
  21. install /root/rpmbuild/SPECS/nginx.sh %{buildroot}/etc/init.d/
  22. ##注意,这里是将一个脚本拷贝到安装目录,如果没有则不需要该指令
  23. %files
  24. %doc
  25. /etc/init.d/nginx.sh            #将前面拷贝的脚本,打包到RPM中
  26. /usr/local/nginx/*
  27. %changelog

步骤二:使用配置文件创建RPM包

1)安装依赖软件包

  1. [root@svr5 ~]# yum –y install gcc pcre-devel zlib-devel

2)rpmbuild创建RPM软件包

  1. [root@svr5 ~]# rpmbuild -ba SPECS/nginx.spec
  2. [root@svr5 ~]# ls RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
  3. [root@svr5 ~]# rpm -qpi RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
  4. Name : nginx        Relocations: (not relocatable)
  5. Version : 1.8.0        Vendor: (none)
  6. Release : 1            Build Date: Mon 02 May 2016 02:30:53 AM PDT
  7. Install Date: (not installed)            Build Host: localhost
  8. Group : Applications/Internet        Source RPM: nginx-1.8.0-1.src.rpm
  9. Size : 721243                    License: GPL
  10. Signature : (none)
  11. URL : www.nginx.org
  12. Summary : Nginx is a web server software.
  13. Description :
  14. nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server, originally written by Igor Sysoev. For a long time, it has been running on many heavily loaded Russian sites including Yandex, Mail.Ru, VK, and Rambler.
  15. [root@svr5 ~]# rpm -qpl RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
  16. /usr
  17. /usr/local
  18. /usr/local/nginx
  19. /usr/local/nginx/conf
  20. /usr/local/nginx/conf/fastcgi.conf
  21. /usr/local/nginx/conf/fastcgi.conf.default
  22. /usr/local/nginx/conf/fastcgi_params
  23. /usr/local/nginx/conf/fastcgi_params.default
  24. /usr/local/nginx/conf/koi-utf
  25. /usr/local/nginx/conf/koi-win
  26. /usr/local/nginx/conf/mime.types
  27. /usr/local/nginx/conf/mime.types.default
  28. /usr/local/nginx/conf/nginx.conf
  29. /usr/local/nginx/conf/nginx.conf.default
  30. /usr/local/nginx/conf/scgi_params
  31. /usr/local/nginx/conf/scgi_params.default
  32. /usr/local/nginx/conf/uwsgi_params
  33. /usr/local/nginx/conf/uwsgi_params.default
  34. /usr/local/nginx/conf/win-utf
  35. /usr/local/nginx/html
  36. /usr/local/nginx/html/50x.html
  37. /usr/local/nginx/html/index.html
  38. /usr/local/nginx/logs
  39. /usr/local/nginx/sbin
  40. /usr/local/nginx/sbin/nginx

步骤三:安装、卸载软件

  1. [root@svr5 ~]# rpm -ivh RPMS/x86_64/nginx-1.8.0-1.x86_64.rpm
  2. [root@svr5 ~]# rpm -qa |grep nginx
  3. [root@svr5 ~]# /usr/local/nginx/sbin/nginx
  4. [root@svr5 ~]# curl http://127.0.0.1/
  5. [root@svr5 ~]# /usr/local/nginx/sbin/nginx -s stop
  6. [root@svr5 ~]# rpm -e nginx

Subversion基本操作,制作nginx的RPM包

标签:body   std   path   svn add   pms   pat   change   append   ict   

原文地址:https://www.cnblogs.com/xiaoren112/p/8270139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!