Linux installation configures SVN and sets hooks
Installation Notes
System environment: CentOS
Installation method: yum install (source code installation is prone to version compatibility problems)
Installation software: The system automatically downloads SVN software
Check installed version
#检查是否安装了低版本的SVN
rpm -qa subversion
#卸载旧版本SVN
yum remove subversion
1. Install SVN
yum -y install subversion
verify installation
Verify the installed SVN version information
svnserve --version
Code library creation
SVN software installation is complete, you need to create an SVN library
mkdir -p /www/svndata #创建仓库目录
svnadmin create /www/svndata/test #创建项目仓库,test是自己的仓库名称
After executing the above command, the svndata library is automatically established. Check the /www/svndata/test folder and find that it contains conf, db, format, hooks, locks, README.txt and other files, indicating that an SVN library has been established.
Configure the code library
Enter the folder conf generated above to configure (all codes without # behind should not be blank, otherwise it will prompt: authentication configuration is invalid)
cd /www/svndata/test/conf
User password passwd configuration
vim passwd
Modify passwd to the following:
[users]
#harry = harryssecret
#sally = sallyssecret
cy=123456
Permission control authz configuration
vim authz
The purpose is to set which users can access which directories, append the following to the authz file:
#Setting [/] represents all resources in the root directory
[/]
cy=rw
service svnserve.conf configuration
vim svnserve.conf
Append the following:
[general]
#匿名访问的权限,可以是read,write,none,默认为read
anon-access=none
#使授权用户有写权限
auth-access=write
#密码数据库的路径
password-db=passwd
#访问控制文件
authz-db=authz
#认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字
realm = My First Repository
start svn
svnserve -d -r /www/svndata
View SVN process
[root@localhost conf]# ps -ef|grep svn|grep -v grep
root 12538 1 0 14:40 ? 00:00:00 svnserve -d -r /www/svndata
Detect SVN port
[root@localhost conf]# netstat -ln |grep 3690
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN
stop restart svn
[root@localhost password]# killall svnserve //停止
[root@localhost password]# svnserve -d -r /www/svndata // 启动
test
The SVN service has been started, use the client to test the connection.
Client connection address: svn://xxx.xxx.xxx.xxx/test
Username/Password: cy/123456
Test operations such as creating folders.
2. Set the hook to automatically update
to realize the synchronization between SVN and WEB. You can CO one out, or you can directly use the method of automatically updating the web directory. We need to configure the hook in the svn version library to achieve it, which is to create a post-commit configuration file. Simply configure it, and in four simple steps, you can automatically update the web directory configuration of SVN under Linux.
Step 1: Create your web program directory
mkdir /www/wwwroot/test
Enter the web program directory you created (svn checkout can be abbreviated as co)
svn checkout svn://localhost/svntest //不重命名文件夹,直接在当前目录下检出
svn checkout svn://localhost/svntest test //检出文件并且重命名文件夹
Step 2: Create a new post-commit file in the hooks/ directory of the project library [hook script]
Add the script content as follows
export LANG=en_US.UTF-8
SVN=/usr/bin/svn #这里配置的是svn安装bin目录下的svn文件
WEB=/www/wwwroot/test #要更新的目录
$SVN update $WEB --username cy --password 123456
chown -R 777 $WEB #设置目录权限
Among them, SVN = change the right side to svn command position
WEB = change the right side to your actual web directory
Note: If it is a new post-commit file, you need to add #!/bin/sh to the head
Step 3: Let post-commit have execution permission
chmod a+x post-commit
Step 4: It has been completed here, and the fourth step is to test.
Explanation:
export LANG=en_US.UTF-8 is to solve the svn post commit Chinese garbled characters and set the localization encoding, because my system is UTF8 encoding, in fact, SVN defaults to UTF-8 encoding, if the encoding is GBK, if it is not set, it will be An error occurred and the execution was unsuccessful, the error is identified as
svn: Can't convert string from native encoding to 'GBK'
To perform an update operation manually from the command line
/usr/bin/svn update -- username cy -- password 123456 /www/wwwroot/test
If prompted:
post-commit hook failed (exit code 255) with no output
Give the post-commit file executable permission
If your default encoding is UTF-8, to upload a Chinese file, first save the file as UTF-8 format before submitting
Common svn commands:
退回到指定版本:svn log -l 版本号 -v
svn 更新到指定版本:svn up -r 版本号 //版本号不带r
##svn up -r 只是回退当前版本,如果重新执行svn up,则又回到最新的版本