How Do You Find the Number of Processors or the Amount of RAM on a Linux Server?

Problem scenario
You want to know the number of processors your Linux server has.  What do you do?

Solution #1
Run this command:  grep -c ^processor /proc/cpuinfo

Solution #2
Run this command: nproc


Problem scenario
You want to know how much memory your Linux server has.  How do you find the amount of RAM (in gigabytes) on a Linux server?

Solution
Run this command:  free -g | grep Mem | awk '{print $2}'

For megabytes, run this command:  free -m | grep Mem | awk '{print $2}'

How Do You Use Python Eve as a RESTful Endpoint on an Ubuntu Server?

Problem scenario
You want to use Python Eve to test it out.  You also want to create a RESTful endpoint on an Ubuntu Linux server.  How do you do this?

Solution
1.  Install Eve on the Ubuntu server.  Here is one way:

sudo apt-get -y update
sudo apt-get -y install python python-pip
sudo pip install eve

An alternative way to install it is given here.

2.  Run these five commands:

python
contint = {'MONGO_HOST': 'localhost', 'MONGO_PORT': 27017, 'MONGO_DBNAME': 'the_db_name', 'DOMAIN': {'contacts': {}}}
from eve import Eve
app = Eve(settings=contint)
app.run()

3.  From another terminal (e.g., open another command prompt from your desktop or create a duplicate Putty session to the server), run this command:

curl http://localhost:5000

Look at the output on the first terminal.  You should see an HTTP status code of 200 and other information.

How Do You Install python-snappy on an Ubuntu/Debian Linux Server?

Problem scenario
You are trying to install python-snappy on Ubuntu (or a Debian distribution of) Linux.  You go here and find no obvious dependencies or prerequisites:
https://pypi.python.org/pypi/python-snappy

But when you try to install it, you run "python setup.py build" and get an error like this:

"/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)
running build
running build_py
package init file '__init__.py' not found (or not a regular file)
package init file '__init__.py' not found (or not a regular file)
running build_ext
building '_snappy' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time - D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c  snappymodule.cc -o build/temp.linux-x86_64-2.7/snappymodule.o
x86_64-linux-gnu-gcc: error trying to exec 'cc1plus': execvp: No such file or directory
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1"

or an error like this:

"x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time - D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c  snappymodule.cc -o build/temp.linux-x86_64-2.7/snappymodule.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
snappymodule.cc:28:20: fatal error: Python.h: No such file or directory
compilation terminated."

What should you do to install snappy for Python?

Solution
Run these four commands:

sudo apt-get -y install python-pip

sudo su -

pip install snappy

exit

#If you are not allowed to leave pip installed, run this command: "sudo apt-get -y remove python-pip" with no quotes

You Cannot Connect To One IP-Enabled Device to Your WiFi Router Wirelessly. What Do You Do?

Problem scenario
You can connect the device with a network cable (in a wired fashion) to your network including the WiFi router's physical ports.  The wired connection works.  You can connect other devices to the WiFi router wirelessly.  You can even connect  the IP-enabled device with the problem to other wireless routers.  What is wrong?

Possible Solution #1
See if the incompatibility comes from the WiFi router having an access control list enabled.  If it is enabled, it may not allow your IP-enabled device to connect.  The devices that can connect wirelessly may be on the ACL (access control list).  Once (and if) you disable the ACL in the WiFi, you may need to restart the IP-enabled device (e.g., reboot the laptop).  If your IP-enabled device's wireless adapter's MAC address changed, that may cause it to be blocked by the ACL.  Make sure the ACL is not stopping your IP-enabled device.

Possible Solution #2
If your WiFi does not have an access control list that is enabled, the WiFi adapter on the IP-enabled device may be defective.

How Do You Check if snappy Is Installed?

Problem scenario
You are not sure if snappy (the Python development tool) is installed.  You try these two commands:

python
>>> import snappy

You see this:

"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "snappy.py", line 50, in <module>
    from snappy_cffi import UncompressError, compress, decompress, \
  File "snappy_cffi.py", line 3, in <module>
    from cffi import FFI
ImportError: No module named cffi
"

The above means snappy is not installed or if you recently installed it, the environment variables are not updated.  

Potential root cause
You installed it but the environment variables have not been updated and refreshed. 

Solution
Log off as the current user and log back in.

Then use option 1 if you have pip installed:

pip list | grep -i snappy

Then use option 2 if you do not have pip installed:

Run these two commands:

python
>>> import snappy #where ">>>" is not something that you type in

# If you see no errors in the above, then snappy has been installed

What Do You Do When You Get “Permission Denied” in FTP?

Problem scenario
You are trying to transfer a file named foobar.txt via FTP.  But you get this error:

local: foobar.txt remote: foobar.txt
local: foobar.txt: Permission denied

What do you do with this "Permission denied" error?

Solution
The above error would not happen if the problem was on the remote server.  (You would get "550 Failed to open file" if the problem was a lack of read permissions on the source of the FTP file transfer.)

Make sure that the destination of the FTP file transfer (that is the local directory) is one where your user has access to write to.  You must have write permissions in the local directory.  If the server was recently set up or changed, the permissions in the local directory may prevent the user from writing to it.  You may want to change to the /tmp directory to initiate the FTP session from there.

How Do You Remotely Connect with a GUI Interface into a Raspberry Pi 3 from a Windows Computer That Is on the Same Network?

Problem scenario
You want to connect to your Raspberry Pi 3 with a Windows machine (e.g., Windows 7 or Windows 10 laptop).  Both are on the same network.  You want more than the command line interface.  You want a desktop GUI connection beyond just a character prompt.  What do you do?

Solution
On the Raspberry Pi do these three steps:
1.  Change password for the pi user or create a new user.
2.  Find the IP address by using "ifconfig" with no quotes in a command terminal.  (Use "ip addr show" if you prefer.)
3.  Go to the Raspberry button in the upper left hand corner, go to Preferences -> Raspberry Pi Configuration.  For VNC choose "Enabled."

On the Windows workstation, do the following four steps:
4.  Download and install VNC Viewer.
5.  Open VNC Viewer.
6.  Type in the IP address of the Raspberry Pi and press enter.
7.  Enter the username and password and press enter.

How Do You SSH into a Raspberry Pi 3 from a Windows Computer That Is on the Same Network?

Problem scenario
You want to use Putty from a Windows 7 or Windows 10 workstation to connect to a Raspberry Pi 3 on the network. You want to connect via a command prompt (not with a GUI).  What do you do?

Solution
On the Raspberry Pi do these three steps:
1.  Change password for the pi user or create a new user.
2.  Find the IP address by using "ifconfig" with no quotes in a command terminal.  (You can use "ip addr show" if you prefer.)
3.  Go to the Raspberry button in the upper left hand corner, go to Preferences -> Raspberry Pi Configuration.  For SSH choose "Enabled."
4.  On the Windows machine, open Putty.  If you don't have it, you can download it from here.  From the Windows machine, follow the next three steps.
5.  Type in the IP address of the Raspberry Pi
6.  Click "open"
7.  Connect as normal

How Do You Troubleshoot the Error “No package foobar available”?

Problem scenario
You are running "sudo yum install foobar" but it is not working.   You are trying to install a package on a RHEL server, but it is not available from the configured repositories.  You notice that many packages you normally install are not available.  What should you do?

Solution
Run this command:
sudo yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

FFR
To find the number of packages available to you in the configured repository (or repositories), run this command:
sudo yum list available | nl | tail -n 1 | awk '{print $1}'

To learn more about yum commands, see this PDF that RedHat.com provides.

How Do You Set up HAProxy on a Linux Server?

Problem scenario
You have some web servers that you want a new HAProxy server to distribute traffic to.  You have an Ubuntu or Debian Linux server that you want HAProxy installed on.  You want HAProxy to be a load balancer. What do you do?

Solution
Prerequisites

You have at least two web servers set up and you know their IP addresses (either internal or external).  If you do not have these, you may want to see one of these four articles:

How Do You Install Apache Web Server on Ubuntu Linux?
How Do You install Apache Web Server with CentOS/RHEL/Fedora?
How Do You install Nginx on a Debian/Ubuntu Server?
How Do You install Nginx on a CentOS/RHEL/Fedora Server?

You have a third Linux server which will receive the HAProxy installation; this server can have as little as 1 GB of RAM and just one basic processor.  You may need a more powerful server if it will support considerable traffic, but for testing it will be fine.

Procedures
These steps are to be done on the server that will get the HAProxy installation.

1.  If you are using an Ubuntu or Debian server, run these commands:
sudo apt -y update
sudo apt-get -y install haproxy

If you are using a CentOS/RHEL/Fedora server, run these commands:
sudo yum -y update
sudo yum -y install haproxy

2.a.  Modify the main configuration file with this command:
sudo vi /etc/haproxy/haproxy.cfg

2.b.  Determine if you have a CentOS/RHEL/Fedora server (a RedHat derivative) or an Ubuntu/Debian server.  Follow the step 2.b.i or 2.b.ii for your distribution only (do not do both):

2.b.i  For CentOS/RHEL/Fedora, find the "frontend main" section.  Replace the "5000" with "80".  With an indentation to match the other stanzas underneath "frontend main" insert this stanza:
    option                      forwardfor

For the "backend app" section find the stanza with "app1". Replace the 127.0.0.1 with the internal or external IP address of one of the web servers.  Replace the 5001 value with "80".    

Find the stanza with "app2". Replace the 127.0.0.1 with the internal or external IP address of one of the web servers.  Replace the 5002 value with "80".  Skip to 3.

2.b.ii  For Ubuntu or Debian, do the following.  To have HAProxy distribute traffic to different web servers, insert these stanzas at the bottom of the above file (from "frontend firstbalance to "option httpchk"):

frontend firstbalance
        bind *:80
        option forwardfor
        default_backend webservers

backend webservers
        balance roundrobin
        server webserver1 x.x.x.x:80
        server webserver2 y.y.y.y:80
        option httpchk

2.c.  Replace x.x.x.x with the IP address (either internal or external) of the first web server.  Replace y.y.y.y with the IP address (either internal or external) of the second web server.  Save the changes.

3.  Verify you have no intermediate firewall, or AWS Security Group, or Azure NSG, or Google firewall rule, between the HAProxy server and the IP address it is trying to reach.  Port 80 must be open from the HAProxy server to the other servers.  Remember if you are reaching internal IP addresses, use the internal IP address of the HAProxy server.  If you are configuring HAProxy to use external IP addresses, use the external IP adress of the HAProxy server.  To find your external IP address, use this command (assuming you have access to the internet): curl icanhazip

To find your internal IP address use this command: ip addr show | grep inet

4.  Restart HAProxy.  If you have a Debian/Ubuntu server, use this command:
sudo /etc/init.d/haproxy restart

Otherwise use this command:
sudo service haproxy start