Linux Server
From QwikITedia
CentOS CheatSheet
- CentOS is a perfect alternative to Redhat - it's basically Redhat without support and guarantee.
- CentOS v5.2 runs kernel version 2.6
How to access the CD rom on CentOS
- mount /dev/cdrom /mnt
- cd /mnt
How to unmount the CDRom
- umount /dev/cdrom
How to mount a USB drive if the system has two drives(sda and sdb)
- mount /dec/sdc1 /mnt
- cd /mnt
How to unmount the USB drive
- umount /dev/sdc1
Install the RPM Key
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-3
Reinstall SeaMonkey if you've installed the Server GUI
yum install seamonkey
Install GNU C / C++ compiler on CentOS Linux server
yum install gcc gcc-c++ autoconf automake
Update existing packages on the fresh CentOS install
yum -y update
Clean out the yum cache to re-capture disk spaced used during the update process
yum clean all
Install CPAN
# perl -MCPAN -e '$ENV{FTP_PASSIVE} = 1; install CPAN'
Establish Locate or Search Index
# updatedb
Gentoo Tricks
How to Create a User account on Gentoo Server
- To create a user account, we first enter their credentials, followed by its password. We use useradd and passwd for these tasks. In the next example, we create a user called "john".
# useradd -m -G users john # passwd john New password: (Enter john's password) Re-enter password: (Re-enter john's password)
How do I grant someone sudo access
- Same as on Redhat, ensure they are in the wheel group
vi /etc/group
- If not, add them
- If they still cannot sudo, check sudoers file cos Wheel is probably commented out - use visudo command though!
visudo
How to Correlate MAC address with NIC
- When you replace a server's motherboard you'll also have to rejigger the MAC to NIC config
- The first thing you'll notice when you do an "ifconfig -a" is that the old NIC for example eth0 has been recognized and re-labeled as eth2.. so you'll have to tell Gentoo all about that
- In Gentoo there are two places where this must happen
- /etc/conf.d/net .. change the eth0 to eth2
- /etc/init.d/net.eth0 .. rename this file as net.eth2 and ensure the symlink to net.lo works
- Now restart the networking service or the server.
Redhat Tricks
EXIT X Server
CTRL-ALT-F2
Exit X Server to install nvidia drivers
- Open a terminal, on CLI type 'init 3'
- After you install the nVidia drivers type 'init 5'
Log Whereabouts
- Logs are located in:
/var/log
- For the Grid, you'll need to pay particular attention to /var/log/ud.log
Grant SUDO to a normal user on REdhat
- Edit /etc/group and add user to the group wheel
- Run visudo and uncomment the group wheel...leave the percent, ensure you select with Password
- All this can be seen here: http://kbase.redhat.com/faq/docs/DOC-1528
How to change from Dynamic to Static IP
- Go to the /etc/sysconfig/network-scripts and open the ifcfg-eth0 file for editing
- Change
BOOTPROTO=DYNAMIC
- to
BOOTPROTO=STATIC
- add a new line
IPADDR=(type ip address here)
- Save and Close ifcfg-eth0.
- To flush IP address use the following command
/etc/init.d/network stop
- then
/etc/init.d/network start
- To check that the IP address has taken type
/sbin/ifconfig
How to change computer name
- Requires adjustments to two locations:
- /etc/sysconfig/network
- /etc/hosts
- Make a backup of each file first, for example
cp /etc/hosts /etc/old.hosts.safe
- Restart the system or the networking daemon
How do I update my BIOS on a Dell desktop/laptop
This does not apply to Dell Rack Servers
- Create an RPM BIOS image using BIOSDISK
- Download the appropriate Biosdisk rpm
- Install this
rpm -ivh biosdisk-0.75-2.noarch.rpm
- Get the correct *.exe BIOS file from Dells support site using the Dell Service Tag
- Make note of path to where you downloaded it
- Create an RPM from the Windows executable; for example
biosdisk mkpkg /home/resmonde/a11GX620.exe
- Verbose nature of this action will tell you where the rpm has been created and placed.
- Install the rpm
- Restart the system, BIOS screens will result, you shoudl eventually see Update Successful
Sudo on REDHAT
- To gain sudo perms you must be in the group wheel
- Then use the visudo command to edit the /etc/sudoers file
[root@qaserver root]# visudo
- Read this article to ensure you gain a full grasp on what you are doing.
- Once you've uncommented the wheel group in /etc/sudoers you sudo as follows:
[resmonde@qaserver resmonde]$ sudo bash
Users and Groups
- Adduser :
[root@qaserver home]# /usr/sbin/useradd -d /home/user-c -m user-c
- More here: Redhat Docs
Networking on RedHAT
Search for a string in an Apache Conf file
- There are a lot of these on each Grid server so save yourself some time and don't use locate, use:
fgrep -i 'ExecCGI' `find . -iname '*.conf' -print`
Ubuntu Tricks
Check to see if a package is installed or not
dpkg -l | grep <packagename>
Completely Remove a stubborn package that seems to persist
- For example:
aptitude purge r-base-core if that didn't work: aptitude install r-base-core && aptitude purge r-base-core
Check what version of a Package Is Installed on Ubuntu
dpkg -s <packagename>
How do I Access CD Rom ..cli
mount /dev/cdrom /media/cdrom or mount /dev/cdrom /cdrom cd /media/cdrom or cd /cdrom ls -alF
How do I Access USB memory Stick
- Assuming system has two SATA drives sda and sdb
mount /dev/sdc1 /mnt
How do I add or edit nameservers for DNS resolution
- Ensure all nameserver info is setup
#vi /etc/resolv.conf search mycompany.lan nameserver 12.x.x.x nameserver 12.x.x.x
How do I change my Ubuntu systems time zone?
- Great Ubuntu Time Mgmt article
How do I install an exact Package on Ubuntu
- You install a specific version of a package using the following sintax:
# apt-get install package=version
- For example, the line below will install version 2.2.4-1 of the nautilus package.:
# apt-get install nautilus=2.2.4-1
How long has my Ubuntu Server been up?
- Use uptime command to get a brief overview, then correlate with /var/www/log/syslog and/or /var/log/messages
# uptime
What ports is my Linux system listening on
# netstat -l
What ports sans UNIX sockets are open?
netstat -tna
What Processes are running
# ps -A
What ports are actively listening and what for
# netstat -tulnap
Who has recently been connected to my server?
- Use the last commad to view who has been connected to the server and when
# last -x
How to List the installed software on my Ubuntu Server for a future restore
- List installed software
# dpkg --get-selections
- Store list of installed software to a file called /backup/installed-software.log
# dpkg --get-selections > /backup/installed-software.log
- Restore installed software from backup list
# dpkg --set-selections < /backup/installed-software.log
- Now your list is imported use dselect to install the package
- Select 'i' to install the software.
How much RAM is in my Linux system?
- Foolproof across all flavors of Linux:
vi /proc/meminfo
How to Change the default Editor from nano to X on Ubuntu
- Access the editor config mode
root@myserver:~# sudo update-alternatives --config editor
- In the resultant screen select option you prefer #1 for Vi
There are 4 alternatives which provide `editor'.
Selection Alternative
-----------------------------------------------
1 /usr/bin/vim.tiny
2 /bin/ed
*+ 3 /bin/nano
4 /usr/bin/emacs22
- Resultant dialog will confirm your decision
Press enter to keep the default[*], or type selection number: 1 Using '/usr/bin/vim.tiny' to provide 'editor'.
How to Change the HOSTNAME of an Ubuntu System from CLI
- With sudo perms:
# sudo echo "NEW-Server-NAME" > /etc/hostname
- Now run the script to make it permanent
* sudo /etc/init.d/hostname.sh
- Log out of server and log back in.
- Hostname should now be whatever you wanted
How to learn Disc usage in general
- At command prompt, type:
df -h
How to learn Size of Current Directory
- Move into the dir and type:
du -h
- Specific example with alternate switch on DataDyve production - How large is the postgres DB dir on there?
cd /iscsi/ du -sk ./postgresql/
How to check the version of a package already installed
- Best way is to use aptitude:
aptitude show <package name>
- Example:
aptitude show php5
How to Change the TIMEZONE on an Ubuntu Server
- Use the inbuilt tzselect command(used to be tzconfig but they changed it, go figure), run it
- Hit 11
- Enter PST-8 to change timezone to PST from UTC
- edit your /home/username/.profile directory and add this:
TZ='PST-8'; export TZ
- Logoff as username and log back in or merely source your profile file
- Type
date
- Time an dtimezone should have changed.
- To change back just repeat the process to get back to where you want to be
How to RESET the TIMEZONE back to UTC on an Ubuntu Server
- Use the inbuilt tzselect command(used to be tzconfig but they changed it, go figure), run it
- Hit 11
- Enter :
TZ=GST-0
- edit your /home/username/.profile directory and add this:
TZ='GST-0'; export TZ
- Logoff as username and log back in or just source profile file
source ~/.profile
- Type
date
- Time an dtimezone should have changed.
- To change back just repeat the process to get back to where you want to be, it's all relative to GST if you use option 11.. so GST+X or GST-Y
- Think of GST as Greenwich Mean Time and you've got the concept.
Install R on Ubuntu Hardy Heron v 8.04.x Server
- Update sources.list to get latest build from a CRAN-R mirror
- So, edit /etc/apt/sources.list to include the following two changes:
# Get the latest Build of R deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu hardy/ deb http://us.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
- Tell server to update its source repositories list:
sudo apt-get update
- Install R
sudo apt-get install r-base sudo apt-get install r-base-dev
- During the install, if there was an older copy of R on the server it might get overwritten .. you'll atleast be asked about this.
Where is the Network Card?
- You've had a new motherboard put inside the server and you can no longer start Networking
- Your old config was for eth0 and eth1
- when you try to start networking by running:
# /etc/init.s/networking start
- You are greeted with errors such as:
SIOCSIFADDR: No such device eth0: ERROR while getting interface flags: No such device SIOCSIFADDR: No such device SIOCSIFADDR: No such device eth0: ERROR while getting interface flags: No such device eth0: ERROR while getting interface flags: No such device
- On Ubuntu v8.04, the new motherboard has placed the information pertaining to its integrated NICs inside the file:
# /etc/udev/rules.d/70-persistent-net.rules
- It will have appended this info as eth2 and eth3 inside this file
- You need to comment out the old MAC address info for eth0 and eth1(first couple of lines in the file) and then
- you need to change the mention of eth2 and eth3 to eth0 and eth1
- Restart the server:
# shutdown -r now
- Ensure you can stop and start networking
# /etc/init.d/networking stop # /etc/init.d/networking start * Ensure you can ping an internal resource <pre># ping 10.5.5.254
- Ensure you can ping Google if Firewall permits it on that server
# ping www.google.com
After Virtualization something is missing
- Your virtual server doesn't have some functionality which the parent has?
- Just apt-get the functionality you need.
- For example a virtual server does not appear to have the updatedb and locate capability so:
apt-get locate
- Then run update:
updatedb
- locate <whatever> should work fine again
What Ubuntu version am I running?
- Login and check version
sudo lsb_release –a