新版TeamTalk部署教程

原文转自蓝狐(bluefox)的博客:https://blog.csdn.net/simongyley/article/details/45535429。对文中部分问题做了修改。

0、简介

新版TeamTalk已经在2015年03月28日发布了,目前版本定为1.0.0版本,后续版本号会按照如下规则进行:
1、版本规则按照x.y.z的形式进行。
2、各端小bug修复则版本号中z增加。
3、有新的feature增加,则版本号中y增加。
4、有重大更新及不兼容更新,则版本号x增加。

本教程会在VirtualBox 虚拟机中进行安装部署一整套服务端,并做记录,给大家做个参考,后面会将整个虚拟机打包上传到网盘中,为那些不想自己亲自部署的人一个可用环境。

这篇博客中,不会使用一键部署脚本,我会一步一步手动去部署。另外我会尽量选择源码安装mysql,php,nginx等,后面所有的安装在/usr/local/目录下。(源码安装很多参考了军哥(http://www.lnmp.org)的脚本,在此表示感谢)。

真个部署过程从晚上8:00开始到半夜将近2:00(由于时间太晚了,明天还要上班,所以配置那块后面再写),耗时近6个小时,所以本文也耗时5个多小时才完成,希望可以帮助到大家。

更新:


     
     
     
     
  1. 20150402日更新
  2. 更新了配置文件说明
  3. 20150407日更新
  4. 更新了数据库导入,及问题修复。
  5. 20150505
  6. 修复mysql下载不了问题,感谢 @Gene反馈。

我的环境如下:


     
     
     
     
  1. 虚拟机 :VirtualBox 4 .3 .18
  2. CPU :2
  3. 内存 :2GB
  4. 硬盘 :10GB
  5. 操作系统 :CentOS 6 .5 x64
  6. IP :192.168.1.150


下面我们正式开始:

1、更新操作系统

更新操作系统:

CentOS 使用如下命令:

yum update

     
     
     
     

Ubuntu 使用如下命令:

apt-get update

     
     
     
     

该命令会执行更新,会消耗一段时间,国内用户,建议使用科大源或者163,搜狐等都可以,这会为大家节省很多时间,具体使用方法,可以见相关的页面:


     
     
     
     
  1. 163源帮助 :http ://mirrors. 163.com/.help/centos.html
  2. :http ://mirrors. 163.com/.help/ubuntu.html
  3. 搜狐源帮助 :http ://mirrors.sohu.com/help/centos.html
  4. :http ://mirrors.sohu.com/help/ubuntu.html
  5. 科大源帮助 :https ://lug.ustc.edu.cn/wiki/mirrors/help/centos
  6. :https ://lug.ustc.edu.cn/wiki/mirrors/help/ubuntu

执行上面命令后,会检查一些更新,会出现如下图:

后面会询问是否安装更新,有可能会询问你是否需要导入密钥之类的,输入y即可,如下图所示:

2、删除已经安装的软件

为了减少一些不必要的麻烦,我们需要先卸载系统自带的一些软件,譬如mysql,nginx,php,执行以下命令:

CentOS 执行如下命令:

yum -y remove httpd* php* mysql-server mysql mysql-libs php-mysql

     
     
     
     

Ubuntu 使用如下命令:


     
     
     
     
  1. apt-get remove - y apache2 apache2-doc apache2-utils apache2. 2-common apache2. 2-bin apache2-mpm-prefork apache2-doc apache2-mpm-worker mysql-client mysql-server mysql-common php5 php5-common php5-cgi php5-mysql php5-curl php5-gd
  2. killall apache2
  3. dpkg -l | grep mysql
  4. dpkg -P libmysqlclient15off libmysqlclient15-dev mysql-common
  5. dpkg -l | grep apache
  6. dpkg -P apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2. 2-common
  7. dpkg -l | grep php
  8. dpkg -P php5 php5-common php5-cgi php5-mysql php5-curl php5-gd
  9. apt-get purge `dpkg -l | grep php| awk '{print $2}'`

如下图所示:

3、安装必要的依赖软件

由于我选择的是CentOS 最小化安装,所以系统中很多软件是没有安装的,需要我手动安装。
执行如下命令安装一些依赖软件:

CentOS 使用如下命令:

yum -y install wget vim git texinfo patch make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils

     
     
     
     

ubuntu 使用如下命令:


     
     
     
     
  1. apt-get autoremove -y
  2. apt-get -fy install
  3. apt- get install -y build-essential gcc g++ make
  4. apt- get install -y --force-yes wget vim git texinfo patch build-essential gcc g++ make cmake automake autoconf re2c wget cron bzip2 libzip-dev libc6-dev file rcconf flex vim nano bison m4 gawk less make cpp binutils diffutils unzip tar bzip2 libbz2-dev unrar p7zip libncurses5-dev libncurses5 libncurses5-dev libncurses5-dev libtool libevent-dev libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlibc openssl libsasl2-dev libltdl3-dev libltdl-dev libmcrypt-dev zlib1g zlib1g-dev libbz2-1.0 libbz2-dev libglib2.0-0 libglib2.0-dev libpng3 libjpeg62 libjpeg62-dev libjpeg-dev libpng-dev libpng12-0 libpng12-dev curl libcurl3 libmhash2 libmhash-dev libpq-dev libpq5 gettext libncurses5-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libxml2-dev zlib1g-dev libfreetype6 libfreetype6-dev libssl-dev libcurl3 libcurl4-openssl-dev libcurl4-gnutls-dev mcrypt libcap-dev diffutils ca-certificates debian-keyring debian-archive-keyring;
  5. apt- get -fy install
  6. apt- get -y autoremove

过程如下图所示:

如下图安装结束:

4、安装mysql

本次安装的mysql版本是5.6.选择从搜狐源下载,编译过程漫长。

4.1 下载

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.23.tar.gz

     
     
     
     

4.2 解压编译

执行如下命令:


     
     
     
     
  1. tar -zxvf mysql -5.6 .23.tar.gz
  2. cd mysql -5.6 .23
  3. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE= 1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER= 1 -DENABLED_LOCAL_INFILE= 1
  4. make -j 2 && make install

编译将是一个漫长得过程。。。不同的机器性能等待时间不同。
make的-j参数可以使make进行并行编译编译。我cpu的个数是2,所以指定为2.

4.3 添加mysql用户


     
     
     
     
  1. groupadd mysql
  2. useradd -s /sbin/nologin -M -g mysql mysql

4.4 修改配置文件

vim /etc/my.cnf

     
     
     
     

下面给出一份参考配置(只是测试用,如果要用于生产环境,请自行调配):


     
     
     
     
  1. # Example MySQL config file for medium systems.
  2. # The following options will be passed to all MySQL clients
  3. [client]
  4. #password = your_password
  5. port = 3306
  6. socket = /tmp/mysql.sock
  7. default-character- set=utf8mb4
  8. # Here follows entries for some specific programs
  9. # The MySQL server
  10. [mysqld]
  11. bind-address= 127.0. 0.1
  12. port = 3306
  13. socket = /tmp/mysql.sock
  14. datadir = /usr/ local/mysql/ var
  15. collation-server = utf8mb4_general_ci
  16. character- set-server = utf8mb4
  17. skip- external-locking
  18. key_buffer_size = 16M
  19. max_allowed_packet = 1M
  20. table_open_cache = 64
  21. sort_buffer_size = 512K
  22. net_buffer_length = 8K
  23. read_buffer_size = 256K
  24. read_rnd_buffer_size = 512K
  25. myisam_sort_buffer_size = 8M
  26. # Replication Master Server ( default)
  27. # binary logging is required for replication
  28. log-bin=mysql-bin
  29. # binary logging format - mixed recommended
  30. binlog_format=mixed
  31. # required unique id between 1 and 2^ 32 - 1
  32. # defaults to 1 if master-host is not set
  33. # but will not function as a master if omitted
  34. server-id = 1
  35. # Uncomment the following if you are using InnoDB tables
  36. innodb_data_home_dir = /usr/local/mysql/var
  37. innodb_data_file_path = ibdata1: 10M:autoextend
  38. innodb_log_group_home_dir = /usr/ local/mysql/ var
  39. # You can set .._buffer_pool_size up to 50 - 80 %
  40. # of RAM but beware of setting memory usage too high
  41. innodb_buffer_pool_size = 16M
  42. innodb_additional_mem_pool_size = 2M
  43. # Set .._log_file_size to 25 % of buffer pool size
  44. innodb_log_file_size = 5M
  45. innodb_log_buffer_size = 8M
  46. innodb_flush_log_at_trx_commit = 1
  47. innodb_lock_wait_timeout = 50
  48. [mysqldump]
  49. quick
  50. max_allowed_packet = 16M
  51. [mysql]
  52. no-auto-rehash
  53. # Remove the next comment character if you are not familiar with SQL
  54. #safe-updates
  55. default-character- set=utf8mb4
  56. [myisamchk]
  57. key_buffer_size = 20M
  58. sort_buffer_size = 20M
  59. read_buffer = 2M
  60. write_buffer = 2M
  61. [mysqlhotcopy]
  62. interactive-timeout

4.5 初始化mysql


     
     
     
     
  1. /usr/ local/mysql/scripts/mysql_install_db --defaults- file=/etc/my.cnf --basedir=/usr/ local/mysql --datadir=/usr/ local/mysql/ var --user=mysql
  2. chown -R mysql /usr/ local/mysql/ var
  3. chgrp -R mysql /usr/ local/mysql/.
  4. cp support-files/mysql.server /etc/init.d/mysql
  5. chmod 755 /etc/init.d/mysql
  6. cat > /etc/ld.so.conf.d/mysql.conf<
  7. /usr/ local/mysql/lib
  8. /usr/ local/lib
  9. EOF
  10. ldconfig

4.6 启动mysql

/etc/init.d/mysql start

     
     
     
     

4.7 查看mysql进程

ps -ef|grep mysql

     
     
     
     

如果看到下图,恭喜你,mysql安装成功:

4.8 后期配置


     
     
     
     
  1. ln -s /usr/ local/mysql/lib/mysql /usr/lib/mysql
  2. ln -s /usr/ local/mysql/include/mysql /usr/include/mysql
  3. ln -s /usr/ local/mysql/bin/mysql /usr/bin/mysql
  4. ln -s /usr/ local/mysql/bin/mysqldump /usr/bin/mysqldump
  5. ln -s /usr/ local/mysql/bin/myisamchk /usr/bin/myisamchk
  6. ln -s /usr/ local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe

登陆mysql:

mysql -uroot -p

     
     
     
     

修改密码(假定密码为:test123):


     
     
     
     
  1. use mysql;
  2. update user set password= password( '$mysqlrootpwd') where user= 'root';
  3. flush privileges;

退出,重新登陆:

mysql -uroot -p

     
     
     
     

整个过程如下图:

4.9 结束

至此,mysql 已经安装结束。退出到上一层目录

cd ../

     
     
     
     

5、安装PHP

本次安装的PHP是php 5.3.28,选择从搜狐源下载。

5.1 下载PHP

wget http://mirrors.sohu.com/php/php-5.3.28.tar.gz

     
     
     
     

5.2 安装依赖

安装依赖的库,我选择从chinaunix.net下载的,速度也还可以。

5.2.1 libiconv


     
     
     
     
  1. wget http: //down1.chinaunix.net/distfiles/libiconv-1.14.tar.gz
  2. tar -zxvf libiconv -1.14.tar.gz
  3. cd libiconv -1.14
  4. ./configure
  5. make -j 2&& make install
  6. cd ..

5.2.2 libmcrypt


     
     
     
     
  1. wget http: //down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz
  2. tar -zxvf libmcrypt -2.5 .7.tar.gz
  3. cd libmcrypt -2.5 .7
  4. ./configure
  5. make -j 2&& make install
  6. ldconfig
  7. cd libltdl/
  8. ./configure --enable-ltdl-install
  9. make && make install
  10. cd ../../

5.2.3 mhash


     
     
     
     
  1. wget http: //down1.chinaunix.net/distfiles/mhash-0.9.3.tar.gz
  2. tar -zxvf mhash -0.9 .3.tar.gz
  3. cd mhash -0.9 .3
  4. ./configure
  5. make -j 2 && make install
  6. cd ../

5.3 解压编译


     
     
     
     
  1. tar -zxvf php- 5.3. 28.tar.gz
  2. cd php- 5.3. 28
  3. ./configure --prefix=/usr/ local/php -- with-config- file-path=/usr/ local/php/etc --enable-fpm -- with-fpm-user=www -- with-fpm-group=www -- with-mysql=mysqlnd -- with-mysqli=mysqlnd -- with-pdo-mysql=mysqlnd -- with-iconv-dir -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib -- with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable- inline-optimization -- with-curl --enable-mbregex --enable-mbstring -- with-mcrypt --enable-ftp -- with-gd --enable-gd-native-ttf -- with-openssl -- with-mhash --enable-pcntl --enable-sockets -- with-xmlrpc --enable-zip --enable-soap --without-pear -- with-gettext --disable-fileinfo
  4. make -j 2 ZEND_EXTRA_LIBS= '-liconv' && make install

5.4 配置php


     
     
     
     
  1. cp php.ini-production /usr/ local/php/etc/php.ini
  2. sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/ local/php/etc/php.ini
  3. sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/ local/php/etc/php.ini
  4. sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/ local/php/etc/php.ini
  5. sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/ local/php/etc/php.ini
  6. sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/ local/php/etc/php.ini
  7. sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/ local/php/etc/php.ini
  8. sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/ local/php/etc/php.ini
  9. sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/ local/php/etc/php.ini
  10. sed -i 's/register_long_arrays = On/;register_long_arrays = On/g' /usr/ local/php/etc/php.ini
  11. sed -i 's/magic_quotes_gpc = On/;magic_quotes_gpc = On/g' /usr/ local/php/etc/php.ini
  12. sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/ local/php/etc/php.ini

5.5 后期配置


     
     
     
     
  1. ln -s /usr/ local/php/bin/php /usr/bin/php
  2. ln -s /usr/ local/php/bin/phpize /usr/bin/phpize
  3. ln -s /usr/ local/php/sbin/php-fpm /usr/bin/php-fpm
  4. cd ..

5.6 安装ZendGuardLoader


     
     
     
     
  1. mkdir -p /usr/ local/zend/
  2. wget http: //downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
  3. tar -zxvf ZendGuardLoader-php- 5.3-linux-glibc23-x86_64.tar.gz
  4. cp ZendGuardLoader-php- 5.3-linux-glibc23-x86_64/php- 5.3.x/ZendGuardLoader.so /usr/ local/zend/
  5. cat >>/usr/ local/php/etc/php.ini<
  6. ;eaccelerator
  7. ;ionCube
  8. [Zend Optimizer]
  9. zend_extension=/usr/ local/zend/ZendGuardLoader.so
  10. zend_loader.enable= 1
  11. zend_loader.disable_licensing= 0
  12. zend_loader.obfuscation_level_support= 3
  13. zend_loader.license_path=
  14. EOF
  15. cd ..

5.7 修改php-fpm配置文件


     
     
     
     
  1. cat >/usr/local/php/etc/php-fpm.conf<<EOF
  2. [ global]
  3. pid = /usr/local/php/var/run/php-fpm.pid
  4. error_log = /usr/local/php/var/log/php-fpm.log
  5. log_level = notice
  6. [ www]
  7. listen = /tmp/php-cgi.sock
  8. listen.backlog = -1
  9. listen.allowed_clients = 127.0.0.1 #这里之后配置完如果发现php页面打不开,请把127.0.0.1改成自己服务器的地址。
  10. listen.owner = www
  11. listen.group = www
  12. listen.mode = 0666
  13. user = www
  14. group = www
  15. pm = dynamic
  16. pm.max_children = 10
  17. pm.start_servers = 2
  18. pm.min_spare_servers = 1
  19. pm.max_spare_servers = 6
  20. request_terminate_timeout = 100
  21. request_slowlog_timeout = 0
  22. slowlog = var/log/slow.log
  23. EOF

5.8 创建php-fpm启动脚本


     
     
     
     
  1. vim /etc/ init.d/php-fpm
  2. chmod +x /etc/ init.d/php-fpm

以下是一份参考:


     
     
     
     
  1. #! /bin/sh #如果在centos下请使用#!/bin/bash代替
  2. ### BEGIN INIT INFO
  3. # Provides: php-fpm
  4. # Required-Start: $remote_fs $network
  5. # Required-Stop: $remote_fs $network
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: starts php-fpm
  9. # Description: starts the PHP FastCGI Process Manager daemon
  10. ### END INIT INFO
  11. prefix=/usr/ local/php
  12. exec_prefix= ${prefix}
  13. php_fpm_BIN=${exec_prefix}/sbin/php-fpm
  14. php_fpm_CONF= ${prefix}/etc/php-fpm.conf
  15. php_fpm_PID=${prefix}/var/run/php-fpm.pid
  16. php_opts= "--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
  17. wait_for_pid () {
  18. try=0
  19. while test $try -lt 35 ; do
  20. case "$1" in
  21. 'created')
  22. if [ -f "$2" ] ; then
  23. try=''
  24. break
  25. fi
  26. ;;
  27. 'removed')
  28. if [ ! -f "$2" ] ; then
  29. try= ''
  30. break
  31. fi
  32. ;;
  33. esac
  34. echo -n .
  35. try=`expr $try + 1`
  36. sleep 1
  37. done
  38. }
  39. case "$1" in
  40. start)
  41. echo -n "Starting php-fpm "
  42. $php_fpm_BIN --daemonize $php_opts
  43. if [ "$?" != 0 ] ; then
  44. echo " failed"
  45. exit 1
  46. fi
  47. wait_for_pid created $php_fpm_PID
  48. if [ -n "$try" ] ; then
  49. echo " failed"
  50. exit 1
  51. else
  52. echo " done"
  53. fi
  54. ;;
  55. stop)
  56. echo -n "Gracefully shutting down php-fpm "
  57. if [ ! -r $php_fpm_PID ] ; then
  58. echo "warning, no pid file found - php-fpm is not running ?"
  59. exit 1
  60. fi
  61. kill -QUIT `cat $php_fpm_PID`
  62. wait_for_pid removed $php_fpm_PID
  63. if [ -n "$try" ] ; then
  64. echo " failed. Use force-quit"
  65. exit 1
  66. else
  67. echo " done"
  68. fi
  69. ;;
  70. force-quit)
  71. echo -n "Terminating php-fpm "
  72. if [ ! -r $php_fpm_PID ] ; then
  73. echo "warning, no pid file found - php-fpm is not running ?"
  74. exit 1
  75. fi
  76. kill -TERM `cat $php_fpm_PID`
  77. wait_for_pid removed $php_fpm_PID
  78. if [ -n "$try" ] ; then
  79. echo " failed"
  80. exit 1
  81. else
  82. echo " done"
  83. fi
  84. ;;
  85. restart)
  86. $0 stop
  87. $0 start
  88. ;;
  89. reload)
  90. echo -n "Reload service php-fpm "
  91. if [ ! -r $php_fpm_PID ] ; then
  92. echo "warning, no pid file found - php-fpm is not running ?"
  93. exit 1
  94. fi
  95. kill -USR2 `cat $php_fpm_PID`
  96. echo " done"
  97. ;;
  98. *)
  99. echo "Usage: $0 {start|stop|force-quit|restart|reload}"
  100. exit 1
  101. ;;
  102. esac

5.9 启动php-fpm


     
     
     
     
  1. groupadd www
  2. useradd -s /sbin/nologin -g www www
  3. /etc/ init.d/php-fpm start

见到如下图代表启动成功:

6 安装nginx

6.1 下载nginx

wget http://mirrors.sohu.com/nginx/nginx-1.6.0.tar.gz

     
     
     
     

6.2 安装依赖

6.2.1 pcre


     
     
     
     
  1. wget http: //down1.chinaunix.net/distfiles/pcre-8.12.tar.bz2
  2. tar -jxvf pcre -8.12.tar.bz2
  3. cd pcre -8.12
  4. ./configure
  5. make -j 2 && make install
  6. cd ..

6.3 解压编译nginx


     
     
     
     
  1. tar -zxvf nginx- 1.6. 0.tar.gz
  2. cd nginx- 1.6. 0
  3. ./configure --user=www --group=www --prefix=/usr/ local/nginx -- with-http_stub_status_module -- with-http_ssl_module -- with-http_gzip_static_module -- with-ipv6
  4. make -j 2 && make install
  5. cd ..
  6. ln -s /usr/ local/nginx/sbin/nginx /usr/bin/nginx

6.4 配置nginx

/usr/local/nginx/conf/nginx.conf

     
     
     
     

下面是一份参考配置:


     
     
     
     
  1. user www www;
  2. worker_processes auto;
  3. error_log /home/wwwlogs/nginx_error. log crit;
  4. pid /usr/local/nginx/logs/nginx.pid;
  5. #Specifies the value for maximum file descriptors that can be opened by this process.
  6. worker_rlimit_nofile 51200;
  7. events
  8. {
  9. use epoll;
  10. worker_connections 51200;
  11. multi_accept on;
  12. }
  13. http
  14. {
  15. include mime.types;
  16. default_type application/octet-stream;
  17. server_names_hash_bucket_size 128;
  18. client_header_buffer_size 32k;
  19. large_client_header_buffers 4 32k;
  20. client_max_body_size 50m;
  21. sendfile on;
  22. tcp_nopush on;
  23. keepalive_timeout 60;
  24. tcp_nodelay on;
  25. fastcgi_connect_timeout 300;
  26. fastcgi_send_timeout 300;
  27. fastcgi_read_timeout 300;
  28. fastcgi_buffer_size 64k;
  29. fastcgi_buffers 4 64k;
  30. fastcgi_busy_buffers_size 128k;
  31. fastcgi_temp_file_write_size 256k;
  32. gzip on;
  33. gzip_min_length 1k;
  34. gzip_buffers 4 16k;
  35. gzip_http_version 1.0;
  36. gzip_comp_level 2;
  37. gzip_types text/plain application/x-javascript text/css application/xml;
  38. gzip_vary on;
  39. gzip_proxied expired no-cache no-store private auth;
  40. gzip_disable "MSIE [1-6]\.";
  41. #limit_conn_zone $binary_remote_addr zone=perip:10m;
  42. ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
  43. server_tokens off;
  44. #log format
  45. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  46. '$status $body_bytes_sent "$http_referer" '
  47. '"$http_user_agent" $http_x_forwarded_for';
  48. server
  49. {
  50. listen 80 default;
  51. #listen [::]: 80 default ipv6only= on;
  52. server_name www.lnmp.org;
  53. index index.html index.htm index.php;
  54. root /home/wwwroot/ default;
  55. #error_page 404 / 404.html;
  56. location ~ [^/]\.php(/|$)
  57. {
  58. # comment try_files $uri =404; to enable pathinfo
  59. try_files $uri =404;
  60. fastcgi_pass unix:/tmp/php-cgi.sock;
  61. fastcgi_index index.php;
  62. include fastcgi.conf;
  63. #include pathinfo.conf;
  64. }
  65. location /nginx_status {
  66. stub_status on;
  67. access_log off;
  68. }
  69. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  70. {
  71. expires 30d;
  72. }
  73. location ~ .*\.(js|css)?$
  74. {
  75. expires 12h;
  76. }
  77. access_log /home/wwwlogs/access. log access;
  78. }
  79. include vhost/*.conf;
  80. }

6.5 后期配置


     
     
     
     
  1. mkdir -p /home/wwwroot/default
  2. chmod +w /home/wwwroot/default
  3. mkdir -p /home/wwwlogs
  4. chmod 777 /home/wwwlogs
  5. chown -R www:www /home/wwwroot/default

6.6 编写nginx启动脚本


     
     
     
     
  1. vim /etc/ init.d/nginx
  2. chmod +x /etc/ init.d/nginx

下面是一份参考配置:


     
     
     
     
  1. #! /bin/sh #如果在centos下请使用#!/bin/bash代替
  2. # chkconfig: 2345 55 25
  3. # Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
  4. # run 'update-rc.d -f nginx defaults', or use the appropriate command on your
  5. # distro. For CentOS/Redhat run: 'chkconfig --add nginx'
  6. ### BEGIN INIT INFO
  7. # Provides: nginx
  8. # Required-Start: $all
  9. # Required-Stop: $all
  10. # Default-Start: 2 3 4 5
  11. # Default-Stop: 0 1 6
  12. # Short-Description: starts the nginx web server
  13. # Description: starts nginx using start-stop-daemon
  14. ### END INIT INFO
  15. # Author: licess
  16. # website: http://lnmp.org
  17. PATH=/usr/ local/sbin:/usr/ local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  18. NAME=nginx
  19. NGINX_BIN=/usr/ local/nginx/sbin/ $NAME
  20. CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
  21. PIDFILE=/usr/ local/nginx/logs/ $NAME.pid
  22. SCRIPTNAME=/etc/init.d/$NAME
  23. case "$1" in
  24. start)
  25. echo -n "Starting $NAME... "
  26. if netstat -tnpl | grep -q nginx; then
  27. echo "$NAME (pid `pidof $NAME`) already running."
  28. exit 1
  29. fi
  30. $NGINX_BIN -c $CONFIGFILE
  31. if [ "$?" != 0 ] ; then
  32. echo " failed"
  33. exit 1
  34. else
  35. echo " done"
  36. fi
  37. ;;
  38. stop)
  39. echo -n "Stoping $NAME... "
  40. if ! netstat -tnpl | grep -q nginx; then
  41. echo "$NAME is not running."
  42. exit 1
  43. fi
  44. $NGINX_BIN -s stop
  45. if [ "$?" != 0 ] ; then
  46. echo " failed. Use force-quit"
  47. exit 1
  48. else
  49. echo " done"
  50. fi
  51. ;;
  52. status)
  53. if netstat -tnpl | grep -q nginx; then
  54. PID=`pidof nginx`
  55. echo "$NAME (pid $PID) is running..."
  56. else
  57. echo "$NAME is stopped"
  58. exit 0
  59. fi
  60. ;;
  61. force-quit)
  62. echo -n "Terminating $NAME... "
  63. if ! netstat -tnpl | grep -q nginx; then
  64. echo "$NAME is not running."
  65. exit 1
  66. fi
  67. kill `pidof $NAME`
  68. if [ "$?" != 0 ] ; then
  69. echo " failed"
  70. exit 1
  71. else
  72. echo " done"
  73. fi
  74. ;;
  75. restart)
  76. $SCRIPTNAME stop
  77. sleep 1
  78. $SCRIPTNAME start
  79. ;;
  80. reload)
  81. echo -n "Reload service $NAME... "
  82. if netstat -tnpl | grep -q nginx; then
  83. $NGINX_BIN -s reload
  84. echo " done"
  85. else
  86. echo "$NAME is not running, can't reload."
  87. exit 1
  88. fi
  89. ;;
  90. configtest)
  91. echo -n "Test $NAME configure files... "
  92. $NGINX_BIN -t
  93. ;;
  94. *)
  95. echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"
  96. exit 1
  97. ;;
  98. esac

6.7 测试nginx

6.7.1 写php测试代码


     
     
     
     
  1. cat >/home/wwwroot/ default/index.php<
  2. phpinfo();
  3. ?>
  4. EOF

6.7.2启动nginx


     
     
     
     
  1. /etc/ init.d/nginx start
  2. ps -ef|grep nginx

见到下图,代表启动成功:

如果你开启了selinux,请关闭,否则访问不了:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

     
     
     
     

临时关闭selinux:

setenforce 0

     
     
     
     

关闭防火墙:

service iptables stop

     
     
     
     

通过浏览器访问下,如下图:


7 安装redis

7.1 下载redis

wget http://download.redis.io/releases/redis-2.8.19.tar.gz

     
     
     
     

这里会快很多:

wget http://download.redis.io/releases/redis-2.8.19.tar.gz

     
     
     
     

7.2 解压编译redis


     
     
     
     
  1. tar -zxvf redis-2.8.19.tar.gz
  2. cd redis-2.8.19
  3. make PREFIX=/usr/ local/redis install

7.3 配置redis


     
     
     
     
  1. mkdir -p /usr/ local/redis/etc/
  2. cp redis.conf /usr/ local/redis/etc/
  3. sed -i 's/daemonize no/daemonize yes/g' /usr/ local/redis/etc/redis.conf
  4. cd ..

7.4 编写redis启动脚本


     
     
     
     
  1. vim /etc/ init.d/redis
  2. chmod +x /etc/ init.d/redis

下面是一份参考配置:


     
     
     
     
  1. #! /bin/bash #如果在centos下请使用#!/bin/bash代替
  2. #
  3. # redis - this script starts and stops the redis-server daemon
  4. #
  5. # chkconfig: 2345 80 90
  6. # description: Redis is a persistent key-value database
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides: redis
  10. # Required-Start: $syslog
  11. # Required-Stop: $syslog
  12. # Should-Start: $local_fs
  13. # Should-Stop: $local_fs
  14. # Default-Start: 2 3 4 5
  15. # Default-Stop: 0 1 6
  16. # Short-Description: redis-server daemon
  17. # Description: redis-server daemon
  18. ### END INIT INFO
  19. REDISPORT=6379
  20. EXEC=/usr/ local/redis/bin/redis-server
  21. REDIS_CLI=/usr/ local/redis/bin/redis-cli
  22. PIDFILE=/var/run/redis.pid
  23. CONF= "/usr/local/redis/etc/redis.conf"
  24. case "$1" in
  25. start)
  26. if [ -f $PIDFILE ]
  27. then
  28. echo "$PIDFILE exists, process is already running or crashed"
  29. else
  30. echo "Starting Redis server..."
  31. $EXEC $CONF
  32. fi
  33. if [ "$?"="0" ]
  34. then
  35. echo "Redis is running..."
  36. fi
  37. ;;
  38. stop)
  39. if [ ! -f $PIDFILE ]
  40. then
  41. echo "$PIDFILE does not exist, process is not running"
  42. else
  43. PID=$(cat $PIDFILE)
  44. echo "Stopping ..."
  45. $REDIS_CLI -p $REDISPORT shutdown
  46. while [ -x ${PIDFILE} ]
  47. do
  48. echo "Waiting for Redis to shutdown ..."
  49. sleep 1
  50. done
  51. echo "Redis stopped"
  52. fi
  53. ;;
  54. restart)
  55. ${0} stop
  56. ${0} start
  57. ;;
  58. *)
  59. echo "Usage: /etc/init.d/redis {start|stop|restart}" >&2
  60. exit 1
  61. esac

7.5 启动redis

/etc/init.d/redis start

     
     
     
     

查看redis是否启动

ps -ef|grep redis

     
     
     
     

如果看到如下图,恭喜你,启动成功:

8 设置开机启动


     
     
     
     
  1. chkconfig --level 345 php-fpm on
  2. chkconfig --level 345 nginx on
  3. chkconfig --level 345 mysql on
  4. chkconfig --level 345 redis on

9 升级gcc,gdb等(非常漫长,如果系统中自带的g++支持C++11,可跳过此步骤)

9.1 下载gcc4.9.2

使用日本的源可能会快些:

wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.9.2/gcc-4.9.2.tar.gz

     
     
     
     

9.2 解压编译gcc4.9.2


     
     
     
     
  1. tar -zxvf gcc-4.9.2.tar.gz
  2. cd gcc-4.9.2
  3. ./contrib/download_prerequisites
  4. mkdir gcc-build-4.9.2
  5. cd gcc-build-4.9.2
  6. ../configure --prefix=/usr - enable-checking=release - enable-languages=c,c++ - disable-multilib
  7. make -j 2 && make install
  8. cd ../../

9.3 下载termcap

wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz

     
     
     
     

9.4 解压编译termcap


     
     
     
     
  1. tar -zxvf termcap -1.3 .1.tar.gz
  2. cd termcap -1.3 .1
  3. ./configure --prefix=/usr
  4. make -j 2 && make install

9.5 下载gdb

wget http://ftp.gnu.org/gnu/gdb/gdb-7.9.tar.gz

     
     
     
     

9.6 解压编译gdb


     
     
     
     
  1. tar -zxvf gdb -7.9.tar.gz
  2. cd gdb -7.9
  3. ./configure --prefix=/usr
  4. make -j 2 && make install

10 重启电脑

shutdown -r now

     
     
     
     

11 安装PB

11.1 下载pb

wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz

     
     
     
     

11.2 解压编译pb


     
     
     
     
  1. tar -zxvf protobuf -2.6 .1
  2. cd protobuf -2.6 .1
  3. ./configure --prefix=/usr/local/protobuf
  4. make -j 2 && make install

12 下载TeamTalk代码

git clone https://github.com/mogujie/TeamTalk.git

     
     
     
     

13 生成pb文件

13.1 拷贝pb相关文件

拷贝pb的库、头文件到TeamTalk相关目录中:


     
     
     
     
  1. mkdir -p /root/TeamTalk/ server/src/base/pb/lib/linux/
  2. cp /usr/local/protobuf/lib/libprotobuf-lite.a /root/TeamTalk/ server/src/base/pb/lib/linux/
  3. cp -r /usr/local/protobuf/include/* /root/TeamTalk/ server/src/base/pb/

13.2 生成pb协议

cd /root/TeamTalk/pb

     
     
     
     

执行:


     
     
     
     
  1. export PATH=$PATH:/usr/local/protobuf/bin
  2. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH :/usr/local/protobuf/lib
  3. sh create.sh

生成协议相关源码文件。

再执行:

sh sync.sh

     
     
     
     

将相关文件拷贝到server 目录下。

14 安装依赖


     
     
     
     
  1. cd /root/TeamTalk/server/src
  2. sh make_log4cxx.sh #如后运行时仍提示没有找到log4xx的库,请手动安装,安装在/usr下就可以
  3. sh make_hiredis.sh

15 编译server

15.1 编译

由于我们是源码安装mysql的,所以对db_proxy_server中的CMakeList做一定的修改.
原来:


     
     
     
     
  1. SET(MYSQL_INCLUDE_DIR /usr/ include/mysql)
  2. SET(MYSQL_LIB /usr/lib64/mysql)

修改为:


     
     
     
     
  1. SET(MYSQL_INCLUDE_DIR /usr/ local/mysql/ include)
  2. SET(MYSQL_LIB /usr/ local/mysql/lib)

进入server目录下,执行:

sh build.sh version 1.0.0

     
     
     
     

如果一切顺利,你将会看到如下画面:

16 配置server

配置就以本机192.168.1.150 为例。

16.1 配置文件说明:

16.1.1 login_server


     
     
     
     
  1. ClientListenIP= 0.0 .0 .0 # can use multiple ip, seperate by ';'
  2. ClientPort= 8008
  3. HttpListenIP= 0.0 .0 .0
  4. HttpPort= 8080
  5. MsgServerListenIP= 0.0 .0 .0 # can use multiple ip, seperate by ';'
  6. MsgServerPort= 8100
  7. msfs=http: //127.0.0.1:8700/
  8. discovery=http: //127.0.0.1/api/discovery

ClientListenIP:目前已经作废。
ClientPort:与上一个配套,同样作废。
HttpListenIP:供客户端过来获取msg_server及其他参数的接口地址,走http协议。
HttpPort:与上一个配套使用。
MsgServerListenIP:用于监听msg_server上报信息使用。
MsgServerPort:与上一个配套使用。msg_server启动的时候回来连接该ip:port,以上报自己的信息。
在运行过程中,也会实时将自己的信息汇报给login_server。
msfs:小文件存储的地址,该配置是提供给客户端获取参数时使用。
discovery:发现内容获取地址,该配置是提供给客户端获取参数时使用。

参考配置:


     
     
     
     
  1. ClientListenIP= 192.168.1.150
  2. ClientPort= 8008
  3. HttpListenIP= 192.168.1.150
  4. HttpPort= 8080
  5. MsgServerListenIP= 192.168.1.150
  6. MsgServerPort= 8100
  7. msfs=http: //192.168.1.150:8700/
  8. discovery=http: //192.168.1.150/api/discovery

16.1.2 route_server


     
     
     
     
  1. ListenIP= 0.0 .0 .0 # Listening IP
  2. ListenMsgPort= 8200 # Listening Port for MsgServer

route_server配置比较简单,一个监听ip,一个监听port就OK了,供msg_server连接上来用。

参考配置:


     
     
     
     
  1. ListenIP=192.168.1.150
  2. ListenMsgPort=8200

16.1.3 http_msg_server


     
     
     
     
  1. ListenIP= 0.0 .0 .0
  2. ListenPort= 8400
  3. ConcurrentDBConnCnt= 4
  4. DBServerIP1= 127.0 .0 .1
  5. DBServerPort1= 10600
  6. DBServerIP2= 127.0 .0 .1
  7. DBServerPort2= 10600
  8. RouteServerIP1=localhost
  9. RouteServerPort1= 8200
  10. #RouteServerIP2=localhost
  11. #RouteServerPort2=8201

ListenIP:监听IP,供其他人来调用http_msg_server接口,比如,php在创建群组的时候,就会来调用http_msg_server的接口。
ListenPort:监听端口,与上一个配套使用。
ConcurrentDBConnCnt:DB数目,目前必须配置为2的整数倍,是历史遗留问题,后期会修复。
DBServerIP(x):db_proxy_server监听的IP,http_msg_server会主动去连接。
DBServerPort(x):db_proxy_server监听的Port
RouteServerIP(x):route_server监听的IP,http_msg_server会主动去连接。
RouteServer(x):route_server监听的Port

参考配置:


     
     
     
     
  1. ListenIP=192.168.1.150
  2. ListenPort=8400
  3. ConcurrentDBConnCnt=4
  4. DBServerIP1=192.168.1.150
  5. DBServerPort1=10600
  6. DBServerIP2=192.168.1.150
  7. DBServerPort2=10600
  8. RouteServerIP1=192.168.1.150
  9. RouteServerPort1=8200

16.1.4 msg_server


     
     
     
     
  1. ListenIP= 0.0 .0 .0
  2. ListenPort= 8000
  3. ConcurrentDBConnCnt= 2
  4. DBServerIP1= 127.0 .0 .1
  5. DBServerPort1= 10600
  6. DBServerIP2= 127.0 .0 .1
  7. DBServerPort2= 10600
  8. LoginServerIP1= 127.0 .0 .1
  9. LoginServerPort1= 8100
  10. #LoginServerIP2=localhost
  11. #LoginServerPort2=8101
  12. RouteServerIP1= 127.0 .0 .1
  13. RouteServerPort1= 8200
  14. #RouteServerIP2=localhost
  15. #RouteServerPort2=8201
  16. PushServerIP1= 127.0 .0 .1
  17. PushServerPort1= 8500
  18. FileServerIP1= 127.0 .0 .1
  19. FileServerPort1= 8600
  20. #FileServerIP2=localhost
  21. #FileServerPort2=8601
  22. IpAddr1= 127.0 .0 .1 #电信IP
  23. IpAddr2= 127.0 .0 .1 #网通IP
  24. MaxConnCnt= 100000
  25. #AES 密钥
  26. aesKey= 12345678901234567890123456789012

ListenIP:监听客户端连接上来的IP。
ListenPort:与上一个配套使用,监听客户端连接的port。
ConcurrentDBConnCnt:db_proxy_server个数,同http_msg_server 一样。
DBServerIP(x):db_proxy_server监听的ip,msg_server主动去连接。
DBServerPort(x):db_proxy_server监听的port。
LoginServerIP(x):login_server监听的ip,msg_server会主动去连接,汇报本机信息。
LoginServerPort(x):login_server监听的port。
RouteServerIP(x):route_server监听的IP,msg_server主动去连接。
RouteServerPort(x):route_server监听的port。
PushServerIP(x):push_server监听的IP,msg_server会主动去连接,给ios系统推送消息。
PushServerPort(x):push_server监听的port。
FileServerIP(x):file_server监听的IP,msg_server会主动去连接,用于文件传输,暂时未用到。
FileServerPort(x):file_server监听的port。
IpAddr1:msg_server监听的ip,用于汇报给login_server,便于login_server在客户端请求的时候返回给客户端。注意,这个ip一定要是客户端能连接的ip,之前发现好多人配置成127.0.0.1,这是不行的。
IpAddr2:同上。
aesKey:消息文本加密密钥.这里配置主要在msg_server向push_server推送的时候需要将加密的消息进行解密。

参考配置:


     
     
     
     
  1. ListenIP= 192.168 .1 .150
  2. ListenPort= 8000
  3. ConcurrentDBConnCnt= 2
  4. DBServerIP1= 192.168 .1 .150
  5. DBServerPort1= 10600
  6. DBServerIP2= 192.168 .1 .150
  7. DBServerPort2= 10600
  8. LoginServerIP1= 192.168 .1 .150
  9. LoginServerPort1= 8100
  10. RouteServerIP1= 192.168 .1 .150
  11. RouteServerPort1= 8200
  12. PushServerIP1= 192.168 .1 .150
  13. PushServerPort1= 8500
  14. FileServerIP1= 192.168 .1 .150
  15. FileServerPort1= 8600
  16. IpAddr1= 192.168 .1 .150 #电信IP
  17. IpAddr2= 192.168 .1 .150 #网通IP
  18. MaxConnCnt= 100000
  19. #AES 密钥
  20. aesKey= 12345678901234567890123456789012

16.1.5 db_proxy_server


     
     
     
     
  1. ListenIP= 127.0 .0 .1
  2. ListenPort= 10600
  3. ThreadNum= 48 # double the number of CPU core
  4. MsfsSite= 127.0 .0 .1
  5. #configure for mysql
  6. DBInstances=teamtalk_master,teamtalk_slave
  7. #teamtalk_master
  8. teamtalk_master_host= 127.0 .0 .1
  9. teamtalk_master_port= 3306
  10. teamtalk_master_dbname=teamtalk
  11. teamtalk_master_username=root
  12. teamtalk_master_password= 12345
  13. teamtalk_master_maxconncnt= 16
  14. #teamtalk_slave
  15. teamtalk_slave_host= 127.0 .0 .1
  16. teamtalk_slave_port= 3306
  17. teamtalk_slave_dbname=teamtalk
  18. teamtalk_slave_username=root
  19. teamtalk_slave_password= 12345
  20. teamtalk_slave_maxconncnt= 16
  21. #configure for unread
  22. CacheInstances=unread,group_set,token,group_member
  23. #未读消息计数器的redis
  24. unread_host= 127.0 .0 .1
  25. unread_port= 6379
  26. unread_db= 1
  27. unread_maxconncnt= 16
  28. #群组设置redis
  29. group_set_host= 127.0 .0 .1
  30. group_set_port= 6379
  31. group_set_db= 2
  32. group_set_maxconncnt= 16
  33. #deviceToken redis
  34. token_host= 127.0 .0 .1
  35. token_port= 6379
  36. token_db= 4
  37. token_maxconncnt= 16
  38. #GroupMember
  39. group_member_host= 127.0 .0 .1
  40. group_member_port= 6379
  41. group_member_db= 5
  42. group_member_maxconncnt= 48
  43. #AES 密钥
  44. aesKey= 12345678901234567890123456789012

ListenIP:db_proxy_server监听的IP。
ListenPort:db_proxy_server监听的port
ThreadNum:工作线程个数。
MsfsSite:配置msfs服务器的地址,用于发送语音的时候上传保存语音文本。
DBInstances:db实例名称。一般配置一主一从即可,其他根据自己的需求修改。
(xxxx)_host:xxxx实例的ip
(xxxx)_port:xxxx实例的port
(xxxx)_dbname:xxxx实例的scheme名称
(xxxx)_username:xxxx实例的用户名
(xxxx)_password:xxxx实例的密码
(xxxx)_maxconncnt:xxxx实例最大连接数
CacheInstances:cache实例名称。
(xxxx)_host:xxxx实例的ip
(xxxx)_port:xxxx实例的port
(xxxx)_db:xxxx实例的db
(xxxx)_maxconncnt:xxxx
aesKey:消息加密密钥。
目前我们db实例配置的一主一从,cache实例配置了5个实例,分别是:
unread:主要用于未读计数。
group_set:群组设置。设置屏蔽群组。
token:主要用于保存ios系统的token。
group_member:保存群成员信息。

参考配置:


     
     
     
     
  1. ListenIP= 192.168. 1.150
  2. ListenPort= 10600
  3. ThreadNum= 48 # double the number of CPU core
  4. MsfsSite= http:/ /192.168.1.150:8700/
  5. #configure for mysql
  6. DBInstances=teamtalk_master,teamtalk_slave
  7. #teamtalk_master
  8. teamtalk_master_host= 192.168. 1.150
  9. teamtalk_master_port= 3306
  10. teamtalk_master_dbname=teamtalk
  11. teamtalk_master_username=teamtalk
  12. teamtalk_master_password=test@123
  13. teamtalk_master_maxconncnt= 16
  14. #teamtalk_slave
  15. teamtalk_slave_host= 192.168. 1.150
  16. teamtalk_slave_port= 3306
  17. teamtalk_slave_dbname=teamtalk
  18. teamtalk_slave_username=teamtalk
  19. teamtalk_slave_password=test@123
  20. teamtalk_slave_maxconncnt= 16
  21. #configure for unread
  22. CacheInstances=unread,group_set,token,group_member
  23. #未读消息计数器的redis
  24. unread_host= 192.168. 1.150
  25. unread_port= 6379
  26. unread_db= 1
  27. unread_maxconncnt= 16
  28. #群组设置redis
  29. group_set_host= 192.168. 1.150
  30. group_set_port= 6379
  31. group_set_db= 2
  32. group_set_maxconncnt= 16
  33. #deviceToken redis
  34. token_host= 192.168. 1.150
  35. token_port= 6379
  36. token_db= 4
  37. token_maxconncnt= 16
  38. #GroupMember
  39. group_member_host= 192.168. 1.150
  40. group_member_port= 6379
  41. group_member_db= 5
  42. group_member_maxconncnt= 48
  43. #AES 密钥
  44. aesKey= 12345678901234567890123456789012

17、更新

17.1 导入mysql

登陆mysql:

mysql -uroot -p

     
     
     
     

输入密码:test123.
创建TeamTalk数据库:

create database teamtalk

     
     
     
     

见到如下:


     
     
     
     
  1. mysql> create database teamtalk;
  2. Query OK, 1 row affected (0 .00 sec)

创建成功。
创建teamtalk用户并给teamtalk用户授权teamtalk的操作:


     
     
     
     
  1. grant select, insert, update, delete on teamtalk.* to 'teamtalk'@ '%' identified by 'test@123';
  2. flush privileges;

导入数据库.


     
     
     
     
  1. use teamtalk;
  2. source /root/TeamTalk/auto_setup/mariadb/conf/ttopen.sql;
  3. show tables;

如下:


     
     
     
     
  1. mysql> show tables;
  2. +--------------------+
  3. | Tables_in_teamtalk |
  4. +--------------------+
  5. | IMAdmin |
  6. | IMAudio |
  7. | IMDepart |
  8. | IMDiscovery |
  9. | IMGroup |
  10. | IMGroupMember |
  11. | IMGroupMessage_0 |
  12. | IMGroupMessage_1 |
  13. | IMGroupMessage_2 |
  14. | IMGroupMessage_3 |
  15. | IMGroupMessage_4 |
  16. | IMGroupMessage_5 |
  17. | IMGroupMessage_6 |
  18. | IMGroupMessage_7 |
  19. | IMMessage_0 |
  20. | IMMessage_1 |
  21. | IMMessage_2 |
  22. | IMMessage_3 |
  23. | IMMessage_4 |
  24. | IMMessage_5 |
  25. | IMMessage_6 |
  26. | IMMessage_7 |
  27. | IMRecentSession |
  28. | IMRelationShip |
  29. | IMUser |
  30. +--------------------+
  31. 25 rows in set ( 0. 00 sec)
  32. mysql>

17.2 修改php

执行如下命令:


     
     
     
     
  1. cd /home/wwwroot/ default
  2. cp -r /root/TeamTalk/php/* /home/wwwroot/ default

修改config.php:

vim application/config/config.php

     
     
     
     

修改第18-19行:


     
     
     
     
  1. $config['msfs_url'] = 'http://192.168.1.150:8700/';
  2. $config[ 'http_url'] = 'http://192.168.1.150:8400';

修改database.php

vim application/config/database.php

     
     
     
     

修改52-54行:


     
     
     
     
  1. $db['default']['hostname'] = '192.168.1.150';
  2. $db[ 'default'][ 'username'] = 'teamtalk';
  3. $db['default']['password'] = 'test@123';
  4. $db[ 'default'][ 'database'] = 'teamtalk';

访问后,看到如下图:

17.3 修改nginx.conf

之前给出的配置有点问题,新配置如下:


     
     
     
     
  1. user www www;
  2. worker_processes auto;
  3. error_log /home/wwwlogs/nginx_error.log crit;
  4. pid /usr/local/nginx/logs/nginx.pid;
  5. #Specifies the value for maximum file descriptors that can be opened by this process.
  6. worker_rlimit_nofile 51200;
  7. events
  8. {
  9. use epoll;
  10. worker_connections 51200;
  11. multi_accept on;
  12. }
  13. http
  14. {
  15. include mime.types;
  16. default_type application/octet-stream;
  17. server_names_hash_bucket_size 128;
  18. client_header_buffer_size 32k;
  19. large_client_header_buffers 4 32k;
  20. client_max_body_size 50m;
  21. sendfile on;
  22. tcp_nopush on;
  23. keepalive_timeout 60;
  24. tcp_nodelay on;
  25. fastcgi_connect_timeout 300;
  26. fastcgi_send_timeout 300;
  27. fastcgi_read_timeout 300;
  28. fastcgi_buffer_size 64k;
  29. fastcgi_buffers 4 64k;
  30. fastcgi_busy_buffers_size 128k;
  31. fastcgi_temp_file_write_size 256k;
  32. gzip on;
  33. gzip_min_length 1k;
  34. gzip_buffers 4 16k;
  35. gzip_http_version 1.0;
  36. gzip_comp_level 2;
  37. gzip_types text/plain application/x-javascript text/css application/xml;
  38. gzip_vary on;
  39. gzip_proxied expired no-cache no-store private auth;
  40. gzip_disable "MSIE [1-6]\.";
  41. server_tokens off;
  42. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  43. '$status $body_bytes_sent "$http_referer" '
  44. '"$http_user_agent" $http_x_forwarded_for';
  45. server
  46. {
  47. listen 80;
  48. server_name 192.168.1.150;
  49. index index.html index.htm index.php default.html default.htm default.php;
  50. root /home/wwwroot/default;
  51. location ~ \.php($|/) {
  52. fastcgi_pass unix:/tmp/php-cgi.sock;
  53. fastcgi_index index.php;
  54. fastcgi_split_path_info ^(.+\.php)(.*)$;
  55. fastcgi_param PATH_INFO $fastcgi_path_info;
  56. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  57. include fastcgi_params;
  58. }
  59. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  60. {
  61. expires 30d;
  62. }
  63. location ~ .*\.(js|css)?$
  64. {
  65. expires 12h;
  66. }
  67. if (!-e $request_filename) {
  68. rewrite ^/(.*)$ /index.php/$1 last;
  69. break;
  70. }
  71. }
  72. }

18、服务端启动

服务端的启动没有严格的先后流程,因为各端在启动后会去主动连接其所依赖的服务端。不过在此,如果是线上环境,还是建议按照如下的启动顺序去启动(也不是唯一的顺序):
1、启动db_proxy。
2、启动route_server,file_server,msfs
3、启动login_server
4、启动msg_server


19、测试

在后台添加test用户,运行ios 模拟器,登陆看到如下图

20、virtualBox 环境

置于怎么加载虚拟机,怎么运行虚拟机请自行百度,谷歌。

20.1 我虚拟机的环境

链接: http://pan.baidu.com/s/1sjx8g49 密码: 4572

     
     
     
     

20.2 虚拟机硬盘

因网盘大小限制1G,所以将虚拟机硬盘切分成3个文件上传:

链接: http://pan.baidu.com/s/1mgDXvwW 密码: tgzp

     
     
     
     

请使用如下命令合并解压:


     
     
     
     
  1. cat CentOS-hd .tar .gz.* > CentOS-hd .tar .gz
  2. tar -zxvf CentOS-hd .tar .gz

20.3 账号信息

虚拟机账号信息如下:


     
     
     
     
  1. linux账号密码 :root/ 123456
  2. mysql root账号密码 :root/test123
  3. mysql teamtalk账号密码 :teamtalk/test@123
  4. php 后台账号密码 :admin/admin
  5. 测试用户账号密码 :test/test

20.4 运行

启动虚拟机后,运行如下命令:

ps -ef|grep server

     
     
     
     

如果看到如下:


     
     
     
     
  1. [root@zhyh ~] # ps -ef|grep server
  2. root 1653 1 0 22: 13 ? 00: 00: 05 /usr/ local/redis/bin/redis-server *: 6379
  3. root 1658 1 1 22: 13 ? 00: 00: 21 ./db_proxy_server
  4. root 1717 1 0 22: 13 ? 00: 00: 02 ./http_msg_server
  5. root 1729 1 0 22: 13 ? 00: 00: 02 ./route_server
  6. root 1737 1 0 22: 14 ? 00: 00: 02 ./login_server
  7. root 1757 1 0 22: 15 ? 00: 00: 02 ./msg_server
  8. root 1788 1774 0 22: 34 pts/ 2 00: 00: 00 grep server

如果没有发现:db_proxy_server, http_msg_server,route_server,login_server,msg_server的进程,请执行如下命令启动:


     
     
     
     
  1. cd /usr/ local/teamtalk
  2. cd xxxx
  3. ../daeml xxxx

xxx代表相应的程序名。通过查看:xxxx/log/default.log 查看程序错误。

20.5 redis,php,nginx,mysql的启动,停止与重启


     
     
     
     
  1. /etc/init.d/redis {start |stop|restart}
  2. /etc/init.d/php-fpm {start |stop|force-quit |restart|reload}
  3. /etc/init.d/nginx {start |stop|force-quit |restart|reload |status|configtest}
  4. /etc/init.d/mysql {start |stop|restart |reload|force-reload |status} [ MySQL server options ]


            

你可能感兴趣的:(TeamTalk)