How to Release Port 8888 on OEL5.5

准备在OEL5.5中安装Oracle VM Manager,文档中说明要保证8888端口可用。

# netstat -na |grep 8888
unix  3      [ ]         STREAM     CONNECTED     8888 

说明该端口已经被占用,那么如何释放该端口?

通过lsof命令可以看到该端口被avahi-daemon程序占用。avahi-daemon的主页可以参看avahi.org

# lsof | grep 8888
avahi-dae 2747     avahi   12u     unix 0xeb4d9740                8888 socket

检查自动启动的服务,发现avahi-daemon是自动启动的。

# chkconfig --list | grep avahi
avahi-daemon   	0:off	1:off	2:off	3:on	4:on	5:on	6:off
avahi-dnsconfd 	0:off	1:off	2:off	3:off	4:off	5:off	6:off

停止avahi-daemon,需要使用avahi-daemon脚本停止。

# service avahi-daemon off
Usage: /etc/init.d/avahi-daemon {start|stop|status|restart|condrestart}
# /etc/init.d/avahi-daemon stop
Shutting down Avahi daemon:                                [  OK  ]

设置avahi-daemon不再随着机器重启而自动启动。

# chkconfig avahi-daemon off

再次检查,端口已经释放。

# netstat -na |grep 8888

How to use Oracle Instant Client in Mac OS X Lion

升级到Mac OS X Lion以后,原先在Snow Leopard下运行正常的Oracle 10.2.0.4 64bit将无法正常工作,无论执行什么命令(比如sqlplus或者lsnrctl)都会报如下错误。

$ sqlplus
Segmentation fault: 11

在OTN Forum中有此问题的讨论,但是目前为止还没有任何可用的解决方案。Oracle对于Mac的支持一向很弱,而OS X最近的这次升级一定是更改了很多库文件,导致64bit的Oracle数据库/64bit的Oracle Instant Client均无法在OS X Lion中正常运行。

对于Oracle数据库而言,只有for MAC OS X on Intel x86-64版本存在,但是对于Oracle Instant Client却有32bit版本下载,因此如果急于在Mac OS X Lion中使用sqlplus的,可以先安装32bit版本。

安装和设置方法:
1. 从以下链接下载Instant Client for Mac OS X。
http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
下载Version 10.2.0.4 (32-bit) 中的:
instantclient-basic-10.2.0.4.0-macosx-x86.zip
instantclient-sqlplus-10.2.0.4.0-macosx-x86.zip

2. 将两个zip文件都解压到一个文件夹中,比如文件夹名为instantclient,我将此文件夹转移到到/Applications/Utilities/下,在你的环境中,任何路径都可以。

3. 修改Mac用户的环境变量,直接修改User Home下的.bash_profile文件,添加如下行,其中的路径替换为你环境中的instantclient路径。

export DYLD_LIBRARY_PATH=/Applications/Utilities/instantclient/
export ORACLE_HOME=/Applications/Utilities/instantclient/
export SQLPATH=ORACLE_HOME
export PATH=PATH:/Applications/Utilities/instantclient/:.

4. 手动创建tns_admin目录,以及tnsnames.ora文件,其中的内容自己写。

mkdir -p ORACLE_HOME/network/admin
viORACLE_HOME/network/admin/tnsnames.ora

在我的环境中,用instantclient连接VirtualBox中的11gR2数据库。

localhost:~ Kamus$ sqlplus kamus@vbox-orcl-oel5

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jul 30 12:09:35 2011

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Enter password: 

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, Oracle Label Security and Real Application Testing options

SQL> 

备注:关于glogin.sql
默认解压完的instantclient-sqlplus-10.2.0.4.0-macosx-x86.zip是不包含目录结构的,因此glogin.sql在sqlplus执行的时候无法被正确调用,导致的结果就是比如show parameter命令的格式非常难看。因此需要手动做如下操作:
1. 创建bin目录,将sqlplus可执行文件mv到该目录中
2. 创建sqlplus/admin目录,将glogin.sql文件mv到该目录中
3. 修改用户.bash_profile文件,将instantclient/bin添加到PATH环境变量中

Open Terminal in Current Folder & Create New Text in Current Folder by AppleScript

如下图所示,在Finder的toolbar中最后有两个自定义的图标,第一个是iTerm2图标,点击该图标会在Finder当前目录中打开iTerm2程序,第二个是TextWrangler图标,点击该图标会在Finder当前目录中用TextWrangler创建一个新文本文件,文件名为当前日期时间。
Finder

我们使用AppleScript来完成这两项工作。

1. 打开AppleScript Editor

2. 将后文给出的两段脚本copy到AppleScript Editor中,分别保存为两个Application。也就是在Save as的时候选择File format为“Application”(默认为Script)。
保存位置随意,我保存在/Applications目录下。比如第一个脚本保存为“Open iTerm2 Here”,第二个脚本保存为“New Text Here”。

3. 修改新建Application的图标,在Mac中复制粘贴的强大在这里体现了。
以“New Text Here”为例,在Finder中同时选中“New Text Here”和TextWrangler这两个程序,Cmd+I快捷键调出属性窗口,在TextWrangler的属性窗口中鼠标点击最上面的小图标(如下图),按Cmd+C复制,然后鼠标点击“New Text Here”属性窗口中最上面的小图标(原本是AppleScript的默认图标),按Cmd+V粘贴。
Copy Icon

4. 将修改完图标的两个App拖动到Finder顶端的Toolbar中,完成。

AppleScript:
–Open iTerm2 Here
–这里我使用的是iTerm2,你可以改成自己习惯的Terminal程序,比如iTerm,那么只需要将以下脚本中的tell application “iTerm2″改为tell application “iTerm”即可。

-- cd to the current finder window folder in iTerm2. Or drag a folder onto this script to cd to that folder in iTerm2.
-- found this script in the comments of this article: http://www.macosxhints.com/article.php?story=20050924210643297
-- script was opened by click in toolbar
on run
	tell application "Finder"
		try
			set currFolder to (folder of the front window as alias)
		on error
			set currFolder to (path to desktop folder as alias)
		end try
	end tell
	CD_to(currFolder, false)
end run

-- script run by draging file/folder to icon
on open (theList)
	set newWindow to false
	repeat with thePath in theList
		set thePath to thePath as string
		if not (thePath ends with ":") then
			set x to the offset of ":" in (the reverse of every character of thePath) as string
			set thePath to (characters 1 thru -(x) of thePath) as string
		end if
		CD_to(thePath, newWindow)
		set newWindow to true -- create window for any other files/folders
	end repeat
	return
end open

-- cd to the desired directory in iterm2
on CD_to(theDir, newWindow)
	set theDir to quoted form of POSIX path of theDir as string
	tell application "iTerm2"
		activate
		delay 1
		-- talk to the first terminal 
		tell the first terminal
			try
				-- launch a default shell in a new tab in the same terminal 
				launch session "Default Session"
			on error
				display dialog "There was an error creating a new tab in iTerm2." buttons {"OK"}
			end try
			tell the last session
				try
					-- cd to the finder window
					write text "cd " & theDir
				on error
					display dialog "There was an error cding to the finder window." buttons {"OK"}
				end try
			end tell
		end tell
	end tell
end CD_to

–New Text Here
–这里我使用的是/usr/local/bin/edit来直接创建新文档,此命令在安装完TextWrangler之后才会有,如果你使用其它的文本编辑器(比如系统自带的TextEdit),那么可能无法使用该脚本。
–该脚本中获取当前日期时间拼成文件名的实现方法有些丑陋,如果你有更好的方法请告诉我。

-- Create new text file in Finder's Current Folder
-- 2011.7.1 Written by Kamus

-- script was opened by click in toolbar
on run
	tell application "Finder"
		try
			set currFolder to (folder of the front window as alias)
		on error
			set currFolder to (path to desktop folder as alias)
		end try
	end tell
	create_text_file(currFolder)
end run

-- cd to the desired directory in iterm
on create_text_file(theDir)
	set theDir to quoted form of POSIX path of theDir as string
	set yearStr to year of (current date) as integer
	set monthStr to month of (current date) as integer
	set dayStr to day of (current date) as integer
	set timeStr to time of (current date) as integer
	
	try
		do shell script "/usr/local/bin/edit " & theDir & yearStr & monthStr & dayStr & timeStr & ".txt"
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end create_text_file