summaryrefslogtreecommitdiff
path: root/maintenance.html
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2021-06-29 08:30:52 -0400
committerLuke Smith <luke@lukesmith.xyz>2021-06-29 08:30:52 -0400
commit825282fea9102326ad2538e4a98329fbd38c899b (patch)
tree678dd28280fd542242ed041778e353c2ac511ae1 /maintenance.html
firststuffs
Diffstat (limited to 'maintenance.html')
-rw-r--r--maintenance.html148
1 files changed, 148 insertions, 0 deletions
diff --git a/maintenance.html b/maintenance.html
new file mode 100644
index 0000000..33a772b
--- /dev/null
+++ b/maintenance.html
@@ -0,0 +1,148 @@
+<!DOCTYPE html>
+<html lang=en>
+ <head>
+ <title>Maintaining a Server &ndash; LandChad.net</title>
+ <meta charset="utf-8"/>
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
+ <link rel='stylesheet' type='text/css' href='style.css'>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel='alternate' type='application/rss+xml' title='Land Chad RSS' href='/rss.xml'>
+ </head>
+<body>
+ <header><h1>Maintaining a Server</h1></header>
+ <nav></nav>
+ <main>
+
+ <p>Here are some important topics you should be familiar with whenever you are managing a server.</p>
+ <h2>Keep packages up to date.</h2>
+ <p>All GNU/Linux distributions use package managers to easily be able to install and update packages without manually downloading them.
+ On Debian, which we use here for these tutorial the package manager is <code>apt-get</code> or <code>apt</code> for short.
+ </p>
+
+ <p>
+ It's a good idea to use <code>apt</code> to keep your software reasonably up to date.
+ </p>
+
+ <pre><code>apt update
+apt upgrade</code></pre>
+
+ <p>
+ Not only do up-to-date packages often come with more features, but they can also fix any possible security bugs.
+ </p>
+
+ <h2>Troubleshooting general problems</h2>
+ <p>
+ Often when you are installing something new, you might miss a step and run into an error, so it's important to know how to check and see what errors have happened on your computer.
+ </p>
+ <p>On Debian and other GNU/Linux distributions that use systemd (most of them), you can use the command <code>journalctl</code> to look at the system's general log.
+ You will probably want to run <code>journalctl -xe</code> as the <code>-x</code> and <code>-e</code> as that gives the most information and starts you at the bottom of the log to see the most recent errors.
+ </p>
+ <p>
+ Some programs do not use this system log, but have their own logs stored in <code>/var/log/</code>, or sometimes it's more convenient to look at a specific program's log to see only its issues.
+ </p>
+
+ <p>For example, we can see that in <code>/var/log/nginx/</code>, nginx produces both <code>error</code> and <code>access</code> files.
+ The <code>access</code> files show you all the times people connect to files on your server and much more.
+ We can look at the most recent errors by running:
+ </p>
+
+ <pre><code>tail -n 25 /var/log/nginx/error.log</code></pre>
+
+ <p>
+ The command <code>tail -n 25</code> means "show me the last 25 lines of this file."
+ You can replace that with <code>less</code> to browse the whole file.
+ In <code>less</code>, navigate with arrows or vim-keys and exit with <code>q</code>.
+ </p>
+
+ <h3>systemctl</h3>
+
+ <p>
+ Another tool on systemd distributions is <code>systemctl</code>.
+ At a basic level, use <code>systemctl status put-service-name-here</code>
+ to see if a system service is running and its most recent log.
+ But there's much more to <code>systemctl</code>.
+ </p>
+
+ <p>
+ For example, you can run <code>systemctl stop nginx</code> to stop NginX and <code>systemctl start nginx</code> to start it back up (or use <code>restart</code> for both).
+ When you make changes to a program's configuration files, <code>reload</code> well make them reload them.
+ If you no longer want a service to start when the system is rebooted, use <code>disable</code>, or conversely, to make a service start on reboot use <code>enable</code>.
+ </p>
+
+ <h2 id=cronjobs>Cronjobs</h2>
+ <p>
+ You might want to have your server automatically run commands (like updating something) at a set time without having to tell it.
+ We can create a "cronjob" to schedule one of these regular commands.
+ To create a cronjob, simply run:
+ </p>
+
+ <pre><code>crontab -e</code></pre>
+
+ <aside>
+ <p>
+ It might ask you what editor you want to use if you run this for the first time.
+ Select <code>nano</code> if you don't know how to use vim.
+ </p>
+ </aside>
+
+ <p>
+ In this crontab file, we can add a line for a command.
+ Here is an example:
+ </p>
+
+ <p><strong>unfinished</strong></p>
+
+ <h2>Finding Files</h2>
+
+ <p>
+ Especially if you're new to how a GNU/Linux system is arranged, you might need help finding files.
+ To find program-related files, you can just use <code>whereis</code>:
+ </p>
+ <pre><code>$ whereis nginx
+nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz</code></pre>
+
+ <p>This command lists the directories related to that program. For example, <code>/etc/nginx</code> is where the configuration files are and <code>/usr/share/nginx</code> is where the library and module-like files are.</p>
+ <p>But <code>whereis</code> can be used only with installed programs.
+ A more general tool is the pair of <code>updatedb</code> and <code>locate</code>.
+ </p>
+
+ <p>
+ <code>updatedb</code> is a command that quickly indexes every file and directory on your computer.
+ Then you can run <code>locate</code> to find a file containing a given name.
+ After running <code>updatedb</code>, try running <code>locate nginx</code> to find all files with "nginx" in their name.
+ </p>
+
+ <p>
+ You can make your search more specific by chaining other Unix commands through pipes.
+ For example, <code>grep</code> takes input and returns only lines that match an extra argument.
+ In the example below, we <code>locate</code> all files with "nginx" in the name, but we use <code>grep</code> to only show us those with the word "available" in them.
+ </p>
+
+ <pre><code>root@landchad:~# locate <strong>nginx</strong> | grep <strong>available</strong>
+/etc/nginx/modules-available
+/etc/nginx/sites-available
+/etc/nginx/sites-available/default
+/etc/nginx/sites-available/landchad
+/usr/share/nginx/modules-available
+/usr/share/nginx/modules-available/mod-http-auth-pam.conf
+/usr/share/nginx/modules-available/mod-http-dav-ext.conf
+/usr/share/nginx/modules-available/mod-http-echo.conf
+/usr/share/nginx/modules-available/mod-http-geoip.conf
+/usr/share/nginx/modules-available/mod-http-image-filter.conf
+/usr/share/nginx/modules-available/mod-http-subs-filter.conf
+/usr/share/nginx/modules-available/mod-http-upstream-fair.conf
+/usr/share/nginx/modules-available/mod-http-xslt-filter.conf
+/usr/share/nginx/modules-available/mod-mail.conf
+/usr/share/nginx/modules-available/mod-stream.conf</code></pre>
+
+ <p>
+ <code>updatedb</code> is an ideal candidate for a cronjob so you don't have to worry about running each time.
+ For example, adding the following to your crontab will run <code>updatedb</code> every 30 minutes:
+ </p>
+ <pre><code>*/30 * * * * /usr/bin/updatedb</code></pre>
+ <p>
+ </p>
+ </main>
+ <footer><a href="https://landchad.net">LandChad.net</a></br>Because Everyone should be an Internet LandChad.</br><li><a href="index.html"><img src="pix/chad.gif" alt="chad"></a></li><li><a href="rss.xml"><img src="pix/rss.svg" alt="RSS"></a></li><li><a href="pix/btc.png"><img src="pix/btc.svg" alt="BTC"></a></li><li><a href="pix/xmr.png"><img src="pix/xmr.svg" alt="XMR"></a></li><li><a href="https://github.com/lukesmithxyz/landchad"><img src="pix/git.svg" alt="Github"></a></footer>
+</body>
+</html>