Install and configure the svn server in Ubuntu

Source: Internet
Author: User
Tags addgroup svn update rsync
I. SVN installation 1. Installation Package $ sudo apt-Get install Subversion
2. Add SVN management users and subversion groups $ sudo adduser svnuser $ sudo addgroup subversion $ sudo addgroup svnuser Subversion
3. Create a project directory $ sudo mkdir/home/SVN $ CD/home/SVN $ sudo mkdir fitness $ sudo chown-r root: Subversion fitness $ sudo chmod-r g + RWS fitness
4. Create a SVN File Repository $ sudo svnadmin create/home/SVN/fitness
5. access Method and project import: $ SVN Co file: // home/SVN/fitness or $ SVN Co file: // localhost/home/SVN/fitness * Note: if you are not sure about the host name, you must use three slashes (//). If you specify the Host Name, you must use two slashes (//). // -- the following command is used to import a project to the svn File Repository: $ SVN import-M "New Import"/home/SVN/fitness file: /// home/svnuser/src/fitness must indicate the import information
// -------------------------- // 6. modify/home/SVN/fitness under the directory svnserve. conf, passwd, and authz files. spaces are not allowed at the front end of the row. // -- edit svnserve. in the conf file, uncomment the following two lines: Password-DB = PASSWORD authz-DB = authz
// Additional description # [general] anon-access = read auth-access = WRITE password-DB = passwd where anon-access and Auth-access are anonymous and permitted to users, respectively, anonymous Users are granted read-only permissions by default.
You only need to change read to none to achieve the purpose of user access.
// -- Edit/home/svnuser/etc/passwd as follows: [users] Mirze = 123456 test1 = 123456 Test2 = 123456 // -- edit/home/svnuser/etc/authz as follows [groups] admin = Mirze, test1 test = Test2 [/] @ admin = RW * = r three users are set here: Mirze, test1, and Test2. The passwords are 123456. Among them, Mirze and test1 belong to the admin group, you have the read and write permissions. Test2 belongs to the test group and only has the read permission.
7. start the svn service svnserve-d-r/home/SVN description: -D indicates that svnserver runs in "daemon" process mode.-R specifies the root location of the file system (the root directory of the version Library), so that the client does not need to enter the full path, you can access the version Library such as SVN: // 192.168.12.118/fitness.
At this time, SVN installation is complete. LAN access method: for example: SVN checkout SVN: // 192.168.12.118/fitness -- username Mirze -- password 123456/var/www/fitness
-----------------------------------------------------------------------
2. http: // [Apache] 1. Installation Package [installed subversion] $ sudo apt-Get install libapache2-svn
Create a version Repository: The sudo svnadmin create/directory address must exist. This is where the version repository is saved. Create different folders for different version repositories, for example: sudo svnadmin create/home/SVN/project has nothing in the/home/SVN/project directory. Run the following command and check again. There are more files and folders, we need to operate on the conf folder, which contains a file named passwd, used to store the user name and password. Then, grant the Apache read/write: sudo chown-r www-data: www-data/directory address to the repository directory, and then open the Apache configuration file: sudo gedit/etc/apache2/mod-available/dav_svn.conf
Add the following content: <location/Project> Dav SVN svnpath/home/SVN/Project authtype basic authname "myproject subversion repository" authuserfile/home/SVN/project/CONF/passwd # <limit#t get PROPFIND Options Report> require valid-user # </limitexcept> </location>
Location refers to the access address. For example, the access address is http: // 127.0.0.1/Project. Two lines are commented out to ensure that the user name and password are required each time. The last step is to create an access user. We recommend that you store the user name and password file in the conf folder of the current version repository, so that the version repository is too messy when there are many versions. Because the passwd file already exists in the conf folder, add sudo htpasswd-C/home/SVN/project/CONF/passwd test and enter the password twice, the laoyang user is created. Open the/home/SVN/project/CONF/passwd file and open the file in the following format: Test: wed.83h. geala // followed by the encrypted password. After creation, you need to add this user to another version repository and copy the row directly. Restart Apache. Sudo/etc/init. d/apache2 restart
-----------------------------------------------------------------------
3. Synchronously update [hooks]

Synchronization program idea: the user submits the program to SVN, SVN triggers hooks, and processes it according to different hooks. Here post-commit is used, use post-commit to check the code to the local hard disk directory of the svn server, and then synchronize it to the remote web server through rsync.

Knowledge point: 1. SVN hooks # Start-commit trigger transaction before commit # pre-commit trigger transaction before commit is complete # post-commit trigger transaction when commit is complete # pre-revprop-change Attribute Modification previously triggered transactions # After modifying the post-revprop-change attribute, the transaction will be triggered through the scripts written with these names to implement multiple functions, very powerful. 2. the specific parameters of the synchronization command rsync are used. 3. Bash Python Perl can be implemented with the programming capability of the base language.

Post-commit Implementation Details post-commit script

Edit the file: sudo Vim/home/SVN/fitness/hooks/post-commit

Note: after the post-commit is edited, run sudo chmod 755 post-commit.

Content:

#! /Bin/sh
Export lang = zh_CN.UTF-8
Sudo/usr/bin/SVN update/var/www/WWW -- username Mirze -- password 123456

Or

# Set variable
SVN =/usr/bin/SVN
Web =/home/test_nokia/
Rsync =/usr/bin/rsync
Log =/tmp/rsync_test_nokia.log
Webip = "192.168.0.23"
Export lang = en_US.UTF-8

# Update the code from the SVN
$ SVN update $ Web -- username user -- Password
# If the previous command completed successfully, to continue the following
If [$? = 0]
Then
Echo ""> $ log
Echo 'date'> $ log
Echo "###############################" >>> $ log
Chown-r nobody: Nobody/home/test_nokia/
# Synchronization code from the svn server to the Web server, notes: By the key
$ Rsync-vaztph -- timeout = 90 -- exclude-from =/home/SVN/exclude. List $ web [email protected] $ webip:/www/> $ log
Fi
The above are specific post-commit program considerations: 1. variables must be defined, mainly the paths of used commands. Because of the security concerns of SVN, the system variables are not called. IF Manual execution is normal, but SVN Automatic Execution will fail. 2. Before SVN update, you must manually checkout it out, and here you must add users and passwords. If the password is only updated manually, it will not work automatically. 3. added the judgment on the previous command. If a problem occurs during Update and the program does not exit, the code will continue to be synchronized to the web server, this will cause code problems. 4. Remember to set the owner because rsync can synchronize file attributes, and our web servers are generally not root users, if the user is incorrect, the web program cannot work properly. 5. It is recommended that you record the logs. If an error occurs, you can quickly troubleshoot the error. 6. In the final and most critical data synchronization, the relevant parameters of rsync must be clear. Note: In this scenario, the svn server and the Web server define the svn server as the source server and the target server. Scenario 1. If the target Web server is a comprehensive mix, for example, if there is only one static Web resource, the automatically generated resources submitted by the user are all in the same directory of the web. We recommend that you do not use the-delete parameter above this program, the solution is to update and add the source server to the target server without deleting the server. The content of the web server is more than that of the source SVN server. Scenario 2. Implement the image, that is, the data of the target Web server is the same as that of the source SVN server. If any changes on SVN are the same as those on the Web, the-delete parameter scenario is required. 3. Some subdirectories do not need to be synchronized, some directories may be cached temporary junk directories, or dedicated image directories (instead of style or layout) must use the exclude parameter. Note: you do not need to write absolute paths for this parameter, as long as the directory name is used, AA represents the file AA/Represents the directory, the disadvantage is that if multiple subdirectories share the same name, these names will not be synchronized. We recommend that you use-exclude-from =/home/SVN/exclude. list can be used to conveniently add and delete exclude. list
. SVN/. ds_store images/
SVN hooks can also be used to write many programs to control SVN. Before code submission, check whether there are logs, tabs, spaces, and files that cannot be uploaded, whether there are files that exceed the limit.

Install and configure the svn server in Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.