Chapter 2. Server Management with Pi
In the first half of this project, we will move from a desktop-based console to a text-based one that gives more power to the user and lets you perform more advanced tasks compared to the desktop. We will access the Pi's Linux console from an Android device and control it remotely. In the second half, we will send and receive files between the Pi and Android through FTP. We will even combine the two parts by managing our newly installed FTP server remotely using the text-based console. In this chapter, we will even install database and web servers on to the Pi to show how to manage them later on. To make it even more fun, we will implement a simple but useful mini project that makes use of both web and database servers. The following topics will be covered:
Remote console to the Pi from Android
Exchanging files between the Pi and Android
A simple database and web server implementation
Simple management of servers
Remote console to the Pi from Android
The administrators of Linux and Unix computers have been using text-based command-line interfaces called shell for many years to manage and administer their servers. As the Pi's OS, Raspbian, is a Linux variant, the most natural way to access and issue commands or check the status of running programs, services, and different servers on the Pi is again by issuing commands on this text-based shell. There are different shell implementations but the one that is used on Raspbian by default is bash. The most well-known way of accessing shell remotely on a Linux server is through the Secure Shell protocol known, in general, as SSH.
Note
Secure Shell (SSH) is an encrypted network protocol used to send shell commands to a remote machine in a secure way. SSH does two things for you. It enables, through different tools, such as the ones we will present to you in a moment, you to send commands to the remote machine and it does this using a secure channel established...
Exchanging files between the Pi and Android
In the second part of this chapter, we will use the Pi as an FTP server to share files between our Android devices or send files to the Pi to view them on a larger screen that you connect to the Pi HDMI port. The FTP server we will use is vsftpd
. It is a lightweight FTP server used in many small projects. To install it on our Pi, we use the following command:
The preceding command will even start the FTP service.
However, we should make some changes in the configuration of the FTP server to use it effectively. For this purpose, we need to edit the FTP server configuration file using this command:
Find the two lines containing #local_enable=YES
and #write_enable=YES
and remove the #
comment sign at the beginning of these lines before you save and exit. These changes will enable the user pi
to login and be able to send files to the Pi. To restart the FTP server, issue this command:
A simple database and web server implementation
Next, we'll take our project one step further and install both a database and web server, which we can administer later on using ConnectBot. We will even make it more fun by implementing a real project that makes use of these servers. The best candidate for this purpose is a sensor measurement scenario. We will connect a temperature/humidity sensor to our Pi and save the measurements into a database that we will install on the Pi, which a web server will make available to clients. We can later on manage these servers remotely, which is the main objective in this chapter.
For the purpose of this project, we will use a sensor, DHT11, which measures both temperature and humidity, but for the sake of easier connections, we will use an off-the-shelf module called Keyes DHT11 or DHT11 for short, which contains these sensors.
Tip
There is even an improved version of DHT11, which is DHT22. It costs a little bit more but has more accurate...
Simple management of servers
The following command simply checks the status of the FTP server:
This command restarts the FTP server if there's any problem with it:
The service
utility that we have used lets you restart the database and web server using these two commands:
Use the following command to check the status of the MySQL server:
If you believe that the database has grown too much in size, you can start the MySQL console and run a SQL query to see the database size:
You can even delete records that are older than three days using the following query:
Or, as an alternative, you can check...
This chapter introduced you to the management of Raspberry Pi as a server and how to issue commands to it from Android. We installed an FTP server on the Pi and shared files between Android clients. To show an example of database and web servers, we implemented a useful project and learned to manage these servers remotely as well.
The next chapter will introduce you to the Pi camera and help you implement a surveillance solution.