Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Alejandro Duarte
Alejandro Duarte

Posted on • Originally published atdzone.com

     

Your Old Laptop Is Your New Database Server

A couple of weeks ago I almost accidentally found in my apartment an old laptop that was only gathering dust: a Lenovo Thinkpad T440s that I bought in 2014.

The specs:

  • Intel® Core™ i7
  • 8 GB DDR3L-SDRAM
  • 256 GB SSD

Alejandro's old laptop

It looked like a good candidate for an always-available server; a machine that I could connect to at any time and install any kind of server software that I could need when developing apps. In times of Docker containers, configuring a machine to run server software is extremely easy. In this article, I’ll show you how to take advantage of that old laptop by installingUbuntu Server,Docker, and aMariaDB database with all the configurations needed to have it always available, always on.

Wait, but Why?

Is it worth having an old machine running something like a database server? The answer as always is: it depends. More specifically, it depends on the usage you intend to give to it. There are obvious things for which you cannot repurpose an old laptop. For example, if you want to use it as a storage device for large files or run big data applications or experiments, you might want to usecloud storage, acloud database, or get aproper device that fits your requirements.

But in general, I think repurposing an old computer is worth it. Especially for things such as experiments or development/test environments, modest hardware is often more than enough. Moreover, you already have the machine! So why not take advantage of it?

Before You Start

Before you start, make sure that you have a backup of any important files that you want to keep. Look for documents, photos, videos, all that kind of stuff. Spend an hour or so just looking for valuable content in the hard drive. Better to be safe than sorry! Use an external drive or a cloud provider like Google Drive or Dropbox to move the files. Or if they are already configured, move the files from the old laptop to a newer one using your local network.

Depending on the usage that you plan to give the laptop, you might want to encrypt its content or safely erase sensitive data using software likeFile Shredder,Eraser, orCCleaner.

Installing a Server Operating System

Pick an operating system that fits your needs. I recommend a headless operating system since you don’t need a fancy GUI that might waste computing resources.

You have many options. Here are just a few:

Make sure to use one that fits your requirements. For example, check that the software you want to install later in the server is compatible with the operating system.

I went forUbuntu Server, which in my opinion is probably the easiest to install and use. I won’t go through the details on how to install it. You can find plenty ofonline resources that explain how to do this in detail. In short, you’ll need a USB flash drive, download the Ubuntu Server ISO image, and use a program likeEtcher orRufus to create a bootable USB drive. You then connect this USB drive to the laptop and boot from it. On my Thinkpad, I had to press theF11 key when the laptop was starting to enter the boot menu and select the USB drive. From there, is as easy as following the steps.

Also, make sure to install an SSH server (Ubuntu Server includes this by default).

Setting a Static IP Address

When configuring the network connection, set a static IP so you can connect to the server from other machines (for example, your software development machine). In Ubuntu Server, you can do this after the installation process by modifying the/etc/netplan/00-installer-config-wifi.yaml file as follows:

network:  version: 2  wifis:    wlp3s0:      access-points:        YOUR_WIFI_CONNECTION_NAME:          password: YOUR_WIFI_PASSWORD      dhcp4: false      addresses: [192.168.1.200/24]      routes:        - to: default          via: 192.168.1.1
Enter fullscreen modeExit fullscreen mode

Use your Wi-fi connection name, password, and gateway. In the example above, I assigned the static IP address 192.168.1.200. You can reload the configuration using:

sudo netplan apply
Enter fullscreen modeExit fullscreen mode

Disabling Sleeping When the Lid Is Closed

You probably want your server to keep running even when the lid is closed. To disable Ubuntu Server to sleep or go to suspended mode edit the/etc/systemd/logind.conf as follows.

Make sure the following lines are not commented out and that their values are as indicated:

HandleLidSwitch=lockLidSwitchIgnoreInhibited=no
Enter fullscreen modeExit fullscreen mode

Done! Close the lid and place your server wherever you want in your house. For mine, I just placed it in a corner of my office:

Alejandro's Converted Laptop

Connecting to the Server Through SSH

Now you can move to your development machine andSSH to the server using something like:

ssh alejandro@192.168.1.200
Enter fullscreen modeExit fullscreen mode

Of course, specify the user you created when you instilled Ubuntu Server instead of my name.

Even though you can use the IP address to connect to the server, you can configure a hostname in your development machine that maps to the server’s IP address. Just a add an entry in the/etc/hosts file on Linux-like machines orc:\Windows\System32\drivers\etc\hosts on Windows:

192.168.1.200 thinkpad.local
Enter fullscreen modeExit fullscreen mode

Specify the IP address of your server and use any hostname you want. It’s a good practice to append.local at the end to remember that the hostname is local to your network and that it’s not visible from the outside world. On macOS, you’ll have to add the IPv6 address as well if you want to avoid long DNS lookups that slow down the connection process. For example:

fe80::2ab2:bdff:fea2:17dc thinkpad.local
Enter fullscreen modeExit fullscreen mode

Now you can connect to the server using something like:

ssh alejandro@thinkpad.local
Enter fullscreen modeExit fullscreen mode

Notice that if you want to use the hostname to connect to the server from additional machines, you’ll have to configure this in all of them.

Installing Docker

Docker is a virtualization tool that allows you to create isolated environments for your applications. Unlike virtual machines (hypervisors), containers run on top of the operating system without virtualizing the hardware.

If you prefer to have virtual machines instead of containers, a good option isVagrant. Vagrant allows you to automate the creation and provisioning of virtual machines viaVirtualBox or other hypervisors (called providers in Vagrant terminology). I think having virtual machines running on your old laptop is overkill. Running containers provides good isolation, and from a developer’s perspective, they look as if they were virtual machines. For that reason, I suggest using Docker instead.

You could also install any server software (like a database) onbare metal, directly on top of Ubuntu Server; however, using containers gives you the flexibility to experiment with different options without having to uninstall and reinstall the software. You simply run the containers that you want to use and stop or delete them without messing with your base operating system. Moreover, there are many ready-to-use Docker images (an image is like a template to create containers) for all kinds of interesting applications. This simplifies the process of installing databases, web servers, and other tools.

To install Docker, connect to your new server using SSH as described above and run the following command:

sudo apt-get install docker.io
Enter fullscreen modeExit fullscreen mode

Confirm that theDocker daemon is running:

sudo systemctl status docker
Enter fullscreen modeExit fullscreen mode

You should seeactive (running) displayed underActive.

Installing a Database Server

If you Google the name of a database plus "docker image,” you’ll find what you need to install that database using Docker. In this article, I’ll show how to install MariaDB Community Server, an advanced open-source SQL database server. Note that if you have a MariaDB subscription, you can installMariaDB Enterprise Server, an enhanced, hardened, and secured build of the MariaDB Community Server.

Download a MariaDB Community Server image and run it using Docker:

sudo docker run --detach --name mariadb --restart unless-stopped --env MARIADB_ROOT_PASSWORD='password' --publish '3306:3306/tcp' --expose '3306' mariadb:latest
Enter fullscreen modeExit fullscreen mode

This runs the MariaDB server in a container with the namemariadb. The container starts automatically if you restart the machine unless you manually stop the container as follows:

docker container stop mariadb
Enter fullscreen modeExit fullscreen mode

Confirm that the container is running by checking that its status isUp:

docker container ls
Enter fullscreen modeExit fullscreen mode

Copy the IPv4 address of the container from the output of:

docker network inspect bridge
Enter fullscreen modeExit fullscreen mode

Use that IP address to connect to the MariaDB server from the server (where Docker is running). For example:

mariadb -h 172.17.0.2 -u root -p
Enter fullscreen modeExit fullscreen mode

Now end the SSH session to disconnect from the server:

exit
Enter fullscreen modeExit fullscreen mode

From your development machine, connect to the MariaDB database using the hostname (or IP address if you didn’t configure a hostname). For example:

mariadb -h thinkpad.local -u root -p
Enter fullscreen modeExit fullscreen mode

Try running a SQL query:

Congratulations! Your old laptop is now your new database server.

Securing the Database Server

You might want to set a strong password for theroot user (interesting fact: MariaDB Enterprise Serverwon’t even let you use a weak password):

SET PASSWORD FOR 'root'@'%' = PASSWORD('Password123!');
Enter fullscreen modeExit fullscreen mode

Maybe you want to create a new “almost root” user as well:

CREATE USER 'user'@'%' IDENTIFIED BY 'Password123!';GRANT ALL PRIVILEGES ON *.* TO 'user'@'%';
Enter fullscreen modeExit fullscreen mode

And maybe you want to disable remote access to the database to theroot user, in which case later you’ll have to SSH to the server first if you want to connect to the database asroot. Here’s how to disable remote access toroot:

DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
Enter fullscreen modeExit fullscreen mode

What’s Next?

There are many other things you can install on your new server.Continuous Integration servers,web servers,email servers, etc. TheDocker Hub is a huge directory of images that you can safely try in isolated Docker containers. You can always run containers and remove them when you are done with your experiments. For example, you can remove the MariaDB container as follows:

docker container stop mariadbdocker rm mariadb
Enter fullscreen modeExit fullscreen mode

Then tryMariaDB with ColumnStore next. ColumnStore is a storage engine for MariaDB databases thatimproves the performance of ad-hoc analytical queries without having to maintain database indexes. You can install MariaDB with ColumnStorevia Docker:

sudo docker run --detach --name mariadb-columnstore --restart unless-stopped --env MARIADB_ROOT_PASSWORD='password' --publish '3306:3306/tcp' --expose '3306' mariadb/columnstore:latest
Enter fullscreen modeExit fullscreen mode

Now you can create tables that use the ColumnStore engine:

CREATE TABLE some_table(    ... column definitions here ...) ENGINE=ColumnStore;
Enter fullscreen modeExit fullscreen mode

Enjoy your new database server!

Top comments(12)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
hardikjogadia profile image
hardikjogadia
  • Joined

I have only 1 doubt. How can somebody forgot such a good configuration laptop? I m using my laptop from 2013, that is having core i3, 512 hdd and 4gb DDR3. But still I don't forget.🤔

CollapseExpand
 
alejandro_du profile image
Alejandro Duarte
Software Engineer · Published author · Developer Relations Engineer at MariaDB
  • Location
    Finland
  • Education
    National University of Colombia
  • Work
    Developer Relations Engineer at MariaDB
  • Joined

I happen to have a much newer and powerful laptop. Also, it had a keyboard layout I don’t use anymore. Plus the battery was in really bad shape. I get your point, though, and of course you can use a more modest laptop. I even run MariaDB on Raspberry Pi’s sometimes.

CollapseExpand
 
fyodorio profile image
Fyodor
Why'd you (software engineers) have to go and make things (software development) so complicated...
  • Location
    Backwoods
  • Education
    MSc, Royal Holloway University of London
  • Work
    Product Engineer
  • Joined

Agreed, FWIW this machine is too good for a utility server

for things such as experiments or development/test environments

CollapseExpand
 
tohasull profile image
Tom Sullivan
retired english teacher, I run a Minecraft server for grandkids and several opensim regions.
  • Education
    U of Michigan, U of Iowa, Wichita State
  • Work
    no thanks
  • Joined

Great article. I saw lots of tips I want to explore.

I use an old Mac Mini to host a MInecraft serverand to run an opensim Region on OSGrid. It uses Ubuntu 20.04. Ubuntu server would be a better choice.

A lot of old machines dropped out of service as Windows requirements kept going up and up. They still have a lot to offer and linux with its modest requirements gives them new life.

CollapseExpand
 
alejandro_du profile image
Alejandro Duarte
Software Engineer · Published author · Developer Relations Engineer at MariaDB
  • Location
    Finland
  • Education
    National University of Colombia
  • Work
    Developer Relations Engineer at MariaDB
  • Joined

Good to hear! One more tip:

Installavahi-daemon to make the computer visible by its hostname without having to configure a static IP address if you prefer. This also makes the hostname visible to all other devices in the network without having to add an entry to each/etc/hosts file. Simply run the following in the server:

sudo apt-get install avahi-daemon

CollapseExpand
 
onedamianocoder profile image
onedamianocoder
  • Joined

that laptop appear to me brand new XDD

CollapseExpand
 
alejandro_du profile image
Alejandro Duarte
Software Engineer · Published author · Developer Relations Engineer at MariaDB
  • Location
    Finland
  • Education
    National University of Colombia
  • Work
    Developer Relations Engineer at MariaDB
  • Joined

I took really good care of it, but it's almost 10 years old. It's still a good machine I think.

CollapseExpand
 
andrewbaisden profile image
Andrew Baisden
Software Developer | Content Creator | AI, Tech, Programming
  • Location
    London, UK
  • Education
    Bachelor Degree Computer Science
  • Work
    Software Developer
  • Joined

Nice tutorial I would like to give this a go.

CollapseExpand
 
alejandro_du profile image
Alejandro Duarte
Software Engineer · Published author · Developer Relations Engineer at MariaDB
  • Location
    Finland
  • Education
    National University of Colombia
  • Work
    Developer Relations Engineer at MariaDB
  • Joined

Go for it!

CollapseExpand
 
cednore profile image
cednore
If you don't like a person, it's because they remind you of something you don't like about yourself.

Always good to find something on dust but yet useful!

CollapseExpand
 
alejandro_du profile image
Alejandro Duarte
Software Engineer · Published author · Developer Relations Engineer at MariaDB
  • Location
    Finland
  • Education
    National University of Colombia
  • Work
    Developer Relations Engineer at MariaDB
  • Joined

Right? Why didn't I do this before?-kind of feeling.

CollapseExpand
 
samuelrivaldo profile image
Samuelrivaldo
Student in web development and Programmation
  • Work
    Student
  • Joined

Thanks 🙏

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Engineer · Published author · Developer Relations Engineer at MariaDB
  • Location
    Finland
  • Education
    National University of Colombia
  • Work
    Developer Relations Engineer at MariaDB
  • Joined

More fromAlejandro Duarte

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp