2008年6月8日 星期日

How To Upgrade FreeBSD 6.2 to FreeBSD 6.3 ( Minor Update ) using freebsd-update utility

Q. I've FreeBSD 6.2 p9 installed and I'd like to upgrade my box to latest FreeBSD 6.3 release using binary update method. How do I upgrade my box over an ssh session?



A. FreeBSD 6.3 has new updated tool called freebsd-update which supports binary upgrades of i386 and amd64 systems systems running earlier FreeBSD releases, release candidates, and betas. Users upgrading to FreeBSD 6.3 from older releases (in particular, older than 6.3-RC1) will need to download an updated version of freebsd-update(8) that supports upgrading to a new release.


WARNING! These examples may crash your FreeBSD computer if executed or interrupted over ssh session. Backup both data and configuration file before attempting these instructions.

Step # 1: Find out current FreeBSD version


$ uname -mrs

Output:


FreeBSD 6.2-RELEASE-p9 i386

Step # 2: Download updated freebsd-update


Download an updated version of freebsd-update utility that supports upgrading to a new release.


Download freebsd-update-upgrade package:

# fetch http://people.freebsd.org/~cperciva/freebsd-update-upgrade.tgz

Download gpg key to verify package:

# fetch http://people.freebsd.org/~cperciva/freebsd-update-upgrade.tgz.asc

Verify package:

# gpg --verify freebsd-update-upgrade.tgz.asc freebsd-update-upgrade.tgz

Extract package:

# tar -xf freebsd-update-upgrade.tgz


Step #3: Start update procedure with freebsd-update


Start upgrade procedure and download all lates files / packages, enter:

# sh freebsd-update.sh -f freebsd-update.conf -r 6.3-RELEASE upgrade

Output:


Looking up update.FreeBSD.org mirrors... 1 mirrors found.
Fetching metadata signature for 6.2-RELEASE from update1.FreeBSD.org... done.
Fetching metadata index... done.
Fetching 1 metadata files... done.
Inspecting system...
The following components of FreeBSD seem to be installed:
kernel/generic world/base world/dict world/doc world/manpages

The following components of FreeBSD do not seem to be installed:
kernel/smp src/base src/bin src/contrib src/crypto src/etc src/games
src/gnu src/include src/krb5 src/lib src/libexec src/release src/rescue
src/sbin src/secure src/share src/sys src/tools src/ubin src/usbin
world/catpages world/games world/info world/proflibs

Does this look reasonable (y/n)? y

Fetching metadata signature for 6.3-RELEASE from update1.FreeBSD.org... done.
Fetching metadata index... done.
Fetching 1 metadata patches. done.
Applying metadata patches... done.
Fetching 1 metadata files... done.
Inspecting system...
done.
Preparing to download files... done.
Fetching 6150 patches.....10....20....30....40....50....60....70....80....90....100....110....120....130....140....150....160....170....180....190....200....210....220....230....240....250....260....270....280....290....300....310....320....330....340....350....360....370....380....390....400....410....420....430....440....450....460....470....480....490....500....510....520....530....540....550....560....570....580....590....600....610....620....630....640....650....660....670....680....690....700....710....720....730....740....750....760....770....780....790....800....810....820....830....840....850....860....870....880....890....900....910....920....930....940....950....960....970....980....990....1000....1010....1020....1030....1040....1050....1060....1070....1080....1090....1100....1110....1120....1130....1140....1150....1160....1170....1180....1190....1200....1210....1220....
.......
..
....
/bin/rcp
/bin/realpath
/bin/red
/bin/rm
/bin/rmail
/bin/rmdir
/bin/setfacl
/bin/sh

Install downloaded files:

# sh freebsd-update.sh -f freebsd-update.conf install

Output:


Installing updates...
Kernel updates have been installed. Please reboot and run
"freebsd-update.sh install" again to finish installing updates.

Reboot the box:

# reboot


Step #4: Install userland updates


You also need to upgrade other userland packages:

# sh freebsd-update.sh -f freebsd-update.conf install

Output:


Installing updates...

Again reboot the box, enter:

# reboot


Step #5: Verify updates


Make sure there are no error reported on console or log files:

$ uname -mrs

Output:


FreeBSD 6.3-RELEASE i386

Step #6: Update applications / port tree


Finally, you may need to upgrade running application such as php, apache, openssh and others. Simply use portsnap and portmanager commands to update all installed packages:

# portsnap fetch extract

# pkg_version -vIL=


Now upgrade installed ports:

# portmanager -u

OR

# portupgrade -a


References:


upgrade to 7.0

比較要注意的是 default thread library 從 libpthread 換成 libthr ,所以要記得重編一些 ports (簡單的方式就是把 /lib/libpthread.so.2 砍掉,然後會叫的 ports 就是要重練的)。其實去 ls /lib 下可以看到有些過期的,應該也要一併移除,減少 ldconfig 的負擔

How To Upgrade FreeBSD 6.3 to 7.0 Stable Release

A. FreeBSD 6.3 allows upgrade of existing installation to FreeBSD 7.0-RELEASE. Since this is a major version upgrade, it is recommended that you backup existing data, database and config files. You also need to reinstall all ports.


Step # 1: Upgrade ports


Type the following command, enter:

# portupgrade -faP


WARNING! This procedure might not work for you as upgrading system is complex procedure. This may result into data loos. Please backup all important data and configuration files before executing any commands. All instructions are tested on FreeBSD 6.3pX 32/64 bit computers.

Step # 2: Download updated freebsd-update-upgrade tool


Type the following command:

# fetch http://people.freebsd.org/~cperciva/freebsd-update-upgrade.tgz

# fetch http://people.freebsd.org/~cperciva/freebsd-update-upgrade.tgz.asc

# gpg --verify freebsd-update-upgrade.tgz.asc freebsd-update-upgrade.tgz

# tar -xf freebsd-update-upgrade.tgz


Step # 3: Start upgrade procedure


Type the following command to install new kernel and reboot the system, enter:

# sh freebsd-update.sh -f freebsd-update.conf -r 7.0-RELEASE upgrade

# sh freebsd-update.sh -f freebsd-update.conf install

# reboot


Step # 4: Install updated userland tools


Install the new userland components, after which all ports should be recompiled to link to new libraries:

# sh freebsd-update.sh -f freebsd-update.conf install

# portupgrade -faP


Step # 5: Remove all old libraries


Finally, freebsd-update.sh needs to be run one last time to remove old system libraries, after which the system should be rebooted in order that the updated userland and ports will be running:

# sh freebsd-update.sh -f freebsd-update.conf install

# reboot


Step # 6: Verify FreeBSD 7.0


Run following command to verify that everything is running smoothly, enter:

# uname -a

# tail -f /var/log/messages

# tail -f /path/to/other/log/files

# egrep -i 'errorwarning' /path/to/log/files

# sockstat -4 -l


References:


2008年5月3日 星期六

MySQL Server 安裝使用手冊

MySQL安裝使用手冊
一、概述:  
MySQL為一個多使用者、多執行緒及多站台的快速反應資料庫系統,系統主要著眼於快速與多使用者,最大的好處是用於教育用途,免費使用。
  它具有多種版本,從Unix到Windows 98(或NT)都有,很適合於一般教育界來使用開發一些資庫料的整合應用,把它當成後端資料庫系統,一個不錯的選擇。 二、資源:
作業環境:
RedHat 6.0 + CLE 0.8p1
原始出處:
http://www.mysql.net/
台灣Mirror站:http://mysql.ht.net.tw/
版本:
MySQL-3.22.27中文修正版
檔案來源:
ftp://sql.hmes.kh.edu.tw/pub/apache_php3_mysql/mysql-3.22.27/ 或
Mirror站 ftp://ftp.linuxer.nu/Linux/apache_php_mysql/rpms/mysql-3.22.27/ 或
Mirror站 http://linux.mcic.thu.edu.tw/download/pub/packages/apache+php+mysql/
檔案列表: -rw-r--r-- 1 root ftp 4693686 Nov 27 00:59 MySQL-3.22.27-2c.i386.rpm
-rw-r--r-- 1 root ftp 4041769 Nov 27 00:59 MySQL-3.22.27-2c.src.rpm
-rw-r--r-- 1 root ftp 541043 Nov 27 00:59 MySQL-bench-3.22.27-2c.i386.rpm
-rw-r--r-- 1 root ftp 2050704 Nov 27 00:59 MySQL-client-3.22.27-2c.i386.rpm
-rw-r--r-- 1 root ftp 601871 Nov 27 00:59 MySQL-devel-3.22.27-2c.i386.rpm
 
網路資源:
PHP-Zend Resources Center - 技術與資源交流中心 MySQL交流討論區
瑞琦資訊工作室 MySQL交流討論區
linux.twbbs.org BBS站 MySQL版
三、安裝:
以 root 身份登入 Redhat 系統。
到「檔案來源」的其中一站下載上述五個檔案。
依序以 rpm -ivh 命令將所下載下來的檔案安裝入Redhat作業系統中。 [root@test /root]# rpm -ivh MySQL-3.22.27-2c.i386.rpm
[root@test /root]# rpm -ivh MySQL-client-3.22.27-2c.i386.rpm
[root@test /root]# rpm -ivh MySQL-devel-3.22.27-2c.i386.rpm

若您需要重新Compiler,則只要安裝 MySQL-3.22.27-2c.src.rpm 套件即可。
以 root 身份登入 Redhat 系統後,進入MySQL資料庫系統。 [root@test /root]# mysql mysql
 
若安裝成功您可看到下列畫面,並看到mysql的提示號! Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 212 to server version: 3.22.27 Type 'help' for help.
mysql>

 
更改MySQL系統之管理者密碼(新密碼的地方,換成您要設定的密碼) mysql> UPDATE user SET password=password('新密碼') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
 
刪除空帳號,以維護系統安全 mysql> DELETE FROM user WHERE User = '';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
(最後是兩個單引號)
即時更新上述修正之資料 mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
 
離開MySQL資料庫系統 mysql> exit
Bye
[root@test root]#
 
測試一下剛剛更新的密碼是否正常:
[root@test root]# mysql mysql -uroot -p新密碼
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29 to server version: 3.22.27 Type 'help' for help.
mysql> exit
Bye
[root@test root]#

說明:(1)mysql mysql為連結MySQL資料庫,資料庫名稱為mysql。
   (2)-uroot:-u宣告使用者,root為使用者名稱。
   (3)-p新密碼:-p宣告密碼,後面接root新設的密碼。
以後進入使用MySQL資料庫系統,須以下列格式進入: [root@test root]# mysql 資料庫名稱 -u使用者名稱 -p密碼
說明:[-u使用者名稱]-u和使用者名稱間不可有空格。
   [-p密碼]-p和密碼間不可有空格。
四、mysqladmin公用程式的使用:
新增資料庫: [root@test root]# mysqladmin -uroot -p密碼 create 資料庫名稱
說明:用法與mysql一樣,-u緊接MySQL管理者帳號(通常為root),-p緊接管理者密碼(通常為root之密碼)
   資料庫名稱為您要新增的DataBase的名稱。
刪除資料庫: [root@test root]# mysqladmin -uroot -p密碼 drop 資料庫名稱
說明:用法與上述新增資料庫方式一樣。
關閉MySQL服務: [root@test root]# mysqladmin -uroot -p密碼 shutdown

五、基本用法:
增加新的MySQL使用者:(方法一)
(1)開啟mysql資料庫 [root@test root]# mysql mysql -uroot -p密碼
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29 to server version: 3.22.27 Type 'help' for help.
mysql>

 
(2)增加一個新帳號,並設定權限 mysql> insert into user values ('host','user',password('密碼'),'y','y','y','y','y','y','y','y','y','y','y','y','y','y');
說明:host->填入您要連線的主機名稱(完整名稱hostname+domainname),若位於本機則填localhost。
   user-->您要設定的帳號
   密碼-->您要設定的密碼
   之後14個y代表著14個不同的權限,依序為
1.Select_priv 2.Insert_priv 3.Update_priv 4.Delete_priv 5.Index_priv
6.Alter_priv 7.Create_priv 8.Drop_priv 9.Grant_priv 10.References_priv
11.Reload_priv 12.Shutdown_priv 13.Process_priv 14.File_priv

   若您不開放權限,則在該項目下填n即可。
 
增加新的MySQL使用者:(方法二)(較安全)
格式: mysql> GRANT 權限 ON 資料庫(或資料表TABLE) TO user@host IDENTIFIED BY '密碼';
說明:權限授與共分三種:
對資料庫(DateBase)有十五種權限: ALL PRIVILEGES ALTER CREATE DELETE DROP
FILE INDEX INSERT PROCESS REFERENCES
RELOAD SELECT SHUTDOWN UPDATE USAGE
 
對資料表(Table)則只有八種權限: SELECT INSERT UPDATE DELETE CREATE
DROP INDEX ALTER
 
對資料欄(column)則只有三種權限: SELECT INSERT UPDATE

 
user@host表示法:表示來自host主機的user使用者。user為您欲連線MySQL的帳號,host則必須填上你連線來源的主機完整名稱(hostname.domianname);例如:我想要設定的帳號為coco,而且是從mail.hmes.kh.edu.tw這台主機連上來使用的,所以就寫成coco@mail.hmes.kh.edu.tw。若使用萬用字元,則必須加上括號,例如:('test%'@'%.hinet.net')==>表示從.hinet.net網域連上來的test開頭的帳號。  GRANT的特性:在MySQL資料庫,若找到相對應的entry則只作UPDATE,找不到才會CREATE一個新的帳號及權限。  權限設定建議:除了管理者外,其他user儘量避免設定全部權限全開。一般而言,只開SELECT、INSERT、UPDATE三項權限;進階的user則加開DELETE、CREAT、DROP、INDEX四項權限;其餘權限,能不開,則不開,以確保整個MySQL的安全性。 (1)新增帳號,並給予全部權限 mysql> GRANT ALL PRIVILEGES ON *.* TO user@host IDENTIFIED BY '密碼';
說明:將全部權限都設給從host連線上來的user這個人,並給定密碼為密碼。 (2)新增帳號,並指定某資料庫與特定權限給該帳號 mysql> GRANT SELECT,INSERT,UPDATE ON 資料庫名.* TO user@host IDENTIFIED BY '密碼';
說明:開放某資料庫給從host連線上來的user這個人,並給定密碼為密碼。


刪除使用者帳號與權限:
格式: mysql> REVOKE 權限 ON 資料庫(或資料表TABLE) TO user@host IDENTIFIED BY '密碼';
說明:命令與用法均與GRANT一樣,特性也一樣,但不做DELETE的動作,只是將權限關閉,真的要刪除時,須用到DELETE命令。
對MySQL直接下命令作任何動作,離開MySQL系統時,必須先做即時更新(FLUSH)再離開吧! mysql> FLUSH PRIVILEGES;
 
在作業系統中,檢查權限之命令: [root@test root]# mysqlaccess host user 資料庫名 -U root -P 密碼
說明:host->填入您要檢查的來源主機名稱(完整名稱hostname+domainname),若位於本機則填localhost。
   user-->您要檢查的帳號
   資料庫名-->填入您要檢查的資料庫名稱
   -U root-->-u後面填入MySQL管理者的帳號(通常設root)
   -P 密碼-->-p後面填入MySQL管理者的密碼
例如:我要檢查來自mail.hmes.kh.edu.tw這台機器的root帳號,對資料庫fm的權限為何?
   則在系統下輸入
[root@test root]# mysqlaccess mail.hmes.kh.edu.tw fm focalmail -U root -P nnyyjj
結果為 mysqlaccess Version 2.03, 27 Feb 1997
By RUG-AIV, by Yves Carlier (Yves.Carlier@rug.ac.be)
This software comes with ABSOLUTELY NO WARRANTY.
+++USING FULL WHERE CLAUSE+++
+++USING FULL WHERE CLAUSE+++
+++USING FULL WHERE CLAUSE+++ Access-rights
for USER 'fm', from HOST 'mail.hmes.kh.edu.tw', to DB 'focalmail'
+-----------------+---+ +-----------------+---+
| Select_priv | Y | | Shutdown_priv | Y |
| Insert_priv | Y | | Process_priv | Y |
| Update_priv | Y | | File_priv | Y |
| Delete_priv | Y | | Grant_priv | Y |
| Create_priv | Y | | References_priv | Y |
| Drop_priv | Y | | Index_priv | Y |
| Reload_priv | Y | | Alter_priv | Y |
+-----------------+---+ +-----------------+---+
NOTE: A password is required for user `fm' :-( The following rules are used:
db : 'No matching rule'
host : 'Not processed: host-field is not empty in db-table.'
user : '','fm','017186377a52afaf','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'' BUGs can be reported by email to Yves.Carlier@rug.ac.be
[root@test /root]#

snmp && mrtg

首先是修改 /etc/rc.conf,開機時會自動跑 bsnmpd:
bsnmpd_enable="YES"
第一次啟動時可以手動跑:
# /etc/rc.d/bsnmpd start
然後裝
# cd /usr/ports/net-mgmt/mrtg# make install clean
裝完後跑 cfgmaker 產生檔案:
# cfgmaker public@127.0.0.1 > mrtg.cfg
然後修改 mrtg.cfg 內的 WorkDir,最後產生 index.html:
# indexmaker mrtg.cfg > index.html
然後將 mrtg 指令放到 crontab

[轉錄]FreeBSD 產生 apache2 ssl 認證

已經產生好幾十次了, 從來沒記起來過, 每次都是翻 gentoo wiki 來看, 這次自己筆記一下.
$ sudo mkdir /usr/local/apache2/ssl.key
$ sudo mkdir /usr/local/apache2/ssl.crt
$ cd /usr/local/apache2/ssl.key
$ sudo openssl genrsa -des3 -out server.key 1024
$ sudo openssl genrsa -out server.key 1024
$ sudo openssl rsa -in server.key -out server.pem
$ sudo openssl req -new -key server.pem -out server.csr
$ sudo openssl x509 -req -days 365 -in server.csr -signkey server.pem -out server.crt
$ cd server.crt ../ssl.crt

其他 distribution 產生方式也差不多, 大致就是路徑不太一樣.

ericpi 發表在 PIXNET 痞客邦 迴響(0) 引用(0) 人氣(71)

2008年3月31日 星期一

Matlab version 2

These directions are for installing the Linux version of MATLAB 7.0 (R14) under Linux Binary Compatibility. I'll assume that you already have the install CDs, and a valid license.

Enabling Linux Binary Compatibility

The first thing we need to do is install linux binary compatibility. It's likely that you have it installed already. You can check with the following command:

pkg_info | grep linux_base
If you have it installed you will see a line similar to this:

linux_base-fc-4_9 Base set of packages needed in Linux mode (for i386/amd64)
If you have it installed please skip the next commands for installing it. Otherwise, run the following to install linux binary compatibility.


cd /usr/ports/emulators/linux_base-fc4
make install clean
Either way add the following line to /etc/rc.conf.

linux_load=YES
In order to start compatibility, use the following command:

kldload linux.ko
That will be run automatically everytime you boot with the line we added to rc.conf.

Now add the following line to /etc/fstab.

linprocfs /compat/linux/proc linprocfs rw 0 0
Now run the following two commands:

kldload linprocfs
mount /compat/linux/proc
From now on that will be done for you automatically.

Installing Matlab

Now we need to install linux-java. First you'll have to download the linux-java binary from Sun. Accept the license agreement, and download the file j2sdk-1_4_2_10-linux-i586.bin or its closest equivalent. Once downloaded, move the file to /usr/ports/distfiles/. Then we can install linux-java:

cd /usr/ports/java/linux-sun-jdk14
make install clean
Now we can move on to installing MATLAB. When you mount the cds you will have to mount them with executable permissions. Or you can follow my method of copying the contents of the cds to disk, and run the install from there. Either way will work, but I'll walk you through doing it the same way that I did.

cd /usr
mkdir mat mat2 mat3
Now copy all of the contents to those respective directories (mat for cd1, mat2 for cd2, etc).

cd /compat/linux/usr/
mkdir local
cd local
mkdir matlab
cd matlab
mkdir etc
cd etc
That was a slight pain. At this point you will want copy your prepared license.dat file to etc.

cp license.dat /compat/linux/usr/local/matlab/etc
Now that the license is prepared we're ready to begin the install.

cd /compat/linux/usr/local/matlab
/compat/linux/bin/sh /usr/mat/install
Modify that command if you are installing directly off of the cd. For the install itself you will want to take the default installation directory (the directory you are currently in). The rest of the installer is self explanatory. I'll assume the install was successful.

cd /compat/linux/usr/local/matlab/etc
ln -s lmboot /usr/local/etc/lmboot_TMW
ln -s lmdown /usr/local/etc/lmdown_TMW
We just made a few links for files that will be referenced in our license manager script. Now we'll get that script going.

cp rc.lm.glnx86 /usr/local/etc/rc.d/flexlm.sh
cd /usr/local/etc/rc.d/
chmod +x flexlm.sh
vi flexlm.sh
That will give us a good template for the file. We just need to edit a few paths. In the end your file should look like this:

#!/bin/sh
case "$1" in
start)
if [ -f /usr/local/etc/lmboot_TMW ]; then
/compat/linux/bin/sh /usr/local/etc/lmboot_TMW -u xaenn && echo 'MATLAB_lmgrd'
fi
;;
stop)
if [ -f /usr/local/etc/lmdown_TMW ]; then
/compat/linux/bin/sh /usr/local/etc/lmdown_TMW > /dev/null 2>&1
fi
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

exit 0
You will want to change xaenn to the appropriate username for your system.

/usr/local/etc/rc.d/flexlm.sh start
For the first time we need to start it manually, but it will happen at startup automatically from now on. Right now we could use MATLAB, but it's a bit cumbersome to invoke, so let's write a quick script.

vi ~/bin/matlab
Add the following lines:

#!/bin/sh
/compat/linux/bin/sh /compat/linux/usr/local/matlab/bin/matlab
As per the FreeBSD Handbook, depending on your version of emulators/linux_base, you may need to edit the matlab script.

vi /compat/linux/usr/local/matlab/bin/matlab
Edit the following line

if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then
and replace it with

if test -L $newbase; then
And one final note, sound support has been hit or miss for me. Sometimes it works, and other times it won't. As an alternative you may use the wavwrite function, and then play the output from mplayer. It's not ideal, but it works. Finally, you'll have something nice like this: