Posts tagged Sysadmin

How I use ls on Linux

When I run ls, I run it as ls -lAhog:

  • l says to put each file or folder on its own line
  • A says to list all files – hidden files, backups, etc. – but omit the current directory (.) and the parent directory (..)
  • h says to use human readable file sizes – 1.5G instead of 1628688384
  • g says to omit the user
  • o says to omit the group

Occasionally I use the -R parameter, which lists folders and subfolders recursively.

How to change the root password on MySQL

Sometimes the simplest sysadmin tasks are the hardest to find straightforward answers to. Recently, I spent too much time trying to change the root password on a fresh mysql install.

Changing the root password for MySQL has security implications; there is no shortage of paranoid nerds describing how the world might end if you do what I’m about to do. If you understand the security implications of setting the root MySQL password, and still want to do it anyway, here’s how:

mysql -uroot

And, once logged in to the mysql console:

UPDATE mysql.user SET Password=PASSWORD('the password goes here') WHERE User='root';
FLUSH PRIVILEGES;

How to start and stop Apache in OS X

How to start Apache:

sudo apachectl start

How to stop Apache:

sudo apachectl stop

How to restart Apache:

sudo apachectl restart

N.B. I am on OS X Mavericks. It ships with Apache 2.

How to dump all MySQL databases to a gzip file from inside a bash script

Often as part of an hourly, daily, or weekly server backup bash script, you will wish to dump all MySQL databases to disk as a gzip file. This way, in the case that any of your databases suffer from corruption or user error, you will have a backup.

Simply put this command inside your cron-scheduled backup bash script, substituting the USERNAME, PASSWORD, and the destination path with your info:

#!/bin/bash
mysqldump -u USERNAME -pPASSWORD --all-databases --routines| gzip > /mysqlbackups/MySQLDB_`date '+%m-%d-%Y'`.sql.gz

Creating a ruby launchd task with RVM in OS X

In the last few years, ruby has taken the world by storm. With different projects dependent on different versions of Ruby, many Rails, Jekyll, and Sinatra programmers have installed RVM to manage their ruby versions in OS X. I am one of them.

While RVM is awesome, it can make some previously simple tasks difficult. One such example is creating a launchd daemon that invokes a ruby script. If your gems are installed with RVM, you will need to use RVM to write your daemon. That’s where it gets complicated.

This tutorial teaches you how to schedule a ruby task on OS X using launchd. You can schedule any ruby file to be run. It will be executed using the RVM ruby version of your choice.

more...

How to start and stop Apache 2 in Ubuntu Linux

How to start Apache 2:

sudo service apache2 start

How to stop Apache 2:

sudo service apache2 stop

How to restart Apache 2:

sudo service apache2 restart

How to reload Apache 2:

sudo service apache2 reload

Reloading is useful if you change a virtualhost file, since it will not actually stop Apache. Therefore, your websites will not go offline (even for a few seconds).

Where to put custom bash scripts in OS X

If you make a custom bash script in OS X, and you want everyone on the system to be able to access it, this is the directory where you should save it:

/usr/local/bin

How to change ownership recurisively in Linux

Run this command, replacing USER and GROUP with the user and group to which you would like the files changed; substitute DIRECTORY for the folder whose ownership you would like to change:

chown -R USER:GROUP ./DIRECTORY
more...

How to dump a MySQL database

There are many cases where you will want to dump a MySQL database. Examples include: backing up a website, migrating a website to a new server, moving from a development machine to a production server, and more.

Simply run this command, substituting the USERNAME, DATABASE_NAME, and FILENAME with your info. When you run this command, it will prompt you for the MySQL password for the USERNAME you provided:

mysqldump -u USERNAME -p DATABASE_NAME > FILENAME.sql
more...

How to open the MySQL console

The MySQL console allows you to directly execute SQL commands, without having to use a programming language adapter such as PHP, Ruby, or Python.

Run this command, replacing USERNAME with your MySQL username; you will be prompted for the password.

mysql -u USERNAME -p -h localhost
more...

How to set up a new virtualhost domain in Apache 2

This guide will show you how to quickly set up a new website in Apache 2 using virtualhosts. Follow these instructions exactly as written, down to the character: trailing slashes, case, line breaks, etc.

Start by firing up a terminal, and creating a folder for the new website:

mkdir /var/www/my-new-website.com
more...

How to unzip a file on the Linux commandline

In order for this to work, the unzip command must be installed. If you do not have unzip on your system, install it using the package manager for your distro (apt-get, etc.).

unzip ./FILE_NAME.zip

My minimal Apache2 virtualhost file

I have written at length about how administering a Linux server is a nightmare. It does not matter how smart, experienced, or nerdy you are. Everyone who uses Linux bangs their head against a wall from time to time.

more...