Trunk_Daer

1.protoc 环境配置

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf/
git checkout v2.6.1
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig (动态链接库配置刷新)
protoc --version (输出:libprotoc 2.6.1) 表示编译安装成功

参考文章https://github.com/datacratic/protobuf/issues/2修改autogen.sh

修改autogen.sh

echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
mv gtest-1.5.0 gtest

autogen.sh内的上述内容修改为

wget https://github.com/google/googletest/archive/release-1.5.0.tar.gz
tar xzvf release-1.5.0.tar.gz
mv googletest-release-1.5.0 gtest

2.libhiredis.a 编译

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make 输出:
pkg-config not found:
则执行: 
apt-get install pkg-config
重新make
sudo make install
cd /home/redis-stable/deps/hiredis/
make
make install
redis 版本
git clone https://github.com/redis/redis.git
cd /home/reids
git checkout 2.8.11

3.libjson.a =>libjsoncpp.a 编译

参考https://github.com/open-source-parsers/jsoncpp/tree/svn-import

cd /home
git clone https://github.com/open-source-parsers/jsoncpp.git
cd jsoncpp/
git checkout svn-import
sudo apt-get install cmake
mkdir -p ../build/debug
cd ../build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../../jsoncpp
修改/home/jsoncpp/CMakeLists.txt
add_compile_options(-fPIC)
make
这里可以不做:下载 scons-local-1.2.0.tar 拷贝 scons-local-1.2.0.tar jsoncpp/ 目录 cd jsoncpp/ 解压 scons-local-1.2.0.tar  python scons.py platform=linux-gcc

4.install qtcreator

apt-get install qtcreator qbs

5.上传Trunk_DAER.zip

cd /home
unzip Trunk_DAER.zip
rm -rf __MACOSX/
cd Trunk_DAER
rm -rf .svn/
find . -name “.DS_Store” -type f -print -exec rm -rf {} \;
cd /home/Trunk_DAER/proto/
make
cd /home/Trunk_DAER/svr/Common/src
make
cd /home/Trunk_DAER/svr/room/src
make
输出:
error: unable to find string literal operator 'operator""format' with 'const char [12]', 'long unsigned int' arguments

 #define ErrMsg(format,...) TGlobal::g_pErrorLog->logMsg("[%s %u][%s]"format,__F

                                                         ^

../../common/PBConfigBasic.h:585:9: note: in expansion of macro 'ErrMsg'

         ErrMsg("init po_chan_config config");

修改:
vim /home/Trunk_DAER/core/include/global.h
在宏定义处,format前添加空格
删除 /home/Trunk_DAER/
去掉旧版本的json头文件和库,改用自己编译的 
rm -rf /home/Trunk_DAER/libs/json
vim /home/Trunk_DAER/svr/room/src/makefile
LIB += -ljsoncpp #LIB += -L../../../libs/json -ljson
make 后输出:LogWriter.cpp:20: undefined reference to `CLogSocketHandler::Connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
上传:
core_src.zip 到 /home/Trunk_DAER/core/
解压到/home/Trunk_DAER/core/src
cd /home/Trunk_DAER/core/src
make

error: no ‘CEpollSlot* CPollerObject::GetEpollSlot()‘ member function declared in class ‘CPollerObject

CEpollSlot* CPollerObject::GetEpollSlot()

vim /home/Trunk_DAER/core/include/poller.h
friend class CPollerUnit;
//这里添加此行申明
CEpollSlot*GetEpollSlot();
 vim /home/Trunk_DAER/core/include/BindAdapter.h:
#pragma once
#include "net.h"
#include "poller.h"
#include "TCP_Handler_Base.h"
#include 

using namespace std;

class BindAdapter : public CPollerObject
{
public:
    BindAdapter(HandlerProxyBasic* handler_porxy, int acceptcnt, int backlog);
    virtual ~BindAdapter();
    virtual int OnAttachPoller();
    virtual int InputNotify();
    virtual void ProcessInnerMessage();

    void Init(const string& name, const char* ip, uint16_t port);
    bool Bind();
    virtual const string getName();
    virtual bool AppInit() = 0;
    virtual bool Reload() = 0;
    virtual bool Retire()
    {
        return false;
    }
    virtual void Exit() = 0;
    virtual bool Online() = 0;
    virtual bool OnCheckLink() = 0;
    virtual bool OffCheckLink() = 0;
private:
    int proc_accept(struct sockaddr* peer, socklen_t* peerSize);
    int proc_request(struct sockaddr* peer);
protected:
    virtual CTCP_Handler_Base* CreateHandler(int netfd, struct sockaddr* peer) = 0;

public:
    HandlerProxyBasic* _handler_proxy;
protected:
    int     _accept_cnt;
    int     _newfd_cnt;
    int* _fd_array;
    uint16_t    _bindPort;
    char        _bindAddr[128];
    int         _backlog;
    unsigned int    _flag;
    struct sockaddr* _peer_array;
    string _name;
};

vim /home/Trunk_DAER/core/include/NewReactor.h:

#define SIG_ONLINE SIGRTMIN+5
#define SIG_CHECK_LINK_ON SIGRTMIN+6
#define SIG_CHECK_LINK_OFF SIGRTMIN+7

#define FLAG_ONLINE (32)
#define FLAG_CHECK_LINK_ON (64)
#define FLAG_CHECK_LINK_OFF (128)

typedef map<string, BindAdapter*> BindAdapterMap;

//bool Init(int argc, char* argv[], FrameServer* pserver, ENNodeType type, int maxpoller = MAX_POLLER);
//修改为:
bool Init(int argc, char* argv[], int type, int maxpoller = MAX_POLLER);

    void DaemonStart();
    bool bindAdapter(BindAdapter* adapter);
    void OnExit();
    void OnLogLevelChange(int level);
    void OnRetire();
    void OnReload();
    void OnOnline();
    void OnCheckLink();
    void OffCheckLink();
protected:
    BindAdapterMap _adapters;

vim /hom/Trunk_DAER/core/include/New

#include "BindAdapter.h"

vim /home/Trunk_DAER/core/include/global.h

static int _svrd_type;//static ENNodeType _svrd_type;
static int _state;
static int _target_port;
static int& _node_id;
static int& _node_type;
static string _inner_ip;

在"format 之间添加空格 " format

vim ../include/TCP_Handler_Base.h

 CONN_XML_POLICY,
 CONN_PIPE_BROKEN,

vim /home/Trunk_DAER/svr/common/Makefile

LINK    = -lpthread /usr/local/lib/libhiredis.a /usr/local/lib/libjsoncpp.a

cd ../room/src/

vim /home/Trunk_DAER/svr/room/src/makefile

LIB += -ljsoncpp #LIB += -L../../../libs/json -ljson

vim /home/Trunk_DAER/svr/routing/src/makefile

CFLAGS += -g -O0 -Wall -fPIC -fpermissive

cd /home/Trunk_DAER/svr/dbproxy/src/

make

cd /home/Trunk_DAER/svr/connect/src/

vim makefile:

CFLAGS += -g -O0 -Wall -fPIC -fpermissive

cd /home/Trunk_DAER/svr/wsconnect/src/

vim makefile:

CFLAGS += -g -O0 -Wall -fPIC -fpermissive

cd /home/Trunk_DAER/svr/gm/src/

vim makefile:

CFLAGS += -g -O0 -Wall -fPIC -fpermissive
-ljsoncpp #-L../../../libs/libjson.a -ljson

cd /home/Trunk_DAER/svr/hall/src/:

vim makefile:

CFLAGS += -g -O0 -Wall -fPIC -fpermissive
LIB += -L../../../libs #-L../../../libs/json
LIB += /usr/local/lib/libhiredis.a -ljsoncpp #LIB += /usr/local/lib/libhiredis.a -ljson

cd /home/Trunk_DAER/svr/log/src/

vim makefile:

CFLAGS += -g -O0 -Wall -fPIC -fpermissive

cd /home/Trunk_DAER/svr/user/src/

vim makefile:

LIB += -L../../../libs #-L../../../libs/json

LIB += /usr/local/lib/libhiredis.a -ljsoncpp #-ljson

cd /home/Trunk_DAER/svr/mseqs_coin/src/

vim makefile:

LIB += -ljsoncpp #LIB += -L../../../libs/json -ljson

cd /home/Trunk_DAER/srv/lzdaer_coin/src/

vim makefile:

LIB += -ljsoncpp #LIB += -L../../../libs/json -ljson

cd /home/Trunk_DAER/svr/robot/src/

vim makefile:

LIB += -L../../../libs #-L../../../libs/json

LIB += /usr/local/lib/libhiredis.a -ljsoncpp #-ljson

因为hiredis版本不同替换头文件:

cp /home/redis/deps/hiredis/read.h /home/Trunk_DAER/svr/common/
cp /home/redis/deps/hiredis/sds.h /home/Trunk_DAER/svr/common/
cp /home/redis/deps/hiredis/alloc.h /home/Trunk_DAER/svr/common/

6.redis 配置:

apt-get install redis-server
apt-get autoremove redis-server --purge
vim /etc/redis/redis.conf
将#port 6379改成port 6504
6501 account
6511 rank
6521 users
7511 ssdb
添加上面的对应配置
vim /etc/redis/redis6501.conf
vim /etc/redis/redis6502.conf
vim /etc/redis/redis6504.conf
vim /etc/redis/redis6511.conf
vim /etc/redis/redis6512.conf
vim /etc/redis/redis6521.conf
vim /etc/redis/redis6541.conf
vim /etc/redis/redis7501.conf
vim /etc/redis/redis7511.conf
mkdir -p /var/lib/redis/6501
mkdir -p /var/lib/redis/6502
mkdir -p /var/lib/redis/6504
mkdir -p /var/lib/redis/6511
mkdir -p /var/lib/redis/6512
mkdir -p /var/lib/redis/6521 
mkdir -p /var/lib/redis/6541
mkdir -p /var/lib/redis/7501 
mkdir -p /var/lib/redis/7511 
修改*.conf对应的port 和 pidfile /var/run/redis/redis-server-6501.pid 
以及logfile /var/log/redis/redis-server-6501.log 
还有 dir /var/log/redis/6501 
启动redis-server 
redis-server /etc/redis/redis6501.conf 
redis-server /etc/redis/redis6502.conf 
redis-server /etc/redis/redis6504.conf
redis-server /etc/redis/redis6511.conf
redis-server /etc/redis/redis6512.conf
redis-server /etc/redis/redis6521.conf 
redis-server /etc/redis/redis6541.conf
redis-server /etc/redis/redis7501.conf 
redis-server /etc/redis/redis7511.conf

停止默认的redis-server 服务

systemctl disable redis-server
service redis-server stop
重新启动 redis-server /etc/redis/redis6504.conf

关闭redis-server 服务

redis-cli -p 6501
shutdown
exit
redis-cli -p 6502
redis-cli -p 6504
redis-cli -p 6511
redis-cli -p 6512
redis-cli -p 6521
redis-cli -p 6541
redis-cli -p 7501
redis-cli -p 7511

7.调试命令 :

gdb --args TrunkCNZPRoutingSvrd -h ::ffff:0.0.0.0 -p 14397
gdb --args TrunkCNZPLogSvrd -h ::ffff:0.0.0.0 -p 14108 
gdb --args TrunkCNZPDBProxySvrd -p 13708 -s 1 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPDBConnectSvrd -p 13408 -s 1 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPWSSConnectSvrd -p 19408 -s 1001 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPHallSvrd -p 13508 -s 1 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPRoomSvrd -p 13808 -s 1 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPUserSvrd -p 13608 -s 1 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPLzDaerSvrd -p 14308 -s 1 -h ::ffff:0.0.0.0
gdb --args TrunkCNZPLzDaerCoinSvrd -p 14305 -s 1 -h ::ffff:0.0.0.0

8.启动顺序

routing
log
dbproxy
connect
wsconnect
hall
room
user
mseqs_coin

9.安装https ssl证书参考

https://certbot.eff.org/

https://certbot.eff.org/lets-encrypt/ubuntuxenial-apache

https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04

10.apache2开启

#sudo a2enmod ssl
sudo a2enmod proxy
#sudo a2enmod proxy_balancer
#sudo a2enmod proxy_http
#sudo a2enmod proxy_connect
sudo a2enmod proxy_wstunnel

11.查找文件内容命令

sudo find / -type f -name "*.cpp" | xargs grep "ERROR"