Ubuntu Server builds an SVN server

I have always wanted to build a server by myself, and now I have a Raspberry Pi on hand, so I want to build it myself.

1. Configuration

Hardware: Raspberry Pi B4

Hard disk: 4T mechanical hard disk

System: ubuntu-22.04.2-preinstalled-server-arm64+raspi (download from Raspberry Pi official website)

2. Preliminary preparation

Burn the system according to the Raspberry Pi official website and run it.

3. Mount the hard disk

3.1 Format the mechanical hard disk for mounting

During the actual operation, when the volume label is found to be in Chinese, an error will be reported when using the ubuntu console to modify the volume label. It is recommended to change the volume label to English.

3.2 Mount the hard disk

Connect the hard disk to the Raspberry Pi, and then mount it. In this step, you need to connect the hard disk first, and then start the machine, otherwise an Input/Output error will be reported during the operation.

3.2.1 Create a directory:

The hard disk mount in linux needs to be mounted in the system directory, because the linux system cannot automatically recognize it, and can only be mounted in the specified directory. It is said on the Internet that it is generally created in the mnt directory. As a novice, then I am also in this directory Created under.

sudo mkdir /mnt/DbDisk

3.2.2 Identify hard disk

Identify the hard disk through the fdisk -l command:

ubuntu@ubuntu:~$ sudo fdisk -l
Disk /dev/loop0: 59.09 MiB, 61956096 bytes, 121008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop1: 59.12 MiB, 61988864 bytes, 121072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 109.61 MiB, 114929664 bytes, 224472 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop3: 43.19 MiB, 45289472 bytes, 88456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop4: 43.18 MiB, 45277184 bytes, 88432 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: e SSD ST600 MSAT
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x12c9124a

Device     Boot  Start       End   Sectors  Size Id Type
/dev/sdb1  *      2048    526335    524288  256M  c W95 FAT32 (LBA)
/dev/sdb2       526336 250069679 249543344  119G 83 Linux


Disk /dev/sda: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: 006-3CW104
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 9463367F-46F9-46DB-AC72-5633AEA58D7E

Device     Start        End    Sectors  Size Type
/dev/sda1   4096 7814037134 7814033039  3.6T Microsoft basic data

The hard disk I want to mount is /dev/sda1, which I identify based on the size of the hard disk I want to mount.

3.2.3 Mount the hard disk:

sudo mount /dev/sda1 /mnt/DbDisk

You can view the hard disk mounting status through sudo df. I currently mount the sda1 hard disk to the DbDisk directory

ubuntu@ubuntu:~$ sudo df
Filesystem      1K-blocks    Used  Available Use% Mounted on
tmpfs              388000    3176     384824   1% /run
/dev/sdb2       122731688 4809364  111667360   5% /
tmpfs             1939984       0    1939984   0% /dev/shm
tmpfs                5120       0       5120   0% /run/lock
/dev/sdb1          258095  151621     106475  59% /boot/firmware
/dev/sda1      3907016516  221416 3906795100   1% /mnt/DbDisk
tmpfs              387996       4     387992   1% /run/user/1000

3.2.4 Set up automatic mount

Direct mount needs to be mounted once every time it is restarted. Generally, it is better to set automatic mount, which can be realized by modifying the configuration file.

ubuntu@ubuntu:~$ sudo vim /etc/fstab

Then add the disk to be newly mounted to the configuration file:

LABEL=writable  /       ext4    discard,errors=remount-ro       0 1
LABEL=system-boot       /boot/firmware  vfat    defaults        0       1
/dev/sda1               /mnt/DbDisk     ntfs    auto,user,rw    0       1                                  

The identification number at the beginning of the mount can be the LABEL volume label, the UUID hard disk number, or directly write the device path recognized by the system like me. In actual use, I had a situation where neither LABEL nor UUID could be recognized, so I changed it to use the device path to mount directly, which is easy to use.

After setting, you can restart the Raspberry Pi to see if it works normally.

4. Install svnserver

4.1 Install the svn server

sudo apt-get install subversion

4.2 Create svn warehouse folder

ubuntu@ubuntu:~$ sudo mkdir /mnt/DbDisk/svn

Create an svn warehouse folder in the hard disk directory to be used as the svn warehouse folder.

ubuntu@ubuntu:/mnt/DbDisk/svn$ sudo mkdir test
ubuntu@ubuntu:/mnt/DbDisk/svn$ ls
test

A version library test in the warehouse directory

4.3 Create repository

sudo svnadmin create /mnt/DbDisk/svn/test
ubuntu@ubuntu:/mnt/DbDisk/svn/test$ ls
README.txt  conf  db  format  hooks  locks
ubuntu@ubuntu:/mnt/DbDisk/svn/test$ ls -a
.  ..  README.txt  conf  db  format  hooks  locks
ubuntu@ubuntu:/mnt/DbDisk/svn/test$

After the creation is complete, there are files in the directory.

4.4 configuration

Configure permissions by modifying files under the conf folder.

Note that when modifying the configuration files svnserve.conf, authz, and passwd, all line headers cannot be empty, and empty spaces cannot be added at the end. The information described in the configuration # in the afternoon is mainly used for remarks, and cannot be added during actual modification, otherwise it will report "authorization failed" error.

4.4.1 svnserve.conf file

[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
anon-access = none      # 设置匿名用户不可读
auth-access = write     # 权限用户可写
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd    # 使用用密码文件
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the
### directory containing this file.  The specified path may be a
### repository relative URL (^/) or an absolute file:// URL to a text
### file in a Subversion repository.  If you don't specify an authz-db,
### no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz        # 使用权限文件

4.4.2 authz file

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe

# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
# 在末尾添加信息
admin = admin   # 管理员用户admin分组属于admin组
[/]             # 从仓库开始设置权限
@admin = rw     # 管理员组的权限是读写

4.4.3 passwd file

[users]
# harry = harryssecret
# sally = sallyssecret
admin = 123456    # 在末尾添加用户和密码,明文输入

4.5 Start the server

ubuntu@ubuntu:/mnt/DbDisk/svn/test/conf$ sudo svnserve -d -r /mnt/DbDisk/svn
  • -d: flag starts in daemon mode
  • -r: Set the root directory of the svn repository, so do not enter the full path when accessing
  • Others: Not studied yet.

4.6 View connection status

ubuntu@ubuntu:~$ ps -aux | grep svnserve
root        1588  0.0  0.0  18904  2552 ?        Ss   07:46   0:00 svnserve -d -r /mnt/DbDisk/svn
ubuntu      1598  0.0  0.0   6420  1864 pts/0    S+   07:51   0:00 grep --color=auto svnserve
u

If you see the service, it means that the server started successfully.

4.7 Stop the server

killall svnserve

5 access to svn

5.1 View port

ubuntu@ubuntu:~$ sudo netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      822/systemd-resolve
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      1588/svnserve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      987/sshd: /usr/sbin
tcp        0      0 192.168.1.17:22         192.168.1.19:60135      ESTABLISHED 1312/sshd: ubuntu [
tcp6       0      0 :::3389                 :::*                    LISTEN      936/xrdp
tcp6       0      0 ::1:3350                :::*                    LISTEN      896/xrdp-sesman
tcp6       0      0 :::22                   :::*                    LISTEN      987/sshd: /usr/sbin
udp        0      0 127.0.0.53:53           0.0.0.0:*                           822/systemd-resolve
udp        0      0 192.168.1.17:68         0.0.0.0:*                           820/systemd-network
udp6       0      0 fe80::dea6:32ff:fe4:546 :::*                                820/systemd-network
raw6       0      0 :::58                   :::*                    7           820/systemd-network

View the port number of the svn service through sudo netstat -anp, here we can see that the default port of the svn server is 3690.

5.2 Open the svn server port

ubuntu@ubuntu:~$ sudo ufw allow 3690    # 开放端口
Rule added
Rule added (v6)
ubuntu@ubuntu:~$ sudo ufw status        #检查端口状态
Status: active

To                         Action      From
--                         ------      ----
3690                       ALLOW       Anywhere
3690 (v6)                  ALLOW       Anywhere (v6)

After the port is opened, it can be accessed from the outside.

5.3 Access to svn repository

I access it with the svn client in the window environment:

Try to create a folder:

 5.4 Have fun

Looking at the information on the Internet, I feel that I know it. In fact, I still need to practice it to find the problem. Only after configuring it by myself can I gain something.

Guess you like

Origin blog.csdn.net/u010839204/article/details/130028790