Archive for the ‘Tip of the day!’ Category

Rebooting: quick tip

Wednesday, April 9th, 2014

Note to self: whenever rebooting a server, login via SSH and restart the OpenSSH daemon first to validate that it will come back up.

I just updated an AWS instance and rebooted it without doing this. Some new update in OpenSSH required that the AuthorizedKeysCommandUser be defined if AuthorizedKeysCommand is defined and the OpenSSH daemon will not start.

Luckily I can tell puppet to fix this and will be able to login in 30 minutes but that’s 30 minutes I’d prefer not to wait.

- josh

Proxy HTTP Requests through Nginx to Jetty6 with X-Forwarded-For

Wednesday, March 14th, 2012

One important part of any proxy configuration is logging the correct originating IP address on the final application log to ensure proper analytics and problem determination. Note that at times, it’s very useful to log the proxy or load balancer IP at the application server to determine where an issue may be occurring but for the most part, the original IP address is desired in the application log.

This example is using;

  • Amazon Linux (as of 2012-03)
  • nginx-0.8.54-1.4.amzn1.x86_64
  • jetty6-6.1.14-1.jpp5.noarch from jpackage.org

Perform the following steps:

  1. Install and configure nginx to proxy all requests to localhost port 8080.
  2.        location / {
                    proxy_pass   http://127.0.0.1:8080;
            }
    
  3. Install and configure jetty6, using all default options.
  4. Configure nginx to set the proxy header values for X-Forwarded-For
  5.        location / {
                    proxy_set_header X-Real-IP       $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host            $host;
                    proxy_pass   http://127.0.0.1:8080;
            }
    
  6. Configure Jetty to log the X-Forwarded-For IP in /etc/jetty6/jetty.xml under the RequestLog section

  7. ...
    <Set name="LogTimeZone">GMT</Set>
    <Set name="PreferProxiedForAddress">true</Set>
    </New>
    ...

  8. Once that is complete, restart both nginx and jetty to test.
  9. sudo /etc/init.d/nginx restart
    sudo /etc/init.d/jetty6 restart
    

List MySQL Table Space Consumption

Thursday, December 15th, 2011

Have you ever needed to print out a list of each table within MySQL and how much space was consumed?

Try this to list the top 20 space offenders:

SELECT engine, concat( table_schema, '.', table_name ) table_name,
concat( round( data_length / ( 1024 *1024 ) , 2 ) , 'M' ) data_length,
concat( round( index_length / ( 1024 *1024 ) , 2 ) , 'M' ) index_length,
concat( round( round( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , 'M' ) total_size
FROM information_schema.TABLES
ORDER BY ( data_length + index_length ) DESC LIMIT 20

Taken from a comment on the mysql developer docs site: http://dev.mysql.com/doc/refman/5.1/en/tables-table.html

Bash Tip! for loop on directory listing

Tuesday, August 24th, 2010

One very common task when scripting with bash is to use a for loop to iterate over the contents of a directory or directory tree. There are two primary methods of accomplishing this task; using ls and using find. We’ll not consider the manual method as that would be completely unworthy of our attention.

I find it easy to start with ls when I don’t need to recurse into a directory tree as that is a command that I use often. This often turns into a process such as this:

for dir in $(ls)
do
  echo ${dir}
done

Now the above method typically does not work for me. I have an alias setup to print out pretty colors when I issue the ls command and that will cause each command which operates on the variable $dir to fail with a “No such file or directory” error. I always have to remember this and re-write the command with the flag to disable color formatting:

for dir in $(ls --color=never)
do
  echo ${dir}
done

The above script will work every time.

The next option is using find. find is awesome and all powerful. Learn and use find. The most common issue when using find is that you may have to filter out the current and/or parent directories when processing the results. Take this example:

for dir in $(find . -maxdepth 1 -type d)
do
  echo ${dir}
done

This loop will print out the current directory, as well as all other directories in the current working directory. If you are running some sort of processing within this loop, you may end up re-processing everything unless you discard the current working directory (noted by the dot).

This example will not process the current working directory:

for dir in $(find . -maxdepth 1 -type d)
do
  if [ ${dir} == "." ]
  then
    continue
  fi
  echo ${dir}
  while pushd ${dir}
  do
    echo ${dir}
  done
  popd
done

Bash for loops are incredibly useful and easy to work with. Use the above tips and make bash work for you.

System Administrator Technical Interviews

Thursday, July 8th, 2010

I have had the opportunity to interview many candidates over the past few months and have a few tips:

  • When indicating that you have VMware experience, clearly indicate which features you have experience with. I have interviewed many candidates who claim to be experts on VI3/vSphere and yet have never used clustering or shared storage.
  • When asked about rating yourself from 1-5 or 1-10, make sure you understand which side is the proficient side and give an example of what you think is proficient in a particular area.

My methodology is to ask the interviewee to rate themselves and then ask them what that rating means to them. If they rate themselves a 4 out of 5 with general Linux system administration, I then ask them to give me a few examples of what somebody who has a 4/5 rating would be able to do. I then ask them questions based on that assessment. If you can’t win on those terms, you typically can’t win.

It is not my desire to stump somebody in an interview, I would prefer to ask them questions about what they have done in the past and get into a good dialogue about things they are familiar with.  Do your interviewer a favor and be very clear on the resume and during the interview process.

Bash Tip! Renaming files using Bash string operations

Wednesday, January 6th, 2010

To rename all html files in a particular directory to shtml files, use the following loop:

for file in *.html
do
  mv ${file} ${file%%.html}.shtml
done

This uses the ${variable%%match} format which strips the longest match from the end of the variable.