xmpp openfire linux 安装 im 及时通讯服务器

 

xmpp openfire linux  安装 im 及时通讯服务器

 

技术栈: openfire+smack+spark

 

Smack是一个开源,易于使用的XMPP客户端类库。Smack API, 是一个 Java 的XMPP Client Library,也是由Jive Software开发。 优点:编程简单。 缺点:API并非为大量并发用户设计,每个客户要1个线程,占用资源大,1台机器只能模拟有限(数千个)客户。Smack是一个用 java 写的XMPP客户端代码库, 是 spark 的核心。

 

smack demo android :https://github.com/mini188/SmackDemo 

 

spark  非大数据 spark ,类似 fetion 飞信的客户端

 

 

 

1.安装 java

 

jdk-7u79-linux-x64.tar.gz
tar xf jdk-7u79-linux-x64.tar.gz
vim /etc/profile

export JAVA_HOME=/usr/java/jdk1.7.0_79
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
source /etc/profile

java -version

 

 

2.mysql 安装

 

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
yum install -y mysql-community-server
systemctl start mysqld.service
grep 'temporary password' /var/log/mysqld.log  看见密码 
【 Your password does not satisfy the current policy requirements】
set global validate_password_policy=0;
【Your password does not satisfy the current policy requirements】
select @@validate_password_length;
set global validate_password_policy=0
SET PASSWORD = PASSWORD('66666666');
use mysql
update user set host='%' where user='root' and host='localhost';
flush privileges; 
exit

firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
firewall-cmd --list-all

mysql -uroot -p66666666
create database openfire;
use openfire ;
source openfire_mysql.sql
update grant all on openfire.* to admin@"%" identified by '66666666'
flush privileges;
exit

 

 

3.openfire 安装

tar xf openfire_3_8_2.tar.gz
cp openfire_3_8_2 /home/baoyou/soft/openfire_3_8_2

bin/openfire start

firewall-cmd --permanent --add-port=9090/tcp
firewall-cmd --permanent --add-port=9091/tcp
firewall-cmd --reload
firewall-cmd --list-all

 

4.访问地址

访问 openfire
http://192.168.206.237:9090/

 

5.安装步骤



 



 

 

 

 

 

 

 

 spark 



 

 

 

6. openfire 数据库结构



  

 

 

 7.java  測試

 

              <!-- smack start -->
		<dependency>
			<groupId>jivesoftware</groupId>
			<artifactId>smack</artifactId>
			<version>3.1.0</version>
		</dependency> 
		<!-- smack end -->

 

 

package com.baoy.cn.smack;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
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.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;

/**
 * 
 * @author baoy
 *
 */
public class SmackTest {
	
    public static XMPPConnection con;
    public static Chat newChat;
    public static ChatManager chatmanager;

    public static void main(String[] args) throws InterruptedException {
        try {
            // 配置域和端口号,域可以换成IP地址
            ConnectionConfiguration config = new ConnectionConfiguration(
                    "www.baoyou.com", 5222);
            // 新建一个XMPPConnection对象
            con = new XMPPConnection(config);

            // 连接服务器
            con.connect();
            // 用户登录
            con.login("1223716098", "111111");
            // 是否已经通过身份验证
            System.out.println("Authenticated = " + con.isAuthenticated());

            addListener();
            // 获取一个ChatManager对象
            chatmanager = con.getChatManager();
            newChat = chatmanager.createChat("[email protected]",
                    new MessageListener() {
                        public void processMessage(Chat chat, Message message) {
                            System.out.println("I'm sending: "  + message.getBody());
                        }
                    });
            newChat.sendMessage("hi");
        } catch (XMPPException e) {
            e.printStackTrace();
        } finally {
            // 让线程休眠 然后再关闭连接
            Thread.sleep(20000000);
            con.disconnect();
        }
    }

    private static void addListener() {
        // 包的过滤器
        PacketFilter filterMessage = new PacketTypeFilter(Message.class);
        // 创建包的监听器
        PacketListener myListener = new PacketListener() {
            public void processPacket(Packet packet) {
                // 以XML格式输出接收到的消息
                System.out.println(packet.toXML());
                System.out.println("From: " + packet.getFrom() + "\n");
                System.out.println("Body: " + ((Message) packet).getBody());

                try {
                    // 尝试发送消息给服务器
                    newChat.sendMessage("hi again");
                } catch (XMPPException e) {
                    e.printStackTrace();
                }
            }
        };
        // 给连接注册一个包的监听器
        con.addPacketListener(myListener, filterMessage);
    }
}

 

 

 8.openfire web  向所有用户发送 



 
9.日志显示



 
 

 10.注意

1. host  改为域名  

linux

vim /etc/hosts  

192.168.206.237 www.baoyou.com

windows

C:\WINDOWS\system32\drivers\etc\hosts

 192.168.206.237 www.baoyou.com

 

 2. JID  为  用户名@域名

eg: [email protected]

 

 

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页http://knight-black-bob.iteye.com/



 
 
 谢谢您的赞助,我会做的更好!

猜你喜欢

转载自knight-black-bob.iteye.com/blog/2395293