MySQLdump to reset Slave server from Master

Just a quick entry here. I keep forgetting how to reset a mysql slave server from the master, without disrupting the operations on the master server. Something silly that doesn’t stick in my head, so I am putting here for future use:

If you have Server A with the master, and Server B with the slave, and you need to reset the slave if it gets lost, simply do this:

Login to the Server A and issue this command:

mysqldump --master-data --all-databases newdbs.sql 

Then scp or ftp the newdbs.sql file to Server B.

Login to Server B, stop http and turn off the slave (slave stop;), load in the new database SQL file you brought over and restart the mysql slave (slave start;) and http:

/etc/init.d/httpd stop
mysql 
newdbs.sql
/etc/init.d/httpd start 

To be sure everything is working as it should, you can go into mysql and ‘show slave status;’

 

{deprecated} PalmOne Treo Error 0x7301

I just got a PalmOne Treo650 with my Bell account here in Quebec. Shortly after I got my new phone I started getting the error ‘Error 0X7301’ whenever I tried to connect to the internet.

After some searching on google, I came across the rather simple and straight forward solution. Here is the site I found the solution on: http://www.howardforums.com/showthread.php?threadid=899093

And here is the solution:

Goto the main application screen by pressing on the Home button, select Prefs and then Network under Communication. Beside where it says service at the top of your screen, you will probably see ‘1X Connection Copy’. This means that at some point I made a copy of my connection, which is not good apparently. Simply delete the copy by selecting Delete from the menu at the top. Click on Done and that’s it, your done!

You should now be able to connect to the internet again!

Albeit short and simple little how-to, I hope it helps someone else.

Formatting a second drive on RHEL Linux

Here is a quick little how-to for formatting a second drive on RHEL4 Linux. A great deal of credit goes to http://www.eth0.us/mount on this.

This how-to is based on my machine which has two 80GB scsi drives which we can see by doing the following:

#cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: FUJITSU Model: MAW3073NP     Rev: 5803
  Type:  Direct-Access             ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: SEAGATE Model: ST373207LW     Rev: D702
  Type:  Direct-Access             ANSI SCSI revision: 03

WARNING: Be very careful as the smallest mistake can lead to a complete loss of ALL information on your machine!

Now let’s get going!

The first thing we will do is run fdisk which is used to format a disk. I first run it with the -l (elle) flag to see what partitions my drives currently have:

[root@server var]# fdisk -l

Disk /dev/sda: 73.4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot     Start       End     Blocks   Id System
/dev/sda1   *        1       13     104391   83 Linux
/dev/sda2         14       268   2048287+  82 Linux swap
/dev/sda3         269       399   1052257+  83 Linux
/dev/sda4         400     8924   68477062+  5 Extended
/dev/sda5         400     8924   68477031   83 Linux

Disk /dev/sdb: 73.4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot     Start       End     Blocks   Id System
/dev/sdb1   *        1       13     104391   83 Linux
/dev/sdb2         14       268   2048287+  82 Linux swap
/dev/sdb3         269       399   1052257+  83 Linux
/dev/sdb4         400     8924   68477062+  5 Extended
/dev/sdb5         400     8924   68477031   83 Linux

As you can see above I can see the two SCSI drives and they both have partitions. This is because at some point in the past I ran dd to duplicate my primary disk over to my secondary disk. I want to now get rid of all those partitions on drive B and format drive B with one partition, which I will use to store my backups on.

The following is what did to remove the old paritions and create a new one:

[root@server var]# fdisk /dev/sdb

The number of cylinders for this disk is set to 8924.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
No free sectors available

Command (m for help): d
Partition number (1-5): 5

Command (m for help): d
Partition number (1-5): 4

Command (m for help): d
Partition number (1-4): 3

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Selected partition 1

Command (m for help): d
No partition is defined yet!

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-8924, default 1):  (Here we just hit -ENTER- to accept the default)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-8924, default 8924): (Here we just hit -ENTER- to accept the default)
Using default value 8924

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now when we run fdisk we can see the two drives with different partitions:

[root@server var]# fdisk -l

Disk /dev/sda: 73.4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot     Start       End     Blocks   Id System
/dev/sda1   *        1       13     104391   83 Linux
/dev/sda2         14       268   2048287+  82 Linux swap
/dev/sda3         269       399   1052257+  83 Linux
/dev/sda4         400     8924   68477062+  5 Extended
/dev/sda5         400     8924   68477031   83 Linux

Disk /dev/sdb: 73.4 GB, 73407820800 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot     Start       End     Blocks   Id System
/dev/sdb1           1     8924   71681998+  83 Linux

Now we need to format partition sdb1 so that Linux can use it. We will use ext3 in this case:

[root@server var]# mkfs.ext3 /dev/sdb1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
8962048 inodes, 17920499 blocks
896024 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=20971520
547 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
      32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
      4096000, 7962624, 11239424

Writing inode tables: done                  
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

The only thing left to do is create a mount point for the drive and add one line to our fstab. I like to put all my drives in a root folder called /mnt. So let’s create mnt and meaningful place within mount which I like to name after the drive, so in this case sdb. For future reference we can now easily keep track of which drive is which.

[root@server5 var]# mkdir /mnt
[root@server5 var]# cd mnt
[root@server5 var]# mkdir /sdb

Now we can add the line to fstab so the system know what to mount and where. Note that your fstab will vary considerably. The line I enter is ‘/dev/sdb1 /mnt/sdb ext3 defaults 1 1’ without the quotes:

[root@server mnt]# pico -w /etc/fstab

# This file is edited by fstab-sync - see ‘man fstab-sync’ for details
/dev/sda5 /    ext3   usrquota,grpquota 1 1
/dev/sda1 /boot   ext3   defaults 1 2
/dev/sda3 /tmp   ext3   defaults,noexec 1 0
none     /dev/pts devpts gid=5,mode=620 0 0
none     /proc   proc   defaults 0 0
none     /dev/shm tmpfs defaults 0 0
/dev/sda2 swap   swap   defaults 0 0
/dev/hdc           /media/cdrom         au
to   pamconsole,exec,noauto,managed 0 0
/dev/sdb1 /mnt/sdb ext3 defaults 1 1

Now ew can simply use the mount command to use our drive and check that it is there:

[root@server scsi]# cd /mnt/sdb/
[root@server5 sdb]# ls
lost+found

That’s all there is to it.

Setting up server-status on apache

The more I know how my server is feeling, the better off I am. Using apache’s built in Server Status is just one such tool that will let you see how apache is handling it’s load. The server status will tell you the server load, uptime, requests per second, total workers, available workers, and every connection to your apache server with who is connecting and to what page and on what site they are connecting. All very useful information especially if you are experiencing a problem.

This little tutorial will show you how one might setup their server status.
Little warning before you start, setting up server status can be insecure and give bad people access to critical information if done wrong. I am not liable for any problems that result from you following my tutorial, or any tutorial on this site. You break your server, that is your problem and yours alone.

Here is how I set it up:

First, let’s install a configuration file in /etc/httpd/conf.d. We will call it serverstatus.conf. Be sure it ends in conf or apache won’t see it.


<Location>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from XXX.XXX.XXX.XXX
</Location>

Location
Tells you what to enter in your browser. To be extra safe change it from server-status to something obscure. For this example I am going to use . To see the status you would then enter this into your browser: http://www.yourdomainname.com/st994576BB76.

SetHandler
Tells the server to apply the server status handler to this location

Order Deny,Allow
tells the server to Deny first and then Allow. Deny from all tells the server that first we will deny access to everyone. So no one can access the server status URL.

Allow from XXX.XXX.XXX.XXX
tells the server to allow access only from the IP address XXX.XXX.XXX.XXX. Be sure to change it to your own IP address. If you have a dynamic IP that changes quickly then this won’t work for you. Whatever you do, don’t let the world see your server status. It is insecure to let that info out.

So we now have a secure method to access the server status. Next we will turn on extended status in apache.

The file we are going to edit is /etc/httpd/conf/httpd.conf. First make a backup of that file. If you screw up this file your web server will NOT work anymore. So make sure you have a backup before proceeding.

Using your favourite editor, add this line–ExtendedStatus On–right after the Include conf.d/*.conf line. Mine looks like this after the change:


Include conf.d/*.conf
ExtendedStatus On

Now check that Apache still likes the config file by typing this at the command line:


/etc/init.d/httpd configtest

If the server comes back with ‘Syntax OK’ then you are set to reload apache. If any errors or warnings show up, be sure to fix them right away, and before restarting or reloading apache. If you cannot figure out why you are getting errors or warnings, you can always replace the modified version with the backup you made a few minutes ago.

Assuming all is safe, now you can enter


/etc/init.d/httpd reload

We use reload so it won’t kick anyone off the server and it is just nicer than restart, which kicks everyone off the server and then restarts.

Now you should be able to go to your URL http://www.yourdomainname.com/st994576BB76 and see the stats.

Pretty cool eh? Now you can see why you don’t want just anyone to see your server status.

If you don’t plan on using server status for awhile, be sure to disable it in the config files by turn ExtendedStatus Off in /etc/httpd/httpd.conf and removing the ‘Allow from’ line in the serverstatus.conf file. Or simply remove the serverstatus.conf file altogether.

Come back next week and I will show you how you can get a nice machine readable format of the stats.

Sendmail pipe php script dilemma

Spent a little bit tonight getting sendmail to pipe one address to a php script. My searching for solutions never gave my exact solution so here is what I did to get this working.

The setup: Ensim on RHEL4. Installed PHP script sits on the main servers site which sits in /var/www/html and not on a virtually hosted site. The script is called pipe.php and sits in /var/www/html/order/pipe/pipe.php

Step 1: Add an alias in /etc/alias for my support email. Be sure to rebuild the alias file after by typing newaliases at the command line.
support: “|/usr/bin/php -q /var/www/html/order/pipe/pipe.php”

Step 2: chmod the script so it is executable:

chmod 755 /var/www/html/order/pipe/pipe.php

Step 3: Create a symbolic link in /etc/smrsh so sendmail will know about my script. If you don’t do this then sendmail will spit out the wholly ugly error message Service unavailable, and smrsh: “php” not available for sendmail programs (stat failed).

cd /etc/smrsh
ln -s /usr/bin/php ./php
ln -s /var/www/html/order/pipe/pipe.php ./pipe.php

Now all you need to do is test the functionality of your new script by sending an email to .(JavaScript must be enabled to view this email address).

Note, that if you are installing a script on a virtual site you need to make the above changes in the virtual site files. So instead of adding links in /etc/smrsh you would add them in /home/virtual/siteXX/fst/etc/smrsh and instead of adding the alias in /etc/aliases, you would add them in /home/virtual/siteXX/fst/etc/aliases. Then to rebuild the aliases DB, you need to do this:

/usr/sbin/chroot /home/virtual/siteXX/fst newaliases

That is about all there was to it. The error messages I got back from sendmail took me a bit to figure out.

Page 16 of 18 pages ‹ First  < 14 15 16 17 18 >