How to power your computer up from away from home

The low-tier, DIY VPN has proven popular. The biggest drawback with its approach has been that it requires you to keep a PC on at home. But if your computer is configured to hibernate after a period of inactivity, or if the power goes out, you’ll have a problem.

If you’re willing to do some work, you can use Wake-on-LAN over any Internet connection to solve that issue and power on the computer at will.
Read more

Scripting Windows sysadmin tasks

I mentioned a couple of days ago a coworker’s philosophy about sysadmins and scripts that automate most tasks.

Here’s a site that has a lot of useful one-liners. http://www.robvanderwoude.com/ntadmincommands.php
Read more

How I changed servers midstream

When upgrading this site, I replaced the underlying hardware as well. The old server was just a dead end in too many regards to be worth upgrading in place, and besides, being able to run new and old side by side for a time is helpful.

This type of maneuver is routine work for a professional sysadmin. But it’s been at least two years since I’ve done a similar maneuver at all, and at least five years since I did it with Linux.

When I built the new machine, I gave it a unique IP address. Turnkey Linux makes getting an operational LAMP stack trivial, and depending on what you want to run on that stack, you may even be able to get that installed for you too.

Unfortunately for me, the Geeklog migration tool doesn’t seem to work with WordPress 3.0.1. So I had to get WordPress running on my old hardware in order to migrate. I chose WordPress 2.0.11 because the 2.0 branch appeared to be the current branch when Justdave wrote his migration tool, and 2.0.11 ran without complaint on the dated versions of PHP and MySQL that were on my old server.

After importing the content, I used mysqldump to export my databases. Specifically:

mysqldump --opt -u [mysql username] -p [database name, probably wordpress] > wordpress.sql

I should have gzipped the file, but I didn’t.

gzip wordpress.sql

I then connected to the old server via FTP and transferred the file. Use your favorite file transfer method; I happened to have FTP set up for my internal network.

Uncompress the file if you compressed it:

gunzip wordpress.sql.gz

Then restore the file:

mysql -u [mysql username] -p [database name] < wordpress.sql

Or, if the database already exists, like in my case:

mysqlimport -u [uname] -p [database name] wordpress.sql

Then I connected to the webserver via my web browser. WordPress 3.0.1 saw the WordPress 2.0.11 database and informed me that it needed to be upgraded. So I let it do its thing, and a few minutes later, I had a functioning WordPress site with 10 years’ worth of legacy entries.

I messed around with it for a while. Finally, I decided to go live. And at this point, I should have physically moved the new server into its permanent home. I didn’t do that, so now when I decide to move the server, I’m going to have some downtime.

To flip the IP addresses, you need to know where your Linux box stores its IP address. Debian and Ubuntu both store it in /etc/network/interfaces. As far as I can tell, Red Hat and derivatives like CentOS store it in /etc/sysconfig/network-scripts/ifcfg-eth0, but I haven’t used Red Hat or a derivative in a long time, perhaps 2003.

If worse comes to worse, try something like this to determine where it’s stored:

grep -r [ip address] /etc/

I edited the appropriate file on both boxes, changing the IP address while leaving all of the other parameters unchanged.

I then issued the command ifdown eth0 on both machines.

On my new production server, I then issued the command ifup eth0. Depending on the Linux distribution, it might also be necessary to re-issue a default route command. I didn’t have to do that.

Depending on how much Linux/Unix cred you have at stake, you could just do it the Windows way and reboot the box. Or both of them.

Once I was satisfied everything was working, I powered down the old server and celebrated.

WordPress may be coming soon. I hope.

I’m experimenting with WordPress. I have it up and running on a system built from spare parts, but importing from this archaic blogging platform that nobody uses (and for good reason) is less than obvious. A filter exists but isn’t officially blessed, so you can’t just go grab it like you can for a common blog platform like Movable Type or Greymatter.I’m going to look at it all again when I’m less tired. It may be possible to just take the importer and turn it into a standalone program that just slurps the database over and puts it into WordPress format. It’s probably been eight years since I did any PHP coding at all. But I have everything to gain from the move.

As far as I can tell, this server and this software have been running for 8 years. That’s a good run, but it’s too long. It’s time to modernize. Time to use modern software, running on a system that was built in this century.

Cheap upgrades

Yesterday, during my weekly garage sale adventures, I bought some computer equipment. Among the haul: a Biostar Socket A motherboard with an AMD Sempron 2200+ CPU and 512MB of RAM. It’s not state of the art, but can hold its own against some of the stuff still on the market, and it’s a big upgrade over the 450 MHz Pentium II that’s been powering this web site since July 2002.I swapped the board into my 266 MHz Pentium II. That first-generation P2 was a useful machine for me for a while, but mostly it’s just been taking up space. I had to do some slight modifications to get the newer board to bolt in, but it fit without too much trouble and now some of the 11-year-old hardware is useful again. It reminded me a lot of my college days, when I used to drop 486 and Pentium boards into IBM PC/ATs.

Debian installed on the upgraded system with no complaints, but I quickly found my Linux command line skills are rusty. And there have been enough changes in the last six years that I can’t just copy over /var/www and /var/lib/mysql and expect it to run like it used to.

So I’ll apply my 15 minutes per day principle. My chances of finding a block of 2-3 hours to get it all done are near zero, but I should be able to find a few minutes each day. So one day I can move the databases, then I can move the HTML and PHP another day, convert to WordPress still another day, and maybe, just maybe, have a vastly improved site in about a week if it all goes well.

When in St. Louis, don’t miss the City Museum

So, not wanting to celebrate the Anheuser-Busch-mandated holiday of New Year’s Eve but not wanting to sit around at home on a Friday night either, a good idea came up: Go to the City Museum.

It claims to be unlike any other museum you’ve ever seen. While that may be debatable, it does have something for everyone.It’s a very hands-on museum designed for exploration. The first level is almost like a catacombs, with secret passages and the like. Wear comfortable tennis shoes. You’ll need them.

The other two levels are a bit more museum-like but still hands-on. Each level has a large slide that goes down to the lobby. Yes, adults can fit in the slides too. I know because I went down each of them about three times.

You’ll find a level of art and artifacts and various activities. Included is a very large, elaborate, and critically acclaimed HO-scale model railroad that was built by St. Louisan Pete Fordyce in the 1950s. Fordyce was a frequent contributor to Model Railroader magazine and the layout is reasonably famous, as far as model railroads go. Anyone who ever built a plastic model kit as a child will be impressed with it; a model railroader could probably stand there for hours studying the techniques.

The top floor has a very large exhibit dedicated to architecture. The artifacts include doors, windows, cornices, and even entire storefronts. Most artifacts have signs telling where they came from and why the building was demolished–sadly, usually for something stupid and generic like a chain store or a gas station. There are exhibits about the histories of door hinges and doorknobs. How can hinges and knobs be interesting? They weren’t always the boring, bland mass-produced affairs you see at Home Depot today.

Outside, there are lots of things for kids (big and small) to climb on. I didn’t climb much; as much as I would have liked to climb up to that airplane and go inside it, climbing up three stories on semi-open girders to get there is more than my nerves can take. Judging from the number of people climbing on it, I’m in the minority and that’s a good thing.

I absolutely recommend it. At night when the admission is only $5, not only is it cheaper than going to the movies, but you’ll get some exercise and if you’re not careful you just might learn something. During the day it’s far less expensive than going to an amusement park.

Incoming link: http://trainboard.com/grapevine/showthread.php?t=56703

How to get your RSS/RDF feed working with Mozilla Firefox\’s Live Bookmarks

As soon as I upgraded to Mozilla Firefox 1.0, I started noticing that when I visited certain sites that had RSS/RDF feeds, a big orange “RSS” icon showed up in the lower right hand portion of the window.

That’s cool. Click on that, and you can instantly see that site’s current headlines, and know if the site has changed, just by looking in your bookmarks.

Except my site has an RSS feed and that icon didn’t show up. Here’s how I fixed it.At first I figured Firefox was looking for the standard “XML” icon everyone uses. So I added that. No go.

So I investigated. A Google search didn’t tell me anything useful. So I went to Slashdot’s page and viewed the source. Four lines down, I found my answer.

In your section, you need to add a line. In my case, since I run GeekLog, it was this:

LINK REL=”alternate” TITLE=”Silicon Underground RSS” HREF=”//dfarq.homeip.net/backend/siliconunderground.rdf” TYPE=”application/rss+xml”

Just substitute the URL for your RSS feed for mine. The two slashes at the beginning are necessary. The whole line has to be enclosed in , of course. (I can’t show them here because my blogging software is trying to protect me from myself.)

But since Geeklog doesn’t have an index.html file, and its index.php file is mostly programming logic, where do you add your code?

In your themes directory, in the file header.thtml, that’s where. I put mine right after the line that indicates the stylesheet.

The location for other blogging systems will vary, of course. But I notice some seem to do it automatically.

Now your readers can keep track of you without constantly refreshing your page (which they probably won’t do) and without having to run a separate RSS aggregator. Pretty cool, huh?

Any Unix gurus care to help me with mod_rewrite?

I’ve watched my search engine traffic decrease steadily for the past few months since I changed blogging software. It seems most engines don’t care much for the super-long arguments this software passes in its URLs.

The solution is mod_rewrite, and I think my syntax looks correct, but it’s not working for me.The goal is to fake out search engines to make them think they’re looking at static files. Search engines are reluctant to index database-driven sites for fear of overloading the site. Since I can’t tell them not to worry about it, I have to make the site look like a static site.

To that end, I created a section at the end of my httpd.conf file:

# rewrites for GL

RewriteEngine on
RewriteRule ^/article/([0-9]+)$ /article.php?id=$1 [NC,L]

This line should make the software respond to Thursday’s entry (https://dfarq.homeip.net/article.php?story=20040902200759738) if it’s addressed as https://dfarq.homeip.net/article/20040902200759738.

Once mod_rewrite is working, in theory I can modify the software to generate its links using that format and watch the search engines take more of a liking to me again. But I’ve got to get mod_rewrite going first, and I’m stumped.

Any expert advice out there?

Thanks in advance.

Optimizing dynamic Linux webservers

Linux + Apache + MySQL + PHP (LAMP) provides an outstanding foundation for building a web server, for, essentially, the value of your time. And the advantages over static pages are fairly obvious: Just look at this web site. Users can log in and post comments without me doing anything, and content on any page can change programmatically. In my site’s case, links to my most popular pages appear on the front page, and as their popularity changes, the links change.

The downside? Remember the days when people bragged about how their 66 MHz 486 was a perfectly good web server? Kiss those goodbye. For that matter, your old Pentium-120 or even your Pentium II-450 may not be good enough either. Unless you know these secrets…

First, the simple stuff. I talked about a year and a half ago about programs that optimize HTML by removing some extraneous tags and even give you a leg up on translating to cascading style sheets (CSS). That’s a starting point.

Graphics are another problem. People want lots of them, and digital cameras tend to add some extraneous bloat to them. Edit them in Photoshop or another popular image editor–which you undoubtedly will–and you’ll likely add another layer of bloat to them. I talked about Optimizing web graphics back in May 2002.

But what can you do on the server itself?

First, regardless of what you’re using, you should be running mod_gzip in order to compress your web server’s output. It works with virtually all modern web browsers, and those browsers that don’t work with it negotiate with the server to get non-compressed output. My 45K front page becomes 6K when compressed, which is better than a seven-fold increase. Suddenly my 128-meg uplink becomes more than half of a T1.

I’ve read several places that it takes less CPU time to compress content and send it than it does to send uncompressed content. On my P2-450, that seems to definitely be the case.

Unfortunately, mod_gzip is one of the most poorly documented Unix programs I’ve ever seen. I complained about this nearly three years ago, and the situation seems little improved.

A simple apt-get install libapache-mod-gzip in Debian doesn’t do the trick. You have to search /etc/apache/httpd.conf for the line that begins LoadModule gzip_module and uncomment it, then you have to add a few more lines. The lines to enable mod_gzip on TurboLinux didn’t save me this time–for one thing, it didn’t handle PHP output. For another, it didn’t seem to do anything at all on my Debian box.

Charlie Sebold to the rescue. He provided the following lines that worked for him on his Debian box, and they also worked for me:

# mod_gzip settings

mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_add_header_count Yes
mod_gzip_minimum_file_size 400
mod_gzip_maximum_file_size 0
mod_gzip_temp_dir /tmp
mod_gzip_keep_workfiles No
mod_gzip_maximum_inmem_size 100000
mod_gzip_dechunk Yes

mod_gzip_item_include handler proxy-server
mod_gzip_item_include handler cgi-script

mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/postscript$
mod_gzip_item_include mime ^application/ms.*$
mod_gzip_item_include mime ^application/vnd.*$
mod_gzip_item_exclude mime ^application/x-javascript$
mod_gzip_item_exclude mime ^image/.*$
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include file .htm$
mod_gzip_item_include file .html$
mod_gzip_item_include file .php$
mod_gzip_item_include file .phtml$
mod_gzip_item_exclude file .css$

Gzipping anything below 400 bytes is pointless because of overhead, and Gzipping CSS and Javascript files breaks Netscape 4 part of the time.

Most of the examples I found online didn’t work for me. Charlie said he had to fiddle a long time to come up with those. They may or may not work for you. I hope they do. Of course, there may be room for tweaking, depending on the nature of your site, but if they work, they’re a good starting point.

Second, you can use a PHP accelerator. PHP is an interpreted language, which means that every time you run a PHP script, your server first has to translate the source code into machine language and run it. This can take longer than the output itself takes. PHP accelerators serve as a just-in-time compiler, which compiles the script and holds a copy in memory, so the next time someone accesses the page, the pre-compiled script runs. The result can sometimes be a tenfold increase in speed.

There are lots of them out there, but I settled on Ion Cube PHP Accelerator (phpa) because installation is a matter of downloading the appropriate pre-compiled binary, dumping it somewhere (I chose /usr/local/lib but you can put it anywhere you want), and adding a line to php.ini (in /etc/php4/apache on my Debian box):

zend_extension=”/usr/local/lib/php_accelerator_1.3.3r2.so”

Restart Apache, and suddenly PHP scripts execute up to 10 times faster.

PHPA isn’t open source and it isn’t Free Software. Turck MMCache is, so if you prefer GPL, you can use it.

With mod_gzip and phpa in place and working, my web server’s CPU usage rarely goes above 25 percent. Without them, three simultaneous requests from the outside world could saturate my CPU.

With them, my site still isn’t quite as fast as it was in 2000 when it was just serving up static HTML, but it’s awfully close. And it’s doing a lot more work.

 

Easy and secure remote Linux/Unix file transfers with SCP

Sometimes you need to transfer files between Linux boxes, or between a Linux box and some other box, and setting up Samba or some other form of network file system may not be practical (maybe you only need to transfer a couple of files, or maybe it’s just a one-time thing) or possible (maybe there’s a firewall involved).
Well, you should already have SSH installed on your Linux boxes so you can remotely log in and administer them. On Debian, apt-get install ssh sshd. If you’re running distro based on Red Hat or UnitedLinux, you may have a little investigative work to do. (I’d help you, but I haven’t run anything but Debian for 2 or 3 years.)

The cool thing about SSH is that it not only does remote login, but it will also do remote file transfer. And unlike FTP, you don’t have to stumble around with a clumsy interface.

If you want to transfer files from a Windows box, just install PuTTY. I just downloaded the 240K PSCP.EXE file and copied it into my Windows directory. That way I don’t have to mess with paths, and it’s always available. Make sure you’re downloading the right version for your CPU. The Windows NT Alpha version won’t run on your Intel/AMD/VIA CPU. Incidentally, Putty.exe is a very good Telnet/SSH client and a must-have if you’re ever connecting remotely to Unix/Linux machines from Windows.

SSH includes a command called SCP. SCP works almost like the standard Unix CP command. All you to do access a remote file is append a username, followed by the @ sign, and the IP address of the remote server. SCP will then prompt you for a password.

Let’s say I want to move a file from my Linux workstation to my webserver:

scp logo.jpg root@192.168.1.2:/var/www/images

SCP will prompt me for my password. After I enter it, it’ll copy the file, including a nice progress bar and an ETA.

On a Windows machine with PuTTY installed, simply substitute the command pscp for scp.

I can copy the other way too:

scp root@192.168.1.2:/var/www/index.php .

This command will grab a file from my webserver and drop it in the current working directory.

To speed up the transfers, add the -C switch, which turns on compression.

SCP is more secure than any other means of file transfer, it’s probably easier (since you already need SSH anyway), and since it’ll do data compression, it’s probably faster too.