Tip: The system environment of this article is: ubuntu-22.04.1-live-server-amd64, different systems and different system version numbers may have different installation methods in some places;
1. Check whether it is installed
svnserve --version
If the system has already been installed, uninstall it first
sudo apt-get remove --purge subversion
2. Install SVN
Update the system before installing
sudo apt-get update
install subversion
sudo apt-get install subversion
Create repository folder
sudo mkdir -p /home/svn # Use /home/svn as the warehouse address, the path of the warehouse address can be changed by yourself
sudo chmod -R 777 /home/svn # Change permissions, if you use root user access, you don’t need to change
Create repository
svnadmin create /home/svn/repos
Remarks: 1. Create a version library repos, where repos is the name of the version library
2. The version library is related to the access path. Here, the name must correspond to the access path.
Such as: svn://ip address/repos
After completion, the following files will be generated under the repos folder
authz
hooks-env.tmpl
passwd
svnserve.conf
Then set permissions on db
cd /home/svn/repos
chmod -R 777 db
3. SVN configuration
Set access permissions: you need to modify the files in the conf folder
vim conf/svnserve.conf
Simply modify a few configurations:
#Anonymous users can read anon-access = read (it is recommended to change to none, that is, unreadable)
#Permission users can write auth-access = write
#The password file is password-db = passwd
#The permission file is authzauthz-db = authz
Note: Remove the # in front and top the grid, otherwise an error may be reported
Modify the passwd file and add access users
vim conf/passwd
[users]
# harry = harryssecret
# sally = sallyssecret
xiaoming = 123456wang = 123456
Modify authz permission
[groups]
admin = xiaoming #Administrator user, has the highest read and write permissionsnormal = wang #Normal user, only has read permission
[/] # / represents all projects, that is, different warehouses have common permissions
@admin = rw@normal = r
Description of this section
The [/] above means to authorize the root directory, that is, the members of the user group have common permissions for all projects. If we want to set different permissions for different projects, we can do the following
[JAVA:/]
Heath = rw //Indicates that the user Heath has read and write permissions to all contents of the project JAVA
Liu = r //Indicates that user Liu only has read access to all contents of the project JAVA
[Python:/]
Ming = rw //Indicates that user Ming has read and write permissions to all contents of the project Python
Tao = r //Indicates that the user Tao only has read permission for all the contents of the project Python
The above method can ensure that Heath only has the read and write permission of the JAVA project, and has no permission of the Python project, which ensures the information security and project security among the project team members, and facilitates the management among the project team members.
4. Start SVN
svnserve -d -r /home/svn
Remarks: 1. Do not start svnserve -d -r /home/svn/repos like this
2. Start the SVN server, here are the instructions: -d: means running in the background -r: specify the root directory of the server
5. Close SVN
killall svnserve
6. Access SVN
svn://ip address/repos
svn uses port 3690 by default
Check if svnserve is already running
ps aux | grep svnserve
7. Test SVN
Copy repository:
svn co svn://192.168.6.221:3690/repos --username xiaoming --password 123456
checkout:
svn checkout svn://192.168.6.221:3690/repos
Analysis of access failure reasons:
1. Check whether the configuration is correct
2. Whether port 3690 is open
3. Whether the access path is correct
check port
View network firewall port 3690 open
firewall-cmd --list-allPort 3690 is not open to the outside world, execute the following command to open
firewall-cmd --zone=public --add-port=3690/tcp --permanentReload the firewall, this step is very important, otherwise the added port will not take effect
firewall-cmd --reloadIn order to protect the security of the server host, it is recommended to open the firewall
8. Configure the system to automatically start SVN
After the ubuntu operating system is restarted, svnserve must be manually started, and we can manually add it to the operating system startup list.
Add the startup script /etc/init.d/subversion.sh as follows
#!/bin/bash
svnserve -d -r /home/svn/repos --log-file=/home/svn/svn.log
exit 0
Modify the properties of the script file
chmod 755 /etc/init.d/subversion.sh
Use the following command to connect the script to the startup directory
ln -s /etc/init.d/subversion /etc/rc3.d/S03subversion
ln -s /etc/init.d/subversion /etc/rc4.d/S03subversion
ln -s /etc/init.d/subversion /etc/rc5.d/S03subversion
The result is as follows:
In this way, after the operating system restarts, the svnserve service will automatically start