summaryrefslogtreecommitdiff
path: root/public/posts/local-apt-mirror/index.html
blob: 5b47e578e74c01da6de21e45d1885683d3b43737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en-us">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<style type=text/css>body{font-family:monospace;}</style>
	<title>Local Apt Mirror</title>
	
	
	<link rel="stylesheet" href="/css/style.css">
	
	
</head>
<body>
	<header>
	==========================<br>
	== <a href="https://blog.tinfoil-hat.net">blog.tinfoil-hat.net</a> ==<br>
	==========================
	<div style="float: right;">A save home for every tinfoil-hat!</div><br>
	<p>
	<nav>
			<a href="/"><b>Start</b></a>.
			
			
			<a href="/posts/"><b>Posts</b></a>.
			
			<a href="/categories/"><b>Categories</b></a>.
			
			<a href="/tags/"><b>Tags</b></a>.
			
	</nav>
	</p>
	<script async defer data-website-id="9b2f4923-27f6-41ac-ba15-43c51d35250e" src="https://stats.tinfoil-hat.net/umami.js"></script>
	
</header>

	
	<main>
		<article>
			<h1>Local Apt Mirror</h1>
			<b><time>19.10.2023 14:47</time></b>
		       
		           <a href="/tags/linux">Linux</a>
        	       
		           <a href="/tags/server">Server</a>
        	       
		           <a href="/tags/technology">Technology</a>
        	       

			<div>
				<h1 id="how-do-make-a-local-debian-apt-mirror">How do make a local debian apt mirror</h1>
<p>To create a local Debian APT mirror, you can follow these general steps:</p>
<p>Set up a server: You will need a server with sufficient storage capacity and network bandwidth to host the mirror.</p>
<p>Install the necessary packages: Start by installing the apt-mirror package, which is available in the Debian repositories. Use the following command to install it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install apt-mirror
</span></span></code></pre></div><p>Configure the mirror: Open the apt-mirror configuration file using a text editor. The file is located at <code>/etc/apt/mirror.list</code>. You can use the following command to open it with nano or vim:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo nano /etc/apt/mirror.list
</span></span></code></pre></div><p>Inside the file, you need to define the repositories you want to mirror. Uncomment the lines for the desired repositories, or add new lines if needed. For example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>deb http://deb.debian.org/debian buster main contrib non-free
</span></span><span style="display:flex;"><span>deb-src http://deb.debian.org/debian buster main contrib non-free
</span></span></code></pre></div><p>Save the file after making the necessary changes.</p>
<p>Configure the mirror directory: By default, apt-mirror uses the directory <code>/var/spool/apt-mirror</code> to store the mirrored files. Ensure that you have enough space available in that directory, or specify a different location in the apt-mirror configuration file if needed.</p>
<p>Run <code>apt-mirror: Execute the apt-mirror command with root privileges to start the mirroring process</code>. Use the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-mirror
</span></span></code></pre></div><p>The mirroring process will take some time, depending on the speed of your network connection and the size of the repositories you&rsquo;re mirroring. Ensure that the server remains connected to the internet during this process.</p>
<p>Serve the mirror using a web server: After the mirroring process completes, you need to serve the mirror using a web server. You can use any web server of your choice, such as Apache or Nginx. Install and configure the web server, ensuring that it points to the mirror directory you specified earlier.</p>
<p>Configure clients to use the local mirror: On the machines where you want to use the local mirror, modify the <code>/etc/apt/sources.list</code> file to point to your mirror&rsquo;s URL. Replace the original Debian repository URLs with the URL of your local mirror. For example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>deb http://your-mirror-url/debian buster main contrib non-free
</span></span><span style="display:flex;"><span>deb-src http://your-mirror-url/debian buster main contrib non-free
</span></span></code></pre></div><p>Save the file after making the changes.</p>
<p>That&rsquo;s it! Your local Debian APT mirror should be ready to use. Clients can now update and install packages from the mirror, which will be significantly faster than downloading from the official Debian repositories. Remember to periodically update your mirror by running apt-mirror again to keep it synchronized with the official repositories.</p>
<h1 id="provide-apt-mirror-via-apache2">Provide Apt-mirror via Apache2</h1>
<p>Install Apache2: If you don&rsquo;t already have Apache2 installed, you can install it using the package manager. On Debian-based systems, you can use the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install apache2
</span></span></code></pre></div><p>Configure Apache2: Once Apache2 is installed, you need to configure it to serve your APT mirror. Open the Apache2 configuration file using a text editor. On Debian-based systems, the file is located at <code>/etc/apache2/sites-available/000-default.conf</code>. Use the following command to open it with nano or vim:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo nano /etc/apache2/sites-available/000-default.conf
</span></span></code></pre></div><p>Inside the file, you need to add a new Alias directive that maps a URL path to the directory where your mirror is located. For example, if your mirror is stored in <code>/var/spool/apt-mirror</code>, you can add the following line within the <code>&lt;VirtualHost&gt;</code> block:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Alias /debian /var/spool/apt-mirror/mirror/deb.debian.org/debian
</span></span></code></pre></div><p>Save the file after making the changes.</p>
<p>Enable the Alias module: By default, the alias module is not enabled in Apache2. Enable it using the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo a2enmod alias
</span></span></code></pre></div><p>Restart Apache2: After making the configuration changes, restart Apache2 for the changes to take effect:</p>
<pre tabindex="0"><code>sudo service apache2 restart
</code></pre><p>Test the mirror: Open a web browser and enter the URL <strong>http://your-server-ip/debian</strong> (replace your-server-ip with the IP address or hostname of your server). You should see the directory listing of the Debian mirror, indicating that Apache2 is serving the mirror correctly.</p>
<p><strong>Note:</strong> If you want to restrict access to the mirror and only allow specific clients to use it, you can configure Apache2 to add authentication or restrict access based on IP addresses.</p>
<p>With these steps, you have configured Apache2 to provide your local Debian APT mirror. Clients can now update their <code>/etc/apt/sources.list</code> file to point to your mirror URL, such as <strong>http://your-server-ip/debian</strong>, and use it to download packages from the local mirror.</p>

			</div>
		</article>
	</main>
<aside>
	<div>
		<div>
			<h3>LATEST POSTS</h3>
		</div>
		<div>
			<ul>
				
				<li><a href="/posts/removed-services/">Service Update: Discontinuation Due to Frontend-Backend Incompatibility</a></li>
				
				<li><a href="/posts/revert-brave-flatpak-to-deb/">Revert Brave Flatpak to Deb</a></li>
				
				<li><a href="/posts/proxmox-docker-workstation/">Proxmox Docker Workstation</a></li>
				
				<li><a href="/posts/local-apt-mirror/">Local Apt Mirror</a></li>
				
				<li><a href="/posts/the-black-and-the-white-wolf/">The Black and the White Wolf</a></li>
				
			</ul>
		</div>
	</div>
</aside>


	<footer>
	<p>&copy; 2023 <a href="https://blog.tinfoil-hat.net"><b>blog.tinfoil-hat.net</b></a>.
	<a href="https://tinfoil-hat.net"><b>Landing Page</b></a>.
	<a href="http://keys.gnupg.net/pks/lookup?op=vindex&amp;fingerprint=on&amp;search=0xC0090D40CFE34966"><b>GPG-Fingerprint</b></a>.
	<a href="mailto:mal@tinfoil-hat.net"><b>E-Mail</b></a>.
	<a href="https://git.tinfoil-hat.net"><b>Gitweb</b></a>.
	</p>
</footer>

</body>
</html>