Posts

Showing posts from December, 2016

Search and replace with Vim and Sed

  Using search and replace is a great way to save time when editing large files in Linux. Becoming proficient with this task will increase your efficiency and will reduce your time spent doing tedious and error-prone file edits by hand. For the sake of this tutorial, I’m going to use a copy of the /etc/apt/sources.list file to illustrate some of the changes that we can make. From your users home directory copy the sources.list file to your home directory. Or you can copy the contents of my list, shown a bit further down, into a new file. This tutorial assumes that you are comfortable reading and writing files with vim. If not open a terminal and type:  vimtutor sudo cp /etc/apt/sources.list /home/luke/sources.txt sudo chown $USER:$USER sources.txt Here are the contents of my sources.list file. cat sources.txt # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ xenial main res

Command not found!

  So you’re running through some instructions to configure software on your system, or troubleshoot some problem with a service and you see an error at the command line that says “command not found”. Here is how to locate the packages you need to install in order to use commands that are not available on your system. CentOS/Red Hat - yum provides Yum is an excellent package manager with lots of great built in functions. Using   yum provides <command>  will output a list of packages that provide the command you are trying to run. Here is an example of the output. sudo yum provides vgscan Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: repo1.sea.innoscale.net * epel: mirror.cogentco.com * extras: mirror.cisp.com * nux-dextop: mirror.li.nux.ro * updates: ftp.linux.ncsu.edu 7:lvm2-2.02.166-1.el7.x86_64 : Userland logical volume management tools Repo : base Matched from: Filename : /usr/sbin/vgscan 7:lvm2-2.02.166-1.el7_3.1.x86_64 : U

What to do when df and du report different usage.

  You may occasionally come across an issue where running  df  will produce output that disagree’s with the output of the  du  command. If you aren’t familiar with these two commands do see my post about   filesystem and directory size . The reason for the difference in reported size is that  df  does not differentiate between files that are open in memory but have been deleted, or altered on the disk, whereas  du  will only see the files that are on the disk. You should recognize that these tools serve different functions and that you will need to rely on both of them to get a truly accurate portrayal of disk usage on your system. Lets say you run   df -h  to get an idea of how much space you have on each of the filesystems on your server or PC only to see that /var is 98% full, 9.8G out of 10G just to keep it simple. Like a good admin you run   du -h --max-depth=1 /var  to find out which directories are the largest and may have files that need to be zipped up, moved, or deleted. The

Managing packages with zypper

Image
  Suse Enterprise Linux and it’s upstream community distro openSUSE use a package manager called “zypper”. Zypper is a fast easy to use package management tool. In my opinion, zypper is hands down the best package manager out there. It provides meaningful, easy to read output, it resolves package dependencies quickly, and it has a cool name. Zypper has many options that can be abbreviated; install (in), search (se), info (if), update (up) and lots of others. Basic package operations Search for a package Search with zypper search  or zypper se luke@OpenSUSE-tst:~> sudo zypper search apache2 Loading repository data... Reading installed packages... S | Name | Summary | Type --+----------------------------+----------------------------------------------------------------------+-------- | apache2 | The Apache Web Server Version 2.4 | package | apache2

Uncomplicated Firewall… be careful

  If like me, you enjoy the simplicity of UFW (Uncomplicated Firewall) on your Ubuntu servers be careful when you turn it on. UFW doesn’t have any default rules to allow ssh inbound by default, if you aren’t careful when turning it on you could find yourself locked out, and if you don’t have direct console access to the server that could mean being locked out forever! Not a conversation you want to have with a client, or your boss,… or tech support at your friendly cloud provider. So before turning UFW on for the first time here are couple quick tips. The easy way Build your allow rule first. sudo ufw allow 22/tcp sudo ufw show added Only then after seeing the output which confirms the rule is added, should you turn on ufw. sudo ufw enable The less easy way - edit the file directly Why would you want to use the less easy way!? Well, you may have need to copy this file over to a newly built server. Maybe because you like to know where configuration files hide. Or maybe just because you

Microsoft and Linux working together!

Image
  I’ve been thrilled to see the recent collaboration between Microsoft and various Linux distributions. Everyone has seen the Microsoft <3 Linux headlines over the last few months, and I’ve been curious about how this relationship has been reciprocated by the Linux community. So I decided to ask Stephanie Wonderlick at Red Hat and Rebecca Cradick at Canonical (the company behind Ubuntu) a few questions about the current state of Linux and Microsoft’s cross-platform cooperation. After my initial contact with Stephanie, I was able to get a few questions over to Mike Ferris, Vice President of Business Architecture at Red Hat who had some great insights for me. I’ll present the full question and answer’s a little further down. Both companies recognize that customers will have a mix of both Microsoft Windows and Red Hat Enterprise Linux within their development and datacenter architectures and will look to deeper integration. - Mike Ferris When you think about it, this type of strategic

Backup a MySQL Database

Image
  If you have a MySQL database working behind the scenes on your web site or app then creating and storing backup’s of that database can be vitally important to the operation of your business operations. A MySQL or MariaDB database uses the  mysqldump  command to create backups. The  mysqldump  command outputs a file that contains SQL statements that can be used to rebuild your database, with all of its data. Which could come in handy in the event of an unrecoverable crash or even to just move the database to a new server. Following the steps in this guide should work on any distribution of Linux that is using MySQL or MariaDB. Contents 1. Review the command 2. Convert to script 3. Run as nightly cron job 4. Restore database Quick note: When you see me use angle brackets <> it means you should alter the command to fit your needs. For example  means use your username; so cd /home/  should be cd /home/spidey for a user called spidey. Secondly all of the below commands shoul

Find services that require a restart

  Ubuntu offers a live patching utility that allows kernel patches to be installed without requiring a system restart to be applied. Read more about online patching in this post about   patching.   That said, in many cases other services or processes on your system may need to be restarted after an upgrade. Finding services that need to be restarted in Ubuntu Install debian-goodies sudo apt update sudo apt install debian-goodies Now just run sudo checkrestart This command will output a list of processes and services that need to be restarted. Update - 12/26/2016 I just discovered that there is another Debian/Ubuntu program that will not only check for services that need a restart but also restart them for you. sudo apt install needrestart Running this program without options will attempt to restart all services that have been updated. You can also run this program interactively if you want to see which services need to be restarted and choose only the one’s that you want to install. su