You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/RPi.rst
+51-114
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ Making Raspberry Pi usable
4
4
Introduction
5
5
----------------
6
6
7
-
After 3 months of using RPi, I decided to make this tutorial for same
7
+
After 8 months of using RPi, I decided to make second version of this tutorial for same
8
8
people as I'm - who looks for easy, understandable way to make RPi as
9
-
awesome as possible.
9
+
awesome as possible. Several things have changed since last realease of this tutorial, so I decided to rewrite some parts and also to delete some parts which are not necessary today.
10
10
11
11
In this tutorial I will walk you through whole process of making from
12
12
Raspberry Pi secure, reliable, efficient, fast and easy to maintain
@@ -44,6 +44,7 @@ What you don't need
44
44
-------------------
45
45
46
46
- Monitor or ability to connect RPi to some monitor
47
+
- Keyboard or mouse connected to your RPi
47
48
48
49
Start
49
50
-----
@@ -55,7 +56,7 @@ found them satisfaing.
55
56
Installing Arch Linux ARM to SD card
56
57
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
58
58
-
Go `here <http://Arch Linuxarm.org/platforms/armv6/raspberry-pi>`__ and
59
+
Go `here <http://Arch Linuxarm.org/platforms/armv6/raspberry-pi>`__, choose installation and
59
60
make first 3 steps. That's it! You have done it. You have you Arch Linux
60
61
ARM SD card :)
61
62
@@ -71,24 +72,23 @@ connects to the network (or even internet) as usuall?
71
72
72
73
If yes, it is great! You can procced. It is what we need - we need RPi,
73
74
when it boots up, to automatically connect to the network. Then we will
74
-
able to connect to it. You will need one more think to find out - which
75
-
IP address router asign to you when you connected by cable - it is very
76
-
probable that RPi will get the same, or similiar. Don't be afraid - it
77
-
is easy to get (IP address)[how to get ip address]. On modern systems,
75
+
able to connect to it. You will need one more thing to find out - which
76
+
IP address does router assign to you when you connect by cable - it is very
77
+
probable that RPi will get very similiar. Don't be afraid - it
78
+
is easy to get `IP address<http://apple.stackexchange.com/questions/19783/how-do-i-know-the-ip-addresses-of-other-computers-in-my-network>`_. On modern systems,
78
79
one command :) .
79
80
80
81
Ok, now you have to insert SD card to RPi and connect it to your router
81
82
with ethernet cable and then turn RPi on by inserting power supply. The
82
-
diodes starts flashing. Now back to your computer and we will try to
83
+
diods start flashing. Now back to your computer and we will try to
83
84
connect it using **SSH**. SSH is just "magic power" which enables to
84
-
connect from one to other computer.
85
+
connect to another computer.
85
86
86
-
RPi is already ready and waits for connection. How to use ssh and some
87
-
utilities (Linux, Mac) or programs (Windows) is supereasy - you will
87
+
RPi is already ready and waits for SSH connection. How to use SSH is supereasy - you will
88
88
find a tons of tutorials on the internet (keywords: how to use ssh). IP
89
89
address is the probably the one you assigned before. It will be
90
90
something like this: ``192.168.0.x``, ``10.0.0.14x`` or similar. Next
91
-
thing you need is username. It's just "root".
91
+
thing you need is username. It's just "root" (and password also).
92
92
93
93
If your RPi haven't got this address (ssh is not working), than there
94
94
are two options.
@@ -102,53 +102,49 @@ are two options.
102
102
**Example** You have this address assigned: ``192.168.0.201``. Then you
Now try if you are connected to the internet. Type ``ping 8.8.8.8``. If
154
150
you don't see ``ping: unknown host 8.8.8.8`` it's good! If you do, your
@@ -272,7 +268,7 @@ For reasons I will mention in future, we need to set RPi to connect with
272
268
the same and you can connect it. Right now is probably getting
273
269
automatically assigned IP address from router (it's called **dhcp**).
274
270
275
-
We will use ``systemd-network``.
271
+
We will use ``systemd-networkd``.
276
272
277
273
Type ``ip addr``. It should shows something like this:
278
274
@@ -293,7 +289,7 @@ Type ``ip addr``. It should shows something like this:
293
289
294
290
you are interested just in name **eth0**. If it is there, it is ok. In
295
291
future versions of system it can change to something other, for example
296
-
*eth0ps1*. Don't be afraid of it and just use that instead in next
292
+
*enp0s1*. Don't be afraid of it and just use that instead in next
297
293
chapters.
298
294
299
295
In this part you'll need to get address of your router. `How to obtain
@@ -324,7 +320,6 @@ in front of ``vim``, or you'll not be able to save it!) and paste this:
324
320
[Network]
325
321
Address=the.static.address.rpi/24
326
322
Gateway=your.router.ip.address
327
-
a
328
323
329
324
my example:
330
325
@@ -334,53 +329,14 @@ my example:
334
329
Name=eth0
335
330
336
331
[Network]
337
-
Address=192.168.0.201/24
332
+
Address=192.168.0.111/24
338
333
Gateway=192.168.0.1
339
334
340
-
now we need to try it - we don't to close us out. The connection is
341
-
right now ensuring by thing called ``netctl-ifplugd@eth0``. We want to
342
-
do this:
335
+
Now you need to remove old non-static default profile ``/etc/systemd/network/eth0.network``. Move it to your home folder just to be safe if something didn't work.
343
336
344
-
- Turn ``netctl`` off
345
-
- Turn ``networkd`` on
346
-
- Try if RPi is connected to the internet
347
-
- If yes, than do nothing - we can connect now by ssh
348
-
- If not, turn off ``networkd`` and turn on working ``netctl``
337
+
Try to restart RPi and try to SSH again. If you just can't connect, try to find out if RPi hadn't connected at all or it just doesn't use IP specified IP address (try to ssh to old IP, look into your router DHCP table, nmap...). If you want to get it back, just turn off RPi (plug off the power cable), take out SD card, plug in to your PC, move ``eth0.network`` from home directory to ``/etc/systemd/network/``, turn RPi back and try it again.
349
338
350
-
why so complicated? Because when you are changing network, it will
351
-
disconnect - and of course, we will disconnected also from SSH. And it
352
-
discouraged to use more network managers at once, because they'd
353
-
interferate and you don't want that.
354
-
355
-
This script will do what we want:
356
-
357
-
::
358
-
359
-
#!/usr/bin/bash
360
-
systemctl stop netctl-ifplugd@eth0
361
-
systemctl restart systemd-networkd
362
-
363
-
sleep 10
364
-
systemctl status systemd-networkd >> log.txt
365
-
ping -c 1 google.com
366
-
if [[ `echo $?` != 0 ]]
367
-
then
368
-
systemctl stop systemd-networkd
369
-
systemctl start netctl-ifplugd@eth0
370
-
fi
371
-
372
-
to run this script you need to login as root. You can do it by typing
373
-
this: ``sudo -i``. This will log you as a root. Now type
374
-
``vim script.sh`` and insert script there. Save and close (in vim using
375
-
``:x``). Now just type ``chmod +x script.sh``. It will make the script
376
-
executable. Finally this: ``./script.sh``.
377
-
378
-
The connection will close now. Wait 30 seconds. If everything worked
379
-
properly, you should be able to connect to RPi again by using same ssh
380
-
command as previous. In that case find out it works -> does
381
-
systemd-networkd care about connection and netctl is stopped?
382
-
383
-
To find it out, type: ``systemctl status systemd-networkd``. Does it
339
+
If you successfuly connected, check how is ``systemd-networkd`` doing. To find out, type: ``systemctl status systemd-networkd``. Does it
384
340
shows "active (running)" and something like ``gained carrier``?
385
341
386
342
::
@@ -397,20 +353,6 @@ shows "active (running)" and something like ``gained carrier``?
397
353
Jun 17 17:52:01 smecpi systemd-networkd[213]: eth0: lost carrier
398
354
Jun 17 17:52:02 smecpi systemd-networkd[213]: eth0: gained carrier
399
355
400
-
If yes, great! We can get rid off netctl by uninstalling it by
401
-
``pacman -Rnsc netctl`` and enable ``networkd`` to start at boot by
402
-
``systemctl enable systemd-networkd``.
403
-
404
-
If not, ``netctl`` should be started again and save the day. Find it out
405
-
by ``systemctl status netctl-ifplugd@eth0``. It should be active,
406
-
otherwise there is some magic power which care about your connection.
407
-
Try to find out why ``networkd`` didn't workd and repair it (probably
408
-
bad IP address...). There should be some info in file ``log.txt``.
409
-
410
-
If you can't connect, don't panic. Just turn off RPi (take out power
411
-
suppy) and turn it on. It should reconnect normally with
412
-
``netctl-ifplugd``. Try to find out why it is not working and try it
413
-
again.
414
356
415
357
Timesynchronization
416
358
-------------------
@@ -419,9 +361,8 @@ You've maybe noticed that time is quite weird on your RPi. It is beacuse
419
361
it does not have real hardware clock. Every time RPi is waken up, it
420
362
thinks that is June 1970. You don't have to care about it, but after
421
363
boot it would be fine that time is correctly set. You can do it by using
422
-
really great part of ``systemd``. Go ahead and enable service, which
423
-
takes care about that: ``systemctl enable systemd-timesyncd``. Thats
424
-
all. It will start after next reboot. If you want it to start now, just run ``systemctl start systemd-timesyncd``.
364
+
really great part of ``systemd``. Go ahead and check service that
365
+
takes care about that: ``systemctl status systemd-timesyncd``.
425
366
426
367
Configuring SSH
427
368
-------------------
@@ -455,9 +396,9 @@ Since now, only ``ssh bob@ipadress`` is not enough. You will have to add
455
396
port which should be used (in default is assumed port 22).
The next thing we are going to do is set up ``sshguard``. More about it
399
+
If you want to be really safe, the next thing you want to do is set up ``sshguard``. More about it
459
400
`here <https://wiki.Arch Linux.org/index.php/Sshguard>`__. You don't need
460
-
more :) . Just remember to use your port (in my case 1234) for settings.
401
+
more :) . Just remember to use your port (in my case 1234) for settings. Personally I stopped to use it, since just changing port what SSH use was enough to reduce uninvited connections.
461
402
462
403
It is anoying still typing same username and password when we want to
463
404
connect to RPi. And now, we have to add "-p 1234" also. We will make it
@@ -543,7 +484,7 @@ Other tweaks of /boot/config.txt
543
484
544
485
Since you don't need any of gpu memory - which cares about shiny things
545
486
like windows etc., you can disable it in favor of the rest of memory
546
-
which we use.
487
+
which we use. Don't do this if you want to use monitor.
547
488
548
489
::
549
490
@@ -737,8 +678,8 @@ protected etc.
737
678
System analyzing and cleaning
738
679
-----------------------------
739
680
740
-
Use your friend ``systemd-analyze``. It will show you which units are
741
-
loading long time. Also ``systemctl status`` is great for finding failed
681
+
Use your friend ``systemd-analyze``. It will show you which units
682
+
load really long time. Also ``systemctl status`` is great for finding failed
742
683
units.
743
684
744
685
Disable things that you dont need
@@ -747,19 +688,15 @@ Disable things that you dont need
747
688
I guess you don't use ipv6 (if you don't know what it is, you don't need
748
689
it :D). ``systemctl disable ip6tables``. In case you use sshguard, you
749
690
need also edit file ``/cat /usr/lib/systemd/system/sshguard.service``
Copy file name to clipboardExpand all lines: docs/source/ndg.rst
+67
Original file line number
Diff line number
Diff line change
@@ -387,6 +387,73 @@ After every change in configuration of nginx you need to restart it by running `
387
387
388
388
To see what processes are spawned you can use your task manager like ``htop`` or ``ps``.
389
389
390
+
391
+
Integration with GitHub
392
+
=======================
393
+
394
+
For starter it's necessary to say, that GitHub...
395
+
396
+
...is awesome! If you don't needed and you went through whole process above, you can probably save a lot of headaches just by using GitHub. You don't need any special knowledge for start, but you will need to learn them on the fly while reading this tutorial (there is really a lot about git out there, google is your friend).
397
+
398
+
The variant I propose here is very easy, scalable and fast. Probably the most easy and effective I've found.
399
+
400
+
Why to use it
401
+
--------------
402
+
403
+
I was so happy when I deployd my first django project. But few weeks later I've found that it's just not feeling right to make changes on live version of the website (sometimes refered as *production*). So I started to use GitHub and found a solution.
404
+
405
+
Here I will cover this:
406
+
For every your website you end up with one directory including three subdirectories.
407
+
408
+
1. First called **production** - it's the one which is live on the internet - the one what ``nginx`` refers.
409
+
2. Second called **mydomain.git** - this one is necessary for our github configuration. You will barely change there anything
410
+
3. Last one - **work_dir** - the one where all changes are being made and is connected to GitHub
411
+
412
+
413
+
Workflow
414
+
------------
415
+
416
+
Your work will look like this:
417
+
418
+
1. Your work_dir contains master branch. This branch can be pushed to production (to go live) anywhen! So when you want to make change to your website, you need create new branch (correctly named based on the change you are doing - e.g. *hotfix_plugin*, *typo_css*...) and when you finish and test this branch, you merge it to master.
419
+
2. You push master to your GitHub repository
420
+
3. You push master to your production folder on your computer
421
+
422
+
Set it all up
423
+
-------------
424
+
425
+
So how to do it? I suppose you have one working directory as we created in previous chapters.
426
+
427
+
Now go to the place where you websites are stored. Mine is in ``/var/www`` and create this structure::
428
+
429
+
mydomain
430
+
├── mydomain.git
431
+
├── production
432
+
└── work_dir
433
+
434
+
Go to ``/var/www/mydomain.git`` and type this::
435
+
436
+
git init --bare
437
+
438
+
this will create just git repository with some special folders. You don't need to know anything about it. All you need to do is to create this file ``/var/www/mydomain/mydomain.git/hooks/post-receive`` and add this::
and make the script runable ``chmod +x /var/www/mydomain/mydomain.git/hooks/post-receive``
444
+
445
+
Go to work_dir and paste there you current *production* code (the one from previous chapters). Now you need to make a GitHub repository from that. The best guide is this one: `How to add existing folder to GitHub <https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/>`_. (Maybe you'll need to `generate SSH key <https://help.github.com/articles/generating-ssh-keys/>`_). Is it working? Great.
446
+
447
+
Note: It's very good to make git repositories as small as possible, so don't add to repository files which are not necessary or you backup them somewhere else. But virtualenv is a good thing to add there to IMHO.
448
+
449
+
Now just add another remote, which will point to our created git repository. Every time we'll want to go live with master, we'll push changes to this git repository and it will take care to transfer our files to production. So in work_dir type::
450
+
451
+
git remote add production file::///var/www/mydomain/mydomain.git``
452
+
453
+
and that's all. When you now want to push changes to production, type ``git push production master``. Congratulations!
454
+
390
455
Finalization
391
456
============
392
457
That's all! I hope this guide helped you and you has successfully start up your websites! :)
0 commit comments