How To Configure NTP Service in FreeBSD
The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks.
If you only wish to synchronize your clock when the machine boots up, you can use ntpdate. This may be appropriate for some desktop machines which are frequently rebooted, but for servers you should run ntpd.
1. Clock Synchronization using ntpdate
Using ntpdate at boot time is also a good idea for machines that run ntpd. The ntpd program changes the clock gradually, whereas ntpdate sets the clock, no matter how great the difference between a machine's current clock setting and the correct time.
Print This PostHow To keep ports collection up to date in FreeBSD
The FreeBSD Ports collection is a package management system for FreeBSD which provides an easy way of installing software packages on the FreeBSD operating system.
1. Updating the ports collection
a.) Using CVSup method
This is a quick method of getting and keeping your ports collection up to date using cvsup protocol. Make sure /usr/ports is empty before you run cvsup for the first time.
If you never updated ports collection you have to install cvsup utility:
# pkg_add -r cvsup-without-gui
Update ports collection:
# cvsup -L 2 -h cvsup.freebsd.org /usr/share/examples/cvsup/ports-supfile
Above step will take some time to fetch the files.
b.) Using portsnap method
Portsnap is an alternative system for distributing the ports collection.
Install portsnap with the following command:
# pkg_add -r portsnap
Print This PostHow To Set Up a NFS Server in FreeBSD
Network File System (NFS) is a network file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.
1. Setting up a NFS Server
The first step to setting up a NFS server is to edit the /etc/rc.conf file and add the following lines:
nfs_server_enable="YES"
nfs_server_flags="-u -t -n 4"
rpcbind_enable="YES"
mountd_flags="-r"
mountd_enable="YES"
Next, you have to set up /etc/exports file to define which machines have permission to which folders. The exports file looks something like this:
/data -maproot=user1 host1 host2 host3
/backup -alldirs host1 host2 host3
/store host2
In this example the machines host1,host2 and host3 are given the privileges of the user1 for the /data directory.
For /backup they are given access to read from all directories within backup. And for /store only host2 is given access to read just the /store directory (make sure you replace hosts with your desired host names).
To start NFS server, enter:
rpcbind nfsd -u -t -n 4 mountd -r
2. Restarting the NFS Server
Once you have made changes to the exports file you need to restart NFS for the changes to take effect:
kill -HUP `cat /var/run/mountd.pid`Print This Post
How To Reset MySQL Password
1. Stop MySQL server
# /usr/local/etc/rc.d/mysql-server stop
2. Start MySQL server with skip grant table mode
# mysqld_safe –skip-grant-tables &
Output:
[1] 5187
# Starting mysqld daemon with databases from /var/db/mysql
3. Login as user root without password
# mysql -u root -p
Print This PostApache HTTP Server + PHP 5 + MySQL Installation in FreeBSD
1. Install Apache HTTP Server
Go to apache22 port:
# cd /usr/ports/www/apache22
and type:
# make config
Now you can choose the options from the menu.
# make install clean
To enable apache on boot, add the following line to /etc/rc.conf
apache22_enable="YES"
To start apache http server, type
# /usr/local/etc/rc.d/apache22 start
2. Install PHP 5
Go to php port:
# cd /usr/ports/lang/php5
and type:
MySQL Server Installation in FreeBSD using ports
This guide describes how to install MySQL, a very popular relational database, in FreeBSD.
Please make sure the ports collection is up to date. If not, run the following command:
# portsnap fetch update
Then navigate to the ports folder for MySQL:
# cd /usr/ports/databases/mysql51-server
and run:
# make install clean
This command will download required files from the internet and will install MySQL server.
Once the install is finished, we install the database
# mysql_install_db --user=mysql
and we set up the directory permissions
# chown -R mysql /var/db/mysql/
# chgrp -R mysql /var/db/mysql/
Make sure MySQL server start automatically whenever FreeBSD comes up after reboot.
FreeBSD provide this facility via system configuration information. This file lists which services should be started up at system initial boot time.
The file contains the global system configuration information referenced by the start up scripts and is stored in /etc/rc.conf.
Configure FreeBSD to start MySQL at start up
Open /etc/rc.conf file using a text editor ( I use vi but you can use your preferred editor )
# vi /etc/rc.conf
and append following line which will enable MySQL server automatically after each reboot:
mysql_enable="YES"
Save file and exit to shell prompt.
Starting MySQL server
To Start MySQL server under FreeBSD type following command (use script):
# /usr/local/etc/rc.d/mysql-server.sh start
Note: This will work only if you have mysql_enable="YES" in rc.conf. If you don't, use the following command:
# /usr/local/etc/rc.d/mysql-server.sh forcestart
MySQL Password
By default, MySQL super user account has no password. So it’s important to assign the administrator account password. To change the root password, enter the following command:
mysqladmin -u root password newpass
Replace newpass with your own desired password.
Optionally, copy either my-huge.cnf, my-large.cnf, my-medim.cnf or my-small.cnf (depending on the usage and utilization of your MySQL server) as my.cnf to /etc/ or /var/db/mysql which will enable you to tweak and change the configuration of server-specific MySQL server options by editing the file.
Print This PostHow To Recover the root Password in FreeBSD
The password cannot be recovered. The following procedure will allow you to change the root password.
Do the following:
- when the following boot message appears
Hit [ENTER] to boot immediately, or any other key for command prompt.
Booting [kernel] in 10 seconds...
hit a key, just pick one EXCEPT the ENTER key. You'll get a prompt like:
disk1s1a:>
- type the following commands:
disk1s1a:>unload all
disk1s1a:>load kernel
disk1s1a:>boot -s
The boot process will now start, just wait until it asks you for a shell. Just hit
ENTER and 'sh' will be used as shell.
If you type 'mount' you will see that only your root partition ( / ) is mounted, you will have to mount 'usr' partition as well.
#mount /dev/ad0s1f /usr
Now you have to mount root partition as read-write enabled. Use the following command:
#mount -u /
The root partition should now be mounted read-write. Now you can use 'passwd' program to
change the root password.
#passwd
That's all, reboot the system and login with the new password.
Print This PostFreeBSD: How To Upgrade FreeBSD 7 to 8 Stable Release
FreeBSD 7.x allows upgrade of existing installation to FreeBSD 8.0-STABLE. Since this is a major version upgrade, it is recommended that you backup your data, database and configuration files.
This guide will walk a user through updating his source to follow FreeBSD's stable branch. Please make a full backup of the current system before following this guide.
STEP 1: Syncing the source tree
- cvsup installation and configuration
# cd /usr/ports/net/cvsup-without-gui
# make install clean
OR
# pkg_add -r cvsup-without-gui
Copy the sample supfile for Stable to /usr/local/etc/stable-supfile:
# cp /usr/share/examples/cvsup/stable-supfile /usr/local/etc/
Edit file and set host name which specifies the server host which will supply the file updates to your system.
*default host=cvsup1.us.FreeBSD.org
Set release tag to stable 8:
*default release=cvs tag=RELENG_8
Run cvsup to download the latest stable source:
# cvsup -L 2 /usr/local/etc/stable-supfile
When the cvsup has completed, change to the /usr/src directory
Print This PostFreeBSD: How To boot kernel.old
If you want to boot with an old kernel, because the current one is not working properly, this is what you have to do:
During boot you get a message like:
"Booting kernel in 10 seconds or press enter..."
Just hit any key except the ENTER key and you'll get a prompt.
Type 'unload all' and then 'boot [kernel file]' where [kernel file] is the kernel you want
to boot e.g. 'kernel.old' .
Your FreeBSD machine will boot with the kernel you specified.
Print This Post