公司想在內網服務器上搞個IM系統,是linux系統上的,所以挑選了Jabber作為IM server,把安裝過程總結了一下,寫出來,以備以后使用。
安裝是參考Jabber自帶的原文檔進行的,我只是把具體步驟挑出來而已。
操作系統:Redhat AS 3 U2
安裝Jabber2(jabberd-2.0s8.tar.gz)
Jabber2可以在www.jabber.org下載到,用來做IM Server。
客戶端我用了好幾種,個人推薦Pandion、Psi、Gaim,都是Windows平臺的Client,都支持中文。而且Psi和Gaim我都下到了源碼,可以進行二次開發。
安裝Jabber本身很簡單,主要是安裝Jabber的必需的軟件包。
Jabber需要:OpenSSL(0.9.6b以上版本)
Libidn(0.3.0以上版本)
數據存儲:Mysql(4.0以上版本)或者Berkeley DB (4.1.24 以上)、PostgreSQL
身份驗證軟件包(Mysql就可以)
Jabber官方推薦使用Mysql,這樣數據存儲和身份認證就用一個就可以了。
Libidn一般在安裝Linux的時候都不會自帶的,所以要單獨下載安裝,可以在http://www.gnu.org/software/libidn/找到(我用的是libidn-0.5.0.tar.gz)。
OpenSSL一般安裝盤中都有,如果裝系統的時候已經選了,就不用了,要是沒有,需要從安裝盤中把rpm包找到安裝(裝的時候可能需要其他包,也一并裝了吧),OpenSSL裝的話,一定要包含兩個包:openssl和openssl-devel。
Mysql不要用Linux自帶的(官方推薦),需要好幾種包,包括Server、client、Libraries and Header、Dynamic Client Libraries。具體的rpm包是(版本自己決定,4.0以上即可):
MySQL-client-4.0.24-0.i386.rpm
MySQL-server-4.0.24-0.i386.rpm
MySQL-devel-4.0.24-0.i386.rpm
MySQL-shared-4.0.24-0.i386.rpm
將需要的包準備好,比如拷貝到一個目錄下,比如/usr/local/src下
開始安裝:(省去裝OpenSSL)
root身份:
先裝libidn:
# tar -zxvf libidn-0.5.0.tar.gz
# cd libidn-0.5.0
# ./configure --prefix=/usr
# make
# make install (這一步必須用root權限執行)
再裝Mysql(用RPM包裝):
# rpm -ivh MySQL-server-4.0.24-0.i386.rpm
記住默認的Mysql的root密碼:PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h oaserver.oa password 'new-password'
See the manual for more instructions
# rpm -ivh MySQL-devel-4.0.24-0.i386.rpm
# rpm -ivh MySQL-shared-4.0.24-0.i386.rpm
# rpm -ivh MySQL-client-4.0.24-0.i386.rpm
系統會自動建立mysql用戶。
確認Mysql以及啟動,然后更改root密碼,后面輸入新密碼:
# /usr/bin/mysqladmin -u root password 'imadmin'
# mysql -u root -p
輸入新密碼,就登錄進mysql數據庫,測試:
mysql> show databases; (顯示結果為)
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)
OK!說明Mysql安裝成功。
裝Jabber:
# groupadd jabber
# useradd -g jabber jabber
# passwd jabber
輸入jabber用戶的密碼,以后啟動jabber服務就用jabber用戶就可以了
# mkdir -p /usr/local/var/jabberd/pid/
# chown -R jabber:jabber /usr/local/var/jabberd/pid/
# mkdir -p /usr/local/var/jabberd/log/
# chown -R jabber:jabber /usr/local/var/jabberd/log
到jabber包所在路徑執行:
# tar -zxvf jabberd-2.0s8.tar.gz
# cd jabberd-2.0s8
# export CFLAGS="-I/usr/kerberos/include"
# ./configure
# make
# make install
安裝成功,默認安裝路徑是/usr/local,要更換安裝路徑,在configure的時候加參數,具體參數,參考Jabber自己的安裝文檔。Jabber的文檔放在/usr/local/etc/jabberd下面,可執行文件放在/usr/local/bin下。
# chown -R root:jabber /usr/local/etc/jabberd/*
# chmod -R 640 /usr/local/etc/jabberd/*
這樣Jabber的配置文件就只有jabber和root用戶可以讀寫了,這步也可以不做。
# ln -s /usr/local/etc/jabberd/ /etc/jabberd (建立鏈接方便訪問)
基本配置:
1.設置host name:
# cd /etc/jabberd/
# vi sm.xml
In sm.xml :
<!-- Session manager configuration -->
<sm>
<!-- Our ID on the.network. Users will have this as the domain part of
their JID. If you want your server to be aclearcase/" target="_blank" >ccessible from other
Jabber servers, this ID must be resolvable by DNS.s
(default: localhost) -->
<id>localhost</id>
默認是localhost,我是用ip,也可以用somemachine.somedomain.com的格式,但是那先有域名解析。
保存退出。
vi c2s.xml
In c2s.xml :
<!-- Local network configuration -->
<local>
<!-- Who we identify ourselves as. This should correspond to the
ID (host) that the session manager thinks it is. You can
specify more than one to support virtual hosts, as long as you
have additional session manager instances on the network to
handle those hosts. The realm attribute specifies the auth/reg
or SASL authentication realm for the host. If the attribute is
not specified, the realm will be selected by the SASL
mechanism, or will be the same as the ID itself. Be aware that
users are assigned to a realm, not a host, so two hosts in the
same realm will have the same users.
If no realm is specified, it will be set to be the same as the
ID. -->
<id>localhost</id>
也替換成ip,保存退出。
2.配置Mysql:
到Jabber的源代碼路徑下的tools目錄下,有mysql的建庫sql文件,執行db-setup.mysql可以在mysql下建立對應的用戶和表。
# cd /usr/local/src/jabberd-2.0s8/tools/
# mysql -u root -p (輸入mysql的root密碼)
mysql>\. db-setup.mysql
mysql> grant select,insert,delete,update On jabberd2.* to jabberd2@localhost IDENTIFIED by 'secret';
給jabberd在mysql的密碼就賦值為"secret",也可以自己指定密碼
執行完畢退出。
# mysql -u jabberd2 -p來測試密碼是否正確。
mysql的socket在/var/lib/mysql下面,jabberd2需要用到它,所以:
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
3.在jabber中指定mysql的配置:
# cd /etc/jabberd/
# vi sm.xml
數據庫關于數據庫的配置,使用mysql的有兩段:
<!-- Storage database configuration -->
<storage>
<!-- By default, we use the MySQL driver for all storage -->
<driver>mysql</driver>
以及
<!-- MySQL driver configuration -->
<mysql>
<!-- Database server host and port -->
<host>localhost</host>
<port>3306</port>
<!-- Database name -->
<dbname>jabberd2</dbname>
<!-- Database username and password -->
<user>jabberd2</user>
<pass>secret</pass>
<!-- Transacation support. If this is commented out, transactions
will be disabled. This might make database accesses faster,
but data may be lost if jabberd crashes.
This will need to be disabled if you are using a MySQL
earlier than v3.23.xx, as transaction support did not appear
until this version. -->
<transactions/>
</mysql>
系統以及默認好了,除非你在前面改動了密碼什么的,才需要更改這段配置,或者想換個端口。
Jabber推薦使用mysql,用它做數據存儲和身份認證,身份認證需要更改c2s.xml
# vi c2s.xml
<!-- MySQL module configuration -->
<mysql>
<!-- Database server host and port -->
<host>localhost</host>
<port>3306</port>
<!-- Database name -->
<dbname>jabberd2</dbname>
<!-- Database username and password -->
<user>jabberd2</user>
<pass>secret</pass>
</mysql>
系統也已經默認好了。
前面建立了jabber自己的log目錄,這樣就不用加到系統日志里面了,所以要更改sm.xml和c2s.xml。
sm.xml:
<!-- Log configuration - type is "syslog", "file" or "stdout" -->
<log type='file'>
<!-- If logging to syslog, this is the log ident -->
<ident>jabberd/sm</ident>
<!-- If logging to syslog, this is the log facility
(local0 - local7) [default: local3] -->
<facility>local3</facility>
<!-- If logging to file, this is the filename of the logfile -->
<file>/usr/local/var/jabberd/log/sm.log</file>
</log>
系統默認log type是"syslog",改成"file",然后把下面的file的具體路徑的配置取消注釋就可以了。
對應的,c2s.xml,s2s.xml,router.xml,resolver.xml也是同樣改法。
這樣基本配置就完成了,可以測試了。
測試Jabber服務:
# su - jabber
$ jabberd
Ok,這樣就啟動了jabber服務,關閉直接Ctrl+C就行了。
現在用客戶端注冊一個新用戶,然后登錄,需要注意的是注冊是要輸入JabberID,要加@192.168.0.24
包括增加聯系人的時候也是要加上。
這樣就建立一個簡單廉價的IM Server了。
如果啟動jabber時系統報LANG,LANGUAGE,LC_ALL的錯誤,主要是因為redhat默認安裝后,系統unset了LC_ALL,還有因為其他原因更改了LANG變量的設置等,所以可以在jabber用戶下重新賦值:
# su - jabber
$ vi .bash_profile
在里面加入:
export LANG=en_US
export LANGUAGE=$LANG
export LC_ALL=$LANGUAGE
具體指定什么語言,根據實際定吧。
如果想建立自啟動腳本,我做了一個簡單的腳本,我用的還湊合:
#!/bin/sh
#/etc/rc.d/init.d/jabberd
#
# Description: Starts and stops the jabberd services as jabber user .
#
#Date 2005/06/09
# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi
# Jabberd services must be run by jabber user
KIND="Jabberd"
RETVAL=0
start() {
echo -n $"Starting $KIND services: "
echo "----------------------------------------------------" >> /usr/local/var/jabberd/log/jabberd.log
date +"! %T %a %D : Starting Jabberd as part of system up." >> /usr/local/var/jabberd/log/jabberd.log
echo "----------------------------------------------------" >> /usr/local/var/jabberd/log/jabberd.log
su - jabber -c jabberd & >> /usr/local/var/jabberd/log/jabberd.log
echo "Done."
RETVAL=$?
echo "-----------------------" >> /usr/local/var/jabberd/log/jabberd.log
date +"! %T %a %D : Finished." >> /usr/local/var/jabberd/log/jabberd.log
echo "-----------------------" >> /usr/local/var/jabberd/log/jabberd.log
echo
return $RETVAL
}
stop() {
echo -n $"Shutting Down $KIND services: "
echo "-----------------------------------------------------------" >> /usr/local/var/jabberd/log/jabberd.log
date +"! %T %a %D : Shutting Down Jabberd as part of system down." >> /usr/local/var/jabberd/log/jabberd.log
echo "-----------------------------------------------------------" >> /usr/local/var/jabberd/log/jabberd.log
killall s2s >> /usr/local/var/jabberd/log/jabberd.log
killall c2s >> /usr/local/var/jabberd/log/jabberd.log
killall sm >> /usr/local/var/jabberd/log/jabberd.log
killall resolver >> /usr/local/var/jabberd/log/jabberd.log
killall router >> /usr/local/var/jabberd/log/jabberd.log
echo "Done."
RETVAL=$?
echo "-----------------------" >> /usr/local/var/jabberd/log/jabberd.log
date +"! %T %a %D : Finished." >> /usr/local/var/jabberd/log/jabberd.log
echo "-----------------------" >> /usr/local/var/jabberd/log/jabberd.log
echo
return $RETVAL
}
restart() {
stop
start
}
case "" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: "
exit 1
esac
exit $?
這個腳本我起名叫jabberd,放在init.d下面,root權限,然后:
# ln -s /etc/rc.d/init.d/jabberd /etc/rc.d/rc3.d/S99jabberd
# ln -s /etc/rc.d/init.d/jabberd /etc/rc.d/rc5.d/S99jabberd
# ln -s /etc/rc.d/init.d/jabberd /etc/rc.d/rc6.d/K01jabberd
# ln -s /etc/rc.d/init.d/jabberd /etc/rc.d/rc0.d/K01jabberd
這樣計算機啟動和關閉的時候就自動關閉和啟動了,如果手工想關閉重啟什么的時候,直接執行:
# /etc/rc.d/init.d/jabberd (start|stop|restart)
這個文件是用txt文本格式寫的,不能直接把腳本內容拷貝成sh文件,用寫字板或者Ultraedit什么的重寫吧,否則換行符是跟linux不一樣的。
我這些操作是在redhatAS3 U2版本上做的,其他版本應該基本一樣,可能在細節部分略有區別吧,反正我沒有測試過。