Project

General

Profile

ServerSetup » History » Version 1

Anonymous, 12/19/2021 05:12 PM
adding original page

1 1
h1. Server Setup
2
3
In late 2012 I decided it was time to retire the old Dell desktop (the original phalanx) that had been limping along as my fileserver and build a proper fileserver.  The new [[wiki:/CustomComputers/2012/Phalanx|phalanx]] was born. Here are some of the important design/configuration decisions that I made:
4
5
* boot drive is a small SSD that is separate from the storage array which allows OS to be upgraded independently of file storage
6
* software RAID 5 (device mapper raid) using 6 X 3TBB HDDs (12 TB raw, ~11.1 TB useable)
7
8
Although phalanx's primary purpose is as an internal fileserver, it runs 24/7 and has plenty of spare cycles to also act as a webserver. Below are some of the things it is currently running.
9
10
h2. Update History
11
12
*7/8/2019*
13
14
   * Change Dynamic DNS provider to http://freedns.afraid.org. 
15
   
16
*1/9/2019*
17
18
  * Added 10G Ethernet interface.
19
  
20
*1/4/2019*
21
22
  * Replaced mobo/proc/RAM with parts salvaged from work. Proc i7-4790 (Haswell); RAM 32GB DDR3L.
23
24
*6/2/2018*
25
26
  * Upgraded boot drive to 500 GB SSD. Also installed Ubuntu 18.04 LTS.*
27
28
*1/16/2017*
29
30
  * Upgraded server added 2 x 3 TB additional HDDs (via PCIe SATA expansion card), new power supply, and new (slightly used) case.  After adding the new disks to the RAID and growing the file system, total usable storage on the array is now 11.18 TB.
31
32
   Parts List:
33
   ** 2 - Seagate 3TB BarraCuda SATA (ST3000DM008) 3.5-Inch Internal Hard Drive ($89.99 each)
34
   ** IO Crest SI-PEX40062 4 Port SATA III PCIe 2.0 X2 Controller Card ($37.99)
35
   ** SeaSonic G Series 550-Watt 80 PLUS GOLD Certified Modular Active PFC Power Supply SSR-550RM ($69.99)
36
   ** Corsair case (scavenged for free)
37
38
  * Instructions for adding disks, growing the array, and then growing the file system are below.
39
  
40
*11/18/2016*
41
42
  * Updated (wipe and reinstall) to Ubuntu Server 16.04.1 LTS
43
  
44
*9/2015*
45
46
   * I recently decided to pay for dynamic DNS service from "Dyn":http://dyn.com.  The cost was $30 (after 25% coupon) for a year w/ 30 hostnames. Server is now reachable at https://baranovich.homelinux.org:3268
47
   
48
*8/2014*  
49
50
 * Both of the my original 3TB HDDs started acting funny and died within a week of each other after about 1.8 years of continuous use.  Fortunately I reacted immediately and I was able to back up all of my data onto other disks. Although I regularly back up all of my critical data I decided that I really don't want to have to deal with losing any of my data.  I promptly purchased another HDD and a HW RAID card (an LSI MegaRAID SAS 9240-8i) and set out to build a RAID 5 array.  I quickly ran into problems with the RAID card.  I was only able to get the computer to boot with it installed once.  During that boot I upgraded the card's firmware with the hope that it would fix all my issues, but it did not and I was never able to fully boot with the card installed again.  After a little googling I discovered someone in my same position who claimed to have called LSI tech support and was told that LSI cards are "not compatible with newer motherboards".  The guy didn't elaborate as to what that meant but I assume it means LSI cards don't work in UEFI motherboards. I was disappointed but I started reading about software raid (device mapper raid) and decided that it should work perfectly for my little fileserver.  I also decided that btrfs is not really ready for prime time and I should use some other file system.
51
52
h2. OS Configuration
53
54
Current (November 2016) OS information:
55
| *Ubuntu Version:* | Ubuntu 18.04 Server LTS |
56
| *Kernel Version:* | 4.15.0-XX |
57
58
h2. DNS
59
60
Current hostname is: https://phalanx.homelinuxserver.org
61
62
To configure automatic DNS updates, make sure to install @ddclient@:
63
<pre>
64
$ sudo apt-get install ddclient
65
</pre>
66
Then follow instructions to log into account and select correct hostname.
67
68
h2. Network Interfaces
69
70
|*Interface*        | *MAC*           | *Reserved IP*        | *Notes*  |
71
|enp4s0             |d0:50:99:51:75:a4|192.168.8.6           |primary interface gigabit|
72
|enp5s0             |d0:50:99:51:75:a5|                      |secondary gigabit (unused)|
73
|enp1s0f0           |0c:c4:7a:1f:00:ae|192.168.250.3 (static)|10G fiber interface; direct to enthoo|
74
|enp1s0f1           |0c:c4:7a:1f:00:af|192.168.250.1 (static)|10G fiber interface; direct to brutus|
75
|ipmi               |bc:5f:f4:fe:6b:cb|192.168.208.1         |IPMI interface|
76
77
h2. Storage Configuration 
78
79
The software RAID5 array is block device @/dev/md0@ which is mounted at @/storage@; total usable storage is about -5.5TB- 11.1TB with the current drive configuration
80
81
The primary mechanism for accessing the storage on phalanx is via NFS v4. I have found that performance is excellent (much better than samba!) and NFS is supported fairly well on both Mac OS and Linux, which are the main client OSes I use.  The only annoyance I discovered is that uids on all systems MUST match.  This is no big deal on Linux, but I had to manually change my uid on Mac OS, which was not as easy as it should have been. 
82
83
h3. Storage setup
84
85
*NOTE:* After installing Ubuntu 16.04.1 I was pleasantly surprised to discover that none of the steps below were necessary.  The software RAID had already been found and assembled for me.  The stuff below is for reference.
86
87
* Install mdadm:
88
<pre>
89
$ sudo aptitude install mdadm xfsprogs
90
</pre>
91
* For each drive (sdb, sdc, sdd):
92
<pre>
93
# parted -a optimal /dev/sdb
94
GNU Parted 2.3
95
Using /dev/sdb
96
Welcome to GNU Parted! Type 'help' to view a list of commands.
97
(parted) mklabel gpt
98
Warning: The existing disk label on /dev/sdd will be destroyed and all data on
99
this disk will be lost. Do you want to continue?
100
Yes/No? y
101
(parted) mkpart primary 0% 100%
102
(parted) align-check opt 1
103
1 aligned
104
(parted) quit
105
Information: You may need to update /etc/fstab.
106
</pre>
107
* Create the array using mdadm:
108
<pre>
109
# mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sd[b-d]1
110
</pre>
111
* The above step takes quiet a while, about 6 hours in my case. To watch progress:
112
<pre>
113
$ watch cat /proc/mdstat
114
</pre>
115
* Once this is done you can create the XFS file system on the new @/dev/md0@ block device:
116
<pre>
117
$ sudo mkfs -t xfs -d su=512k -d sw=2 /dev/md0
118
</pre>
119
* To make sure the array reappears after reboot:
120
<pre>
121
# mdadm --examine --scan >> /etc/mdadm/mdadm.conf  # NOTE: this syntax is deprecated and no longer works!
122
# mdadm --detail --scan >> /etc/mdadm/mdadm.conf
123
# update-initramfs -u
124
</pre>
125
* If any issues arise you can stop a software RAID and reassemble it using:
126
<pre>
127
$ sudo mdadm --stop /dev/md127
128
$ mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1 /dev/sdd1
129
</pre>
130
* To view array status:
131
<pre>
132
dsorber@phalanx:~$ sudo mdadm --detail /dev/md0
133
/dev/md0:
134
        Version : 1.2
135
  Creation Time : Fri Aug 22 17:05:41 2014
136
     Raid Level : raid5
137
     Array Size : 11720534016 (11177.57 GiB 12001.83 GB)
138
  Used Dev Size : 2930133504 (2794.39 GiB 3000.46 GB)
139
   Raid Devices : 5
140
  Total Devices : 5
141
    Persistence : Superblock is persistent
142
143
    Update Time : Fri Jan 20 16:45:45 2017
144
          State : clean 
145
 Active Devices : 5
146
Working Devices : 5
147
 Failed Devices : 0
148
  Spare Devices : 0
149
150
         Layout : left-symmetric
151
     Chunk Size : 512K
152
153
           Name : phalanx:0  (local to host phalanx)
154
           UUID : 54bfb945:47ec32da:d2ccc4db:9d3615fa
155
         Events : 4001
156
157
    Number   Major   Minor   RaidDevice State
158
       0       8       17        0      active sync   /dev/sdb1
159
       1       8       33        1      active sync   /dev/sdc1
160
       3       8       49        2      active sync   /dev/sdd1
161
       5       8       81        3      active sync   /dev/sdf1
162
       4       8       65        4      active sync   /dev/sde1
163
</pre>
164
* @/etc/fstab@
165
<pre>
166
# /etc/fstab: static file system information.
167
#
168
# Use 'blkid' to print the universally unique identifier for a
169
# device; this may be used with UUID= as a more robust way to name devices
170
# that works even if disks are added and removed. See fstab(5).
171
#
172
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
173
# / was on /dev/sda1 during installation
174
UUID=66e8057c-1b75-40ba-8ceb-480b6e4405ab /               ext4    errors=remount-ro 0       1
175
176
/dev/md0        /storage        xfs     rw,nobarrier,noatime,nodiratime 0       0
177
/storage        /export/storage    none    bind    0    0
178
</pre>
179
180
h3. NFS setup:
181
182
* Install NFS (note additional settings below under firewall configuration):
183
<pre>
184
$ sudo apt install nfs-kernel-server
185
</pre>
186
187
* Edit @/etc/fstab@ and add to mount @/storage@ on @/exports/storage@:
188
<pre>
189
/storage	/export/storage    none    bind    0    0
190
</pre>
191
* Edit @/etc/exports@:
192
<pre>
193
/export            10.0.0.0/24(rw,fsid=0,insecure,no_subtree_check,async)
194
/export/storage    10.0.0.0/24(rw,nohide,insecure,no_subtree_check,async)
195
</pre>
196
* Restart NFS:
197
<pre>
198
$ sudo systemctl restart nfs-kernel-server
199
</pre>
200
201
h2. Firewall Configuration
202
203
|= *Port* =|= *Description*=|
204
|22|ssh|
205
|80|http|
206
|111|SUN rpc|
207
|443|https|
208
|2049|NFS|
209
|3142|apt-cacher-ng|
210
|4045|lockd|
211
|17641|NFS connect|
212
|61993|bt|
213
214
It was a bit annoying to get NFS working when the firewall was enabled but I found some good instructions and got them to work.  The issue was that some of the important rpc/NFS daemons use random ports when they boot up.
215
216
* Edit @/etc/default/nfs-kernel-server@ comment out this line:
217
<pre>
218
RPCMOUNTDOPTS=--manage-gids
219
</pre>
220
 add this line
221
<pre>
222
RPCMOUNTDOPTS="--port 17641"
223
</pre>
224
* Edit/create @/etc/modprobe.d/options.conf@:
225
<pre>
226
options lockd nlm_udpport=4045 nlm_tcpport=4045
227
</pre>
228
* Edit @/etc/modules@ and add @lockd@ on its own line:
229
<pre>
230
...
231
lockd
232
</pre>
233
* Now create the firewall rules (only allow incoming access for the local network), for each port in the table above:
234
<pre>
235
$ sudo ufw allow from 10.0.0.0/24 to any port <PORT>
236
</pre>
237
* Add external allow rules (i.e. up these ports to the outside world) for ssh, https, and bt :
238
<pre>
239
$ sudo ufw allow <PORT>
240
</pre>
241
* Start ufw:
242
<pre>
243
$ sudo ufw enable
244
</pre>
245
Overview of added rules:
246
<pre>
247
sudo ufw allow proto tcp to 0.0.0.0/0 port 22
248
sudo ufw allow proto tcp to 0.0.0.0/0 port 443
249
sudo ufw allow proto tcp to 0.0.0.0/0 port 61993
250
251
sudo ufw allow from 192.168.4.0/24 to any port 111
252
sudo ufw allow from 192.168.4.0/24 to any port 2049
253
sudo ufw allow from 192.168.4.0/24 to any port 3142
254
sudo ufw allow from 192.168.4.0/24 to any port 4045
255
sudo ufw allow from 192.168.4.0/24 to any port 17641
256
257
sudo ufw allow from 192.168.8.0/24 to any port 111
258
sudo ufw allow from 192.168.8.0/24 to any port 2049
259
sudo ufw allow from 192.168.8.0/24 to any port 3142
260
sudo ufw allow from 192.168.8.0/24 to any port 4045
261
sudo ufw allow from 192.168.8.0/24 to any port 17641
262
263
sudo ufw allow from 192.168.20.0/24 to any port 3142
264
265
sudo ufw allow from 192.168.250.0/24 to any port 111
266
sudo ufw allow from 192.168.250.0/24 to any port 2049
267
sudo ufw allow from 192.168.250.0/24 to any port 4045
268
sudo ufw allow from 192.168.250.0/24 to any port 17641
269
</pre>
270
271
272
h2. Apache
273
274
I didn't originally document my Apache setup, but when wiping to install 14.04 I remedied this. The [[source:Default Repo/configs/apache|Apache configs]], are the really important part here. Below is a section on each application that's running on/from Apache.  I am using https with a permanent redirect from port 80 along with a self-signed certificate.  Most of the sections below are password protected using mod_auth_digest.  The appropriate digest file is created and managed with the "htdigest":http://httpd.apache.org/docs/2.2/programs/htdigest.html tool. *NOTE:* make sure the password digest file (e.g. @/home/dsorber/web_users@) is owned by @www-data:www-data@ and permissions are set to @600@.
275
276
* Install apache2 itself:
277
<pre>
278
$ sudo aptitude install apache2
279
</pre>
280
* Enable apache modules:
281
<pre>
282
$ sudo a2enmod ssl proxy proxy_http auth_digest
283
</pre>
284
* Copy backed up apache configs to their location:
285
<pre>
286
$ sudo cp apache_configs/* /etc/apache2/sites-available/
287
</pre>
288
* Setup SSL cert:
289
<pre>
290
cd /etc/apache2
291
sudo mkdir ssl
292
sudo cp baranovich.{crt,key} /etc/apache2/ssl
293
</pre>
294
* Turn on main site (also disable default apache2 site):
295
<pre>
296
$ sudo a2ensite main
297
</pre>
298
Overview of rules to add:
299
<pre>
300
sudo ufw allow proto tcp to 0.0.0.0/0 port 22
301
sudo ufw allow proto tcp to 0.0.0.0/0 port 443
302
sudo ufw allow proto tcp to 0.0.0.0/0 port 61993
303
304
sudo ufw allow from 192.168.4.0/24 to any port 111
305
sudo ufw allow from 192.168.4.0/24 to any port 2049
306
sudo ufw allow from 192.168.4.0/24 to any port 4045
307
sudo ufw allow from 192.168.4.0/24 to any port 17641
308
309
sudo ufw allow from 192.168.8.0/24 to any port 111
310
sudo ufw allow from 192.168.8.0/24 to any port 2049
311
sudo ufw allow from 192.168.8.0/24 to any port 4045
312
sudo ufw allow from 192.168.8.0/24 to any port 17641
313
314
sudo ufw allow from 192.168.250.0/24 to any port 111
315
sudo ufw allow from 192.168.250.0/24 to any port 2049
316
sudo ufw allow from 192.168.250.0/24 to any port 4045
317
sudo ufw allow from 192.168.250.0/24 to any port 17641
318
</pre>
319
320
h3. Transmission
321
322
I use "Transmission":http://www.transmissionbt.com/|Transmission]] to download Linux .isos and give back to the community by sharing them using my own bandwidth. Transmission with its webui runs as a separate daemon so apache is configured to act as reverse proxy.
323
324
Transmission has its own [[source:Default Repo/configs/settings.json|configuration file]].
325
326
* Install transmission daemon:
327
<pre>
328
$ sudo aptitude install transmission-daemon
329
</pre>
330
* Copy over configuration:
331
<pre>
332
$ sudo systemctl stop transmission-daemon.service
333
$ sudo cp settings.json /etc/transmission-daemon
334
$ sudo systemctl start transmission-daemon.service
335
</pre>
336
* Make sure the user digest file is in place:
337
<pre>
338
$ cd /home/dsorber
339
$ cp web_users .
340
</pre>
341
* Enable site:
342
<pre>
343
$ sudo a2ensite transmission
344
</pre>
345
346
h3. Trac + Git
347
348
Make sure to backup the @trac@ folder and then install is a breeze. The trac projects live at @/home/dsorber/trac/projects@, there is currently only one project.
349
350
* Install git, mod_wsgi, and setuptools:
351
<pre>
352
$ sudo apt install git libapache2-mod-wsgi python-pip
353
</pre>
354
* Install trac:
355
<pre>
356
$ sudo pip install trac
357
</pre>
358
* Fix/adjust permissions:
359
<pre>
360
cd ~/trac/projects/headquarters
361
sudo chown -R www-data:www-data db/
362
sudo chown -R www-data:www-data log/
363
</pre>
364
* Enable site:
365
<pre>
366
$ sudo a2ensite trac
367
</pre>
368
* Also install Pygments for syntax highlighting:
369
<pre>
370
$ sudo pip install pygments
371
</pre>
372
373
After using Git a bit at work I decided that I'd give it a try for my personal use.  I'm still getting used to a few things but overall I like it.  Apparently I have configured git over ssh. My git repository clone path is:
374
<pre>
375
git clone /home/dsorber/trac/projects/headquarters/repo.git
376
</pre>
377
378
h3. Nextcloud
379
380
"Nextcloud":https://nextcloud.com/|Nextcloud is a self-hosted "cloud". It allows easy file viewing and sharing as well as !CardDav and !CalDav servers:
381
382
* Install necessary packages including MariaDB (MySQL):
383
<pre>
384
sudo apt install apache2 mariadb-server libapache2-mod-php7.2 php7.2-gd php7.2-json php7.2-mysql php7.2-curl php7.2-mbstring php7.2-intl php-imagick php7.2-xml php7.2-zip unzip
385
</pre>
386
* Download latest Nextcloud release (example) and unzip it:
387
<pre>
388
$ wget https://download.nextcloud.com/server/releases/nextcloud-13.0.2.zip
389
$ unzip nextcloud-13.0.2.zip
390
</pre>
391
* Move Nextcloud to webserver directory and change permissions:
392
<pre>
393
$ sudo mv nextcloud /var/www
394
$ sudo chown -R www-data:www-data /var/www/nextcloud/
395
</pre>
396
* Copy in apache config and enable necessary modules:
397
<pre>
398
$ cp nextcloud.conf /etc/apache2/sites-available/
399
$ sudo a2ensite nextcloud.conf 
400
$ sudo a2enmod rewrite headers env dir mime
401
$ sudo systemctl restart apache2
402
</pre>
403
* For some reason MariaDB does not setup an admin account when it is installed so you must do so manually. Keep this password in a safe place.
404
<pre>
405
$ sudo mysql --user=root mysql
406
407
% CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'Apassword';
408
% GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;
409
% FLUSH PRIVILEGES;
410
% exit
411
</pre>
412
* Now goto the web interface and enter the necessary information.
413
414
h4. Other configuration
415
416
* To setup local storage: go to Apps > Disabled Apps > External Storage (click Enable)
417
* To setup pretty URLS:
418
 * https://docs.nextcloud.com/server/13/admin_manual/installation/source_installation.html#pretty-urls
419
 * <pre> $ sudo vim /var/www/nextcloud/config/config.php </pre>
420
 * <pre> $ sudo systemctl restart apache2 </pre>
421
422
h2. Misc
423
* Setup the display script:
424
 * Edit @~/.profile@ and add @./repo/software/misc/display.py@
425
* Setup checker script:
426
 * 
427
<pre>
428
$ sudo su
429
# crontab -e
430
</pre>
431
 add this line:
432
<pre>
433
0 * * * *       /home/dsorber/repo/software/misc/checker.py
434
</pre>
435
* Install @apt-cacher-ng@:
436
<pre>
437
$ sudo apt install apt-cacher-ng
438
</pre>
439
 * Edit @/etc/apt/apt.conf.d/02proxy@ add: @Acquire::http::Proxy "http://192.168.8.6:3142";@
440
441
----
442
443
h3. Sources
444
445
* "Adding an extra disk to an mdadm array":http://zackreed.me/adding-an-extra-disk-to-an-mdadm-array/
446
* https://raid.wiki.kernel.org/index.php/Growing
447
* "Ubuntu Setting Up NFS HowTo":https://help.ubuntu.com/community/SettingUpNFSHowTo
448
* http://ubuntuforums.org/showthread.php?t=2228292
449
* http://www.mysolutions.it/tutorial-mdadm-software-raid-ubuntu-debian-systems/
450
* http://ubuntuforums.org/showpost.php?p=7959294&postcount=17
451
* http://trac.edgewall.org/wiki/TracModWSGI
452
* "Pro Git":http://git-scm.com/book
453
* http://baikal-server.com/
454
* https://github.com/jeromeschneider/Baikal
455
* https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/
456
* https://wiki.archlinux.org/index.php/Btrfs
457
* https://blog.packagecloud.io/eng/2015/05/05/using-apt-cacher-ng-with-ssl-tls/