Local Mirror

From Gentoo Wiki
Jump to:navigation Jump to:search

This page contains information on how to run a private, local Gentoo rsync mirror.

Note
To help the Gentoo project by providing public mirrors, please see the relevant documentation for source and rsync mirrors.

Setting up the mirror

Many users run Gentoo on several machines and need to sync the Gentoo repository on all of them. Using public mirrors is simply a waste of bandwidth at both ends. Syncing only one machine against a public mirror and all others against that computer would save resources on the public mirrors and save users' bandwidth.

The same holds true for organizations who would like to control the rsync mirror their servers and workstations sync against. Of course, they usually also want to save on bandwidth and traffic costs.

Select which machine is going to be the local rsync mirror and set it up. Choose a computer that can handle the CPU and disk load that an rsync operation requires. The local mirror also needs to be available whenever any of the other computers syncs its ebuild repository. Besides, it should have a static IP address or a name that always resolves to the server. Configuring a DHCP and/or a DNS server is beyond the scope of this guide.

Setting up the server

There is no extra package to install as the required software is already on the computer. Setting up a local rsync mirror is just a matter of configuring the rsyncd daemon to make the Gentoo repository directory available for syncing.

Currently, the Gentoo repository is now located by default at: /var/db/repos/gentoo . Older legacy installations used /usr/portage . Please be sure to enter the proper path in the following example. Create a /etc/rsyncd.conf configuration file such as this:

FILE /etc/rsyncd.conf
pid file = /run/rsyncd.pid
max connections = 5
use chroot = yes
uid = nobody
gid = nobody
# Optional: restrict access to some Gentoo boxes
hosts allow = 192.168.0.1 192.168.0.2 192.168.1.0/24
hosts deny  = *
motd file = /etc/rsync/rsyncd.motd
  
[gentoo-portage]
path=/var/db/repos/gentoo
comment=Gentoo Ebuild Repository

The hosts allow and hosts deny settings are optional and not needed. Without them, all clients will be allowed to connect to the mirror. The order in which the options are written is not relevant. The server will always check the hosts allow option first and grant the connection if the connecting host matches any of the listed patterns. The server will then check the hosts deny option and refuse the connection if any match is found. Any host that does not match anything will be granted a connection. See the man page (man rsyncd.conf) for more advanced configuration information.

Service

Now, start the rsync daemon with the following command as the root user:

OpenRC

root #/etc/init.d/rsyncd start
root #rc-update add rsyncd default

systemd

root #systemctl start rsyncd.service
root #systemctl enable rsyncd.service

Testing the server

It is time to test the rsync mirror. Test first locally and then again from the desired other machine.

Perform the following tests, using the local IP, or hostname. If the hostname can not be resolved by all computers, just refer to it by IP address instead.

root #rsync 192.168.0.1::
gentoo-portage     Gentoo Ebuild Repository

This one-line response indicates good communication with the configured rsync server.

root #rsync 192.168.0.1::gentoo-portage

The content of /var/db/repos/gentoo should be visible on the mirror.

If the tests are unsuccessful, make sure the rsyncd service was actually started, there are no errors in the config file, and a local firewall is not blocking rsyncd's TCP port 873.

If the tests ARE successful, The rsync mirror is now set up.

Running emerge --sync on this system will keep the server up-to-date. If cron or similar facilities to sync regularly, remember to keep it down to a sensible frequency like once or twice a day.

Note
Please note that most public mirror administrators consider syncing more than once or twice a day an abuse. If the abuse limit is reached most mirrors will ban the abusers IP address from their server(s).

Configuring the clients

Now, make the other computers use the local rsync mirror instead of a public one, by changing the sync-uri entry in the appropriate file in /etc/portage/repos.conf/.

Copying the default Gentoo repo file for configuration

One method of configuring the client would be to copy the default repo configuration file for Gentoo from /usr/share/portage/config/repos.conf to /etc/portage/repos.conf/, and then editing the sync-uri = ... line appropriately.

An example configuration file might look like:

FILE /etc/portage/repos.conf/gentoo-mirror.conf
# replace HOST_IP with the local IP address of the host machine

[gentoo]
location = /var/db/repos/gentoo
sync-type = rsync
sync-uri = rsync://HOST_IP/gentoo-portage
#other options here
Note
The local IP of the server can be found by running ip addr on the server.

See also