Openfire Install
------------------
xiaoyang @2012-4-13
环境:fedora16,linux3.2内核,mysql服务器
(1)openfire安装
默认安装在/opt/openfire目录下面。
xiaoyang@xiaoyang openfire$ sudo rpm -ivh openfire-3.7.1-1.i386.rpm
[sudo] password for xiaoyang:
Preparing... ########################################### [100%]
1:openfire ########################################### [100%]
若防火墙开启,则需要加入例外规则
xiaoyang@xiaoyang openfire$ vi /etc/sysconfig/iptables
追加2行
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9091 -j ACCEPT
启动openfire。
xiaoyang@xiaoyang openfire$ sudo /etc/init.d/openfire restart
[sudo] password for xiaoyang:
Shutting down openfire:
Starting openfire:
(2)mysql基本配置
数据库准备。我使用的是mysql.i686 VERSION:5.5.21-1.fc16
修改my.cfg数据库配置文件,在最后添加两行
[mysql] #xiaoyang add
default-character-set=utf8 #xiaoyang add
Fedora16默认没有启动,启动数据库。
xiaoyang@xiaoyang openfire$ service mysqld status
xiaoyang@xiaoyang openfire$ sudo service mysqld restart
xiaoyang@xiaoyang openfire$ service mysqld status
Redirecting to /bin/systemctl status mysqld.service
mysqld.service - MySQL database server
Loaded: loaded (/lib/systemd/system/mysqld.service; disabled)
Active: active (running) since Fri, 13 Apr 2012 13:08:42 +0800; 9s ago
Process: 5861 ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 5722 ExecStart=/usr/bin/mysqld_safe --nowatch --basedir=/usr (code=exited, status=0/SUCCESS)
Process: 5654 ExecStartPre=/usr/libexec/mysqld-prepare-db-dir (code=exited, status=0/SUCCESS)
Main PID: 5860 (mysqld)
CGroup: name=systemd:/system/mysqld.service
└ 5860 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysqld.log --pid-file...
看到active就行了。
检测mysql开放端口,默认是3306.
xiaoyang@xiaoyang openfire$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
输入密码后进入mysql:
xiaoyang@xiaoyang openfire$ mysql -u root -p
创建测试用户:
mysql> insert into mysql.user(Host,User,Password) values("localhost","user1",password("user1"));
mysql> flush privileges;
新安装的MySQL是默认不开户远程访问权限的,也就不能外部连接MySQL。这样对想远程调用MySQL的数据很不方便。下面我们来看下如何设置允许远程连接MySQL数据库。
登录MySQL
mysql -uroot -p
如果无法登录可以使用find / -name mysql搜索mysql程序的路径,比如mysql程序路径为:/usr/local/mysql/bin/mysql,我们可以这样登录:
/usr/local/mysql/bin/mysql -uroot -p
执行如下命令:
grant all privileges on *.* to 'root'@'%' identified by 'ROOT-PASSWORD';
flush privileges;
exit
(3)
mysql for openfire
创建opefire数据库
mysql> create database openfire;
Query OK, 1 row affected (0.00 sec)
套用openfire的数据库模板
xiaoyang@xiaoyang ~$ vim /opt/openfire/resources/database/openfire_mysql.sql
xiaoyang@xiaoyang ~$ sudo mysql -u root < /opt/openfire/resources/database/openfire_mysql.sql -p
重启openfire
xiaoyang@xiaoyang ~$ sudo /etc/init.d/openfire restart
Shutting down openfire:
Starting openfire:
xiaoyang@xiaoyang ~$
(4)
配置openfire。
浏览器打开 http://[本机IP]:9090/setup/index.jsp
a)首先选择语言,中文
b)其次配置域ip和控制台端口,端口默认是9090
c)然后选择数据库连接,
使用标准数据库连接”是连接外部MySQL数据
注意如果出现错误,error.log显示:
Access denied for user 'root'@'192.168.1.3' (using password:YES)
错误,请查看自己的mysql user表。
mysql> use user
ERROR 1049 (42000): Unknown database 'user'
mysql> insert into user (host,user) values ('xiaoyang.hit.edu.cn','root');
ERROR 1062 (23000): Duplicate entry 'xiaoyang.hit.edu.cn-root' for key 'PRIMARY'
mysql> select host,user from user;
+---------------------+-------+
| host | user |
+---------------------+-------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| localhost | user1 |
| xiaoyang.hit.edu.cn | |
| xiaoyang.hit.edu.cn | root |
+---------------------+-------+
8 rows in set (0.00 sec)
如在本地,我的user表中root密码为'%',填写密码时空白即可。
d)进入“标准数据连接”配置页面,配置MySQL连接;配置后会在外部数据库中创建表和字段;
e)进入用户和组配置界面,
“初始配置”既在数据库中保存用户和用户组资料
“目录服务器(LDAP)”就是使用外部LDAP服务器来管理
f) 进入管理员密码配置界面,修改管理员密码;
g)配置完毕,进入“管理控制台”,额外添加一个管理员帐号;默认登录名是admin,密码就是上一步填写的密码。可以在openfire数据库的ofUser表中自己加用户。
至此,可以看到openfire 服务器console了。
下面可以使用smack插件进行一个简单的测试。
package cn.edu.hit; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; public class SmackTest { public static void main(String[] args) throws XMPPException { // 5222是openfire通信的端口 ConnectionConfiguration config = new ConnectionConfiguration( "127.0.0.1", 5222); XMPPConnection connection = new XMPPConnection(config); XMPPConnection.DEBUG_ENABLED = true; connection.connect(); connection.login("user1", "user1"); connection.addPacketListener(new PacketListener() { @Override public void processPacket(Packet arg0) { System.out.println(arg0); } }, new PacketFilter() { @Override public boolean accept(Packet arg0) { return true; } }); IQ iq = new IQ() { @Override public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append(""); return buf.toString(); } }; connection.sendPacket(iq); connection.disconnect(); System.out.println("exit!\n"); System.exit(0); } }
运行完毕可以在控制台中的用户界面看到 登录记录。