Some Basic MySQL Commands

Enter Mysql

mysql -u root -p

Create Database

create DATABASE testdb;

Select Database

use testdb;

Delete Database

drop DATABASE testdb;

Drop Table

drop table table_name;

Show Tables

show tables;

Show data in table

SELECT * FROM table_name;

Create Table

CREATE TABLE contacts_table (id INT, name VARCHAR(20), email VARCHAR(20));

Insert data into table

INSERT INTO contacts_table (id,name,email) VALUES(2,"John","John83@incredigeek.com");

List one row in table

SELECT * FROM table_name LIMIT 1;

Delete Row in Table

DELETE FROM table_name WHERE row_name=data_to_delete;

Delete all “users” from a WordPress database that do not contain admin in the username.

DELETE FROM `wp-users` WHERE user_login NOT LIKE "%admin%"

Add Auto Increment to Table

ALTER TABLE  `table_name` ADD  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

Create table with Date and Time timestamp

CREATE TABLE table_name (id INT, timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

Show MySQL Users

select * from mysql.users;

Create MySQL User

GRANT ALL ON mysqldb.* TO username@localhost IDENTIFIED BY 'password';

Delete MySQL user

DROP USER 'username'@'localhost';

Add Column to the end of MySQL Table

ALTER TABLE mysqltable ADD email VARCHAR(60);

Add Column to the begging of MySQL Table

ALTER TABLE mysqltable ADD email VARCHAR(60) FIRST;

Insert Column after Specific Column in MySQL Table

ALTER TABLE mysqltable ADD email VARCHAR(60) AFTER columnname;

Setup SNMP for Ubiquiti Radios

First lets install SNMP.

On Red Hat type systems such as Fedora and CentOS do the following

yum install -y net-snmp net-snmp-utils

If you are using a Debian based distro the you can use apt.

apt-get install snmp

You will need to make sure that SNMP is turned on in the radio under the Services tab.

Be sure to remember the SNMP Community string as that is needed in the next step.

Now try to connect to the device with the following command.

snmpwalk -v1 -c comunityname 192.168.1.20

You should receive something like the following.

...
IF-MIB::ifSpecific.5 = OID: SNMPv2-SMI::zeroDotZero
SNMPv2-MIB::snmpInPkts.0 = Counter32: 484
SNMPv2-MIB::snmpOutPkts.0 = Counter32: 471
SNMPv2-MIB::snmpInBadVersions.0 = Counter32: 0
SNMPv2-MIB::snmpInBadCommunityNames.0 = Counter32: 12
SNMPv2-MIB::snmpInBadCommunityUses.0 = Counter32: 0
...

If you received

Timeout: No Response from 192.168.1.20

Then either the SNMP Community name is wrong or the ip address is unreachable.

The following command will list all the interfaces on the device.

snmpwalk -v1 -c comunityname 192.168.1.20 ifDescr
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifDescr.3 = STRING: eth1
IF-MIB::ifDescr.4 = STRING: wifi0
IF-MIB::ifDescr.5 = STRING: ath0
IF-MIB::ifDescr.6 = STRING: br0

Notice the number at the end of the ifDescr, That number identifies the interface.  You will need that for the next command.

Now lets check the signal. Note that the last number of the OID(the OID is the last string of numbers) is the interface number of ath0.  Yours could be different depending on how you have the radio setup.

snmpwalk -v1 -c communityname 192.168.1.20 1.3.6.1.4.1.14988.1.1.1.1.1.4.5

Here is a short list of OID’s.  To use them just run the above command but replace the OID with the one you want.

RxRate of 5'th interface (ath0) of the device (bps): 1.3.6.1.4.1.14988.1.1.1.1.1.3.5
TxRate of 5'th interface (ath0) of the device (bps): 1.3.6.1.4.1.14988.1.1.1.1.1.2.5
Channel: 1.3.6.1.4.1.14988.1.1.1.1.1.7.5
Firmware Version: 1.2.840.10036.3.1.2.1.4
Hostname: 1.3.6.1.4.1.14988.1.1.1.1.1.5
AP MAC: 1.3.6.1.4.1.14988.1.1.1.1.1.6
Station MAC: 1.2.840.10036.1.1.1.1
Signal 1.3.6.1.4.1.41112.1.4.5.1.5.1 (OID seems to vary a little bit, from nanoBeam to nanoStation)

 

How to set a static ip address on CentOS, Fedora, or Red Hat Linux

Open up the following file with your favorite text editor. Change eth0 to the interface you need, like “wlan0” or “eth1”.

 vi /etc/sysconfig/network-scripts/ifcfg-eth0

The file should look something like the following.

DEVICE=eth0
HWADDR=0A:2G:F3:56:66:4B
TYPE=Ethernet
UUID=aeh9421c-6a62-712c-886d-347813g8d1dh
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp

To set the static IP address change “BOOTPROTO=dhcp” to “BOOTPROTO=static” and add the following to the end of the file. If you want/need the interface to come up when the computer boots up then be sure to change “ONBOOT=no” to “ONBOOT=yes”.

BROADCAST=192.168.1.255
DNS1=8.8.8.8
GATEWAY=192.168.1.1
IPADDR=192.168.1.110
NETMASK=255.255.255.0

Also, on some newer versions of CentOS you may need to add NM_DISABLED=no

So your file should now look like this.

DEVICE=eth0
HWADDR=0A:2G:F3:56:66:4B
TYPE=Ethernet
UUID=aeh9421c-6a62-712c-886d-347813g8d1dh
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BROADCAST=192.168.1.255
DNS1=8.8.8.8
GATEWAY=192.168.1.1
IPADDR=192.168.1.110
NETMASK=255.255.255.0

Save the file and restart networking.

service network restart

Finally, check you IP address with ifconfig.

root@localhost ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 0A:2G:F3:56:66:4B  
          inet addr:192.168.1.110  Bcast:192.168.1.255  Mask:255.255.255.0

How to Install Nagios 4.0.6 on CentOS 6.3

Install the prerequisite packages

yum install gd gd-devel httpd php gcc glibc glibc-common make perl

Create the Nagios user.

useradd -m nagios
passwd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Create a directory to download and build Nagios from

mkdir /root/nagios
cd /root/nagios

Download Nagios and the Nagios plugins

wget downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz
wget nagios-plugins.org/download/nagios-plugins-2.0.2.tar.gz 

Extract the Nagios zip

 tar xvzf nagios-4.0.6.tar.gz
cd nagios-4.0.6

Compile and make it

./configure
make all
make install-init
make install-commandmode
make install-config
make install-webconf

Create a password so you can login to the web interface

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enable Nagios on startup

 chkconfig nagios on

Start the service

service nagios start

Install the plugins.

cd ..
tar xvzf nagios-plugins-2.0.2.tar.gz
cd nagios-plugins-2.0.2
./configure
make
make install

Start apache and make sure it starts on boot.

service httpd start
chkconfig httpd on

 

How to Install CraftBukkit Minecraft Server on Raspberry Pi

First we need to Install Java.

sudo apt-get install openjdk-7-jre

Next lets create a CraftBukkit directory to store all the files.

mkdir ~/mc-bukkit
cd ~/mc-bukkit

And lets download CraftBukkit.

wget "http://dl.bukkit.org/downloads/craftbukkit/get/02389_1.6.4-R2.0/craftbukkit.jar" -O "craftbukkit.jar"

Now lets create a script that we can use to start the Server.

sudo vi /etc/init.d/mcstart.sh

Copy and paste the following text.

#! /bin/sh
# /etc/init.d/mcserver

### BEGIN INIT INFO
# Minecraft CraftBukkit Start script
### END INIT INFO

case "$1" in
  start)
    echo "Starting mcserver"
    MCDIR=$("/home/pi/craftbukkit")
    cd "$MCDIR"
    java -Xmx512M -jar craftbukkit.jar -o true &
;;
  stop)
    echo "Stopping mcserver"
    kill `pgrep mcserver`
    ;;
  *)
    echo "Usage: /etc/init.d/mcserver {start|stop}"
    exit 1
    ;;
esac
exit 0

Now lets make the file executable.

chmod +x mcstart.sh

And launch

sudo /etc/init.d/mcstart.sh

The first lunch will take a long time so be patient.

If you want to start CraftBukkit when your Pi boots up then run the following command.

sudo /etc/init.d/mcstart.sh start

Turn Your Raspberry Pi into a Wireless Hotspot

Goal:

The goal of this guide is to turn a Raspberry Pi into a wireless home/mobile router.

Equipment:

  1. Raspberry Pi with raspbian
  2. Wireless USB device.  The guide uses a Edimax Nano USB Wifi (EW-7811Un) adapter
  3. Ethernet cat5 cable to connect to the Internet

Lets get started.

Install the following packages.

sudo apt-get install hostapd dnsmasq iptables

Open up “/etc/network/interfaces” and add the following lines.  If there is a line for wlan0 you can comment it out with a “#”.

iface wlan0 inet static
address 192.168.42.17
netmask 255.255.255.0

Configure Hostapd

Edit the following file “/etc/default/hostapd” so it looks like this.

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Now edit the hostapd config file “/etc/hostapd/hostapd.conf” and configure the wireless access point.

interface=wlan0
driver=rtl871xdrv
bridge=br0
ssid=MC
channel=1
wmm_enabled=0
wpa=1
wpa_passphrase=min3cr@ft
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0 

 Configure the DHCP Server

For the DHCP server we just need to add the following lines to “/etc/dnsmasq.conf”

interface=wlan0
dhcp-range=192.168.42.20,192.168.42.152,255.255.255.0,12h
dhcp-option=3,192.168.42.17

Configure Iptables

Now we need to set it up so the pi can forward traffic from wlan0 to eth0.

Edit “/etc/sysctl.conf” and uncomment the following line

net.ipv4.ip_forward=1

then execute

sysctl -p

Next create an iptables “config” file.

sudo touch /etc/network/if-up.d/router.sh
sudo chmod +x /etc/network/if-up.d/router.sh
sudo su -c "echo '/etc/network/if-up.d/router.sh' >> /etc/rc.local"

Add the following line to the file.

sudo iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
sudo iptables --append FORWARD --in-interface wlan0 -j ACCEPT

If you are using the same wireless adapter that is used in this guide then you will need to execute the following commands to replace the hostapd binary.  You can find more info here.

wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip
unzip hostapd.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
sudo mv hostapd /usr/sbin/hostapd.edimax
sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd
sudo chown root.root /usr/sbin/hostapd
sudo chmod 755 /usr/sbin/hostapd

That should do it. Plug in the Ethernet cable and reboot  your pi and you should be good to go.

How to add a NFS ISO Repository to XenServer

This assumes you have a NFS Share setup up.  If you do not you can follow this link.

Open up XenCenter click on add storage device button on the top.

Select NFS iso and hit next.

Connect XenServer to NFS

Enter in the name you want to call your repository
Connect XenServer to NFS 2

Next we add the share location which in my case is 192.168.200.250:/nfs  and hit Finish.

Connect XenServer to NFS 3

If all went well you should have a new NFS ISO repository

Connect XenServer to NFS 5

Connect XenServer to NFS 6

 

How to Create a NFS Share Server on Slackware

  1. Create the NFS Share directory. You can change the name “/nfs” to wherever and whatever you want. Just be sure to remember the path and name
    mkdir /nfs
  2. Add the NFS Share to the /etc/exports file. Change the ip address to your NFS Servers ip address.
    echo "/nfs 192.168.200.250/24(rw,sync,no_subtree_check)" >> /etc/exports
  3. Next we chmod /etc/rc.d/rc.nfsd and rc.rpc so that they can be executed to start the service
    chmod 755 /etc/rc.d/rc.nfsd
    chmod 755 /etc/rc.d/rc.rpc
  4. Start rpc and nfsd
    /etc/rc.d/rc.nfsd start
    /etc/rc.d/rc.rpc start
    
  5. Export the Share
    exports -a
  6. Connect a Client and have fun

Create an Image of a SD Card

The following command works on both OS X and Linux.  It creates an image from the SD card called raspi.img which you can later use to clone to another SD Card or just keep as a backup.  It is exceptionally useful for backing up a Raspberry Pi.

Replace “mmcblk0” with your SD cards name.  Take a look at this post if you need help finding the name.

sudo dd if=/dev/mmcblk0 of=~/raspi.img

How to Change, Add, and Delete Users in Linux

Changing a users name:

sudo usermod -l new-username old-username

To change the users directory name do the following.

 sudo usermod -d /home/new-username

You might need to log in as root or another user to successfully execute the commands.

Adding a user:

sudo useradd -m newuser

The -m option create the new users home directory

Then to activate the user we need to setup a password.

sudo passwd newuser

Enter and reenter the password and your done.

If you need to add the user to a certain group(s) (sudo?) you can do that with usermod

sudo usermod -G sudo,othergroups newuser

 

Deleting a user:

sudo userdel -r username

The “-r” option deletes the users mail and home directory.  If you wanted to keep them then just discard that option.