1.简介

这是蘑菇街开源的一款企业内部即时通讯软件,参考https://github.com/balloonwj/TeamTalk

2.编译

环境:gcc version 11.3.0、Ubuntu 11.3.0-1ubuntu1~22.04

1.脚本自动编译

修改build.sh脚本内容运行即可,待续

2.手动编译

这里说的手动编译是根据build.sh的脚本一个一个编译各个服务。根据TeamTalk/server/src目录下的build.sh脚本内容,此次先后编译的目标是:libbase.a、libslog.so、login_server、route_server、msg_server、http_msg_server、file_server、push_server、tools、db_proxy_server、msfs

  1. 编译libbase库:
    1. 先安装curl库
    sudo apt-get install libcurl4-openssl-dev
    
  2. 编译libslog库:
    1. 先根据make_log4cxx.sh脚本编译生成liblog4cxx.so
      1. make_log4cxx.sh脚本的修改
      #!/bin/bash
      # author: luoning
      # date: 03/24/2015
      LOG4CXX=apache-log4cxx-0.10.0
      # 访问地址需要是可用的
      LOG4CXX_PATH=https://archive.apache.org/dist/logging/log4cxx/0.10.0/$LOG4CXX.tar.gz
      # LOG4CXX_PATH=http://mirror.bit.edu.cn/apache/logging/log4cxx/0.10.0/$LOG4CXX.tar.gz
      CUR_DIR=
      download() {
          if [ -f "$1" ]; then
              echo "$1 existed."
          else
              echo "$1 not existed, begin to download..."
              wget $2
              if [ $? -eq 0 ]; then
                  echo "download $1 successed";
              else
                  echo "Error: download $1 failed";
                  return 1;
              fi
          fi
          return 0
      }
      
      check_user() {
          if [ $(id -u) != "0" ]; then
              echo "Error: You must be root to run this script, please use root to install im"
              exit 1
          fi
      }
      
      get_cur_dir() {
          # Get the fully qualified path to the script
          case $0 in
              /*)
                  SCRIPT="$0"
                  ;;
              *)
                  PWD_DIR=$(pwd);
                  SCRIPT="${PWD_DIR}/$0"
                  ;;
          esac
          # Resolve the true real path without any sym links.
          CHANGED=true
          while [ "X$CHANGED" != "X" ]
          do
              # Change spaces to ":" so the tokens can be parsed.
              SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
              # Get the real path to this script, resolving any symbolic links
              TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
              REALPATH=
              for C in $TOKENS; do
                  # Change any ":" in the token back to a space.
                  C=`echo $C | sed -e 's;:; ;g'`
                  REALPATH="$REALPATH/$C"
                  # If REALPATH is a sym link, resolve it.  Loop for nested links.
                  while [ -h "$REALPATH" ] ; do
                      LS="`ls -ld "$REALPATH"`"
                      LINK="`expr "$LS" : '.*-> \(.*\)$'`"
                      if expr "$LINK" : '/.*' > /dev/null; then
                          # LINK is absolute.
                          REALPATH="$LINK"
                      else
                          # LINK is relative.
                          REALPATH="`dirname "$REALPATH"`""/$LINK"
                      fi
                  done
              done
      
              if [ "$REALPATH" = "$SCRIPT" ]
              then
                  CHANGED=""
              else
                  SCRIPT="$REALPATH"
              fi
          done
          # Change the current directory to the location of the script
          CUR_DIR=$(dirname "${REALPATH}")
      }
      
      build_log4cxx(){
         	#yum -y install apr-devel
          #yum -y install apr-util-devel
          apt-get install -y libapr1-dev
      	apt-get install -y libaprutil1-dev 
      	cd log4cxx
      	# 下面两行如果在第2步中修改了log4cxx的源代码,则需要注释掉
         download $LOG4CXX.tar.gz $LOG4CXX_PATH
         tar -xf $LOG4CXX.tar.gz
          cd $LOG4CXX
          ./configure --prefix=$CUR_DIR/log4cxx --with-apr=/usr --with-apr-util=/usr
          cp ../inputstreamreader.cpp ./src/main/cpp/
          cp ../socketoutputstream.cpp ./src/main/cpp/
          cp ../console.cpp ./src/examples/cpp/
          make
          make install
          cd ../../
          cp -rf log4cxx/include slog/
          mkdir -p slog/lib/
          cp -f log4cxx/lib/liblog4cxx.so* slog/lib/
      }
      
      check_user
      get_cur_dir
      build_log4cxx
      
      
      1. 如果报错如下信息,则是因为使用的是高版本的编译器。直接将报错信息所在行进行注释即可。
      2. 执行sh make_log4cxx.sh
    2. 进入TeamTalk/server/src/slog目录,执行如下命令编译生成libslog.so
    cmake .
    make
    
    1. 进入TeamTalk/server/src/slog目录,分别执行
    mkdir ../base/slog/lib
    cp slog_api.h ../base/slog/
    cp libslog.so ../base/slog/lib/
    cp -a lib/liblog4cxx* ../base/slog/lib/
    
  3. 编译login_server
    1. 先根据TeamTalk/server/src目录下的make_protobuf.sh脚本编译生成libprotobuf-lite.a
    sh make_protobuf.sh
    
    1. 进入login_server目录,根据如下命令生成login_server
    cmake .
    make
    
  4. 编译route_server:进入route_server目录,执行
cmake .
make
  1. 编译msg_server:进入msg_server目录,执行
cmake .
make
  1. 编译http_msg_server
cmake .
make
  1. 编译file_server
cmake .
make
  1. 编译push_server
cmake .
make
  1. 编译tools:进入tools目录
make
  1. 编译db_proxy_server
    1. 编译libhiredis.a
    sh make_hiredis.sh
    
    1. 由于我云服务器上已经安装好MySQL,故不再重新编译一份。但是编译db_proxy_server报如下错误:将其改为bool

    2. 链接时报错:解决方案有两种

      1. 找到系统自身已经安装好的libmysqlclient,然后建立一个软连接
      2. 修改CMakeLists.txt:有三处
      # 以下路径可以通过locate mysql查找
      # 头文件包含目录
      SET(MYSQL_INCLUDE_DIR /usr/include/mysql)
      # 库目录
      SET(MYSQL_LIB /usr/lib/x86_64-linux-gnu)
      ....
      TARGET_LINK_LIBRARIES(db_proxy_server pthread base protobuf-lite dl mysqlclient hiredis curl slog crypto)
      
    3. 在db_proxy_server目录下执行

    cmake .
    make
    
  2. 编译msfs:进入msfs目录下,执行
cmake .
make

3.运行

  1. 启动MySQL,创建teamtalk数据库,根据tables.sql创建表。启动的默认端口3306
  2. 启动redis,启动的默认端口6379
./redis-server ../redis.conf
# 调试启动
cgdb --args ./redis-server ../redis.conf
# 后台启动
nohup ./redis-server ../redis.conf &
  1. 启动db_proxy_server,监听端口是10600
    1. 将dbproxyserver.conf和log4cxx.properties两个配置文件拷贝至和编译生成的db_proxy_server同级目录下
    2. 修改dbproxyserver.conf中的配置:比如说连接MySQL数据库的用户名和密码
    3. 启动:cgdb db_proxy_server
  2. 启动route_server,监听端口是8200
    1. 将routeserver.conf配置文件拷贝至和编译生成的route_server同级目录下
    2. 启动:cgdb route_server
  3. 启动file_server:监听客户端的端口是8600,给MsgServer使用的端口是8601
    1. 将fileserver.conf配置文件拷贝至和编译生成的file_server同级目录下
    2. 启动:cgdb file_server
  4. 启动login_server,给客户端的端口是8008,给MsgServer的端口是8100,给http的端口是8080
    1. 将loginserver.conf配置文件拷贝至和编译生成的login_server同级目录下
    2. 启动:cgdb login_server
  5. 启动msg_server,监听端口是8000,连接db_proxy_server的10600端口,连接login_server的8100端口,连接route_server的8200端口,连接push_server的8500端口,连接file_server的8601端口,
    1. 将msgserver.conf配置文件拷贝至和编译生成的msg_server同级目录下
    2. 启动:cgdb msg_server
  6. 启动msfs:端口号8700
    1. 将msfs.conf.example配置文件拷贝到和编译生成的msfs同级目录下,指定BaseDir的值
    2. 启动:cgdb msfs
  7. 启动push_server(向苹果手机推送):
    1. 将pushserver.conf配置文件拷贝到和编译生成的push_server同级目录下,指定BaseDir的值
    2. 启动:cgdb push_server