Linux install SVN to realize automatic synchronization to web directory

Time:2019-11-10

Personal blog:
Linux install SVN to realize automatic synchronization to web directory

I: install SVN
1. Check whether SVN is installed on the server

svn --version
    Installed:
        svn, version 1.6.11 (r934486)
            compiled Aug 17 2015, 08:37:43
        Copyright (C) 2000-2009 CollabNet.
        Subversion is open source software, see http://subversion.tigris.org/
        This product includes software developed by CollabNet (http://www.Collab.Net/).
        The following repository access (RA) modules are available:
        * ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
          - handles 'http' scheme
          - handles 'https' scheme
        * ra_svn : Module for accessing a repository using the svn network protocol.
          - with Cyrus SASL authentication
          - handles 'svn' scheme
        * ra_local : Module for accessing a repository on local disk.
          - handles 'file' scheme
    Not installed:
        -bash: svn: command not found

2. It is not installed and installed using yum

yum install subversion

3. Create the warehouse directory (the warehouse directory can be changed to other directories, depending on your wishes)

mkdir –p /svn

4. Create project version Library

Svnadmin create / SVN / davesvn -- davesvn is the version library name

5. Enter the version Library Directory after creation

cd /svn/davesvn
Ls view files generated in the directory
Conf directory to store the configuration files used by the version Library
DB version datastore directory
Format stores an integer file representing the library hierarchy version
Hooks store version library hook subdirectory
Locks repository lock directory, used to track library visitors
README.txt

6. Next, start to configure SVN

cd conf
ls 
Authz | permission profile
Passwd | username password file
Svnserve.conf | SVN service configuration file
//Configuration password XXX = XXX
vim password
[users]  
zhan = 123456
//Configuration authority XXX = XXX
vim authz
[/]
zhan = rw
//Configure svnserve.conf to uncomment the following note without spaces
vim svnserve.conf
Anon access = read - anonymous user readable  
Auth access = write ා authorized user can write  
Password DB = passwd - which file to use as the account file  
Authz DB = authz ා which file to use as the permission file  
Realm = / SVN / davesvn ා authentication space name, the directory where the version library is located

7. Start SVN service

svnserve -d -r /svn/davesvn
-D stands for background operation
-R specifies that the directory is / SVN / davesvn
If prompt: svnserve: can't bind server socket: address already in use
Indicates that the service has started, stop the service first
ps -ef | grep svn
Kill - 9 [process number] kill the process

2. Realize automatic deployment of projects
1. Use post commit to realize automatic deployment

Create the post commit file under / SVN / davesvn / hooks, and set the executable permissions
cp post-commit.tmpl post-commit
chmod 755 post-commit

2. Open the post commit file, empty the post commit content, and add the following content

!/bin/sh
export LANG=zh_CN.UTF-8
Svn co SVN: // [your IP address] / davesvn [web actual directory]
LOG_PATH=/tmp/svn_test.log
Web = [web actual directory]
REPOS="$1"
REV="$2"
Svn update -- username [SVN user name just set] - password [SVN password just set] $web -- no auth cache > > $log_path

3. Finally back to shell

Svn co SVN: // your IP / davesvn [web directory]
Input the account password according to the prompt to realize automatic synchronization

Three, use

Svn check out: check whether it can be checked out normally
Svn: // server IP: 3690 / davesvn
After checking out normally, submit to check whether the web directory has synchronized content

Pits:

Svn error: Post commit hook failed (exit code 1) with output
1. Check whether the character code set in post commit is correct
    It was originally "export lang = zh CN. GBK"
    Modify it to export lang = en_us.utf-8 (the default value of SVN server is utf8)
2. Check whether the account password set in post commit and the account password in SVN configuration are correct
3255 error: is post commit authorized
4. Check whether port 3690 of the server is on
4. At last, no matter what you are doing, the most important thing is to be careful. Read the wrong information and don't panic