c++服务器开发环境搭建

sudo apt-get install libgoogle-perftools-dev 

sudo apt-get install cmake

sudo apt-get install git

git clone https://github.com/crossroads-io/libxs.git

git clone https://github.com/zeromq/cppzmq.git

git clone https://github.com/250bpm/cppxs.git

sudo apt-get install libmysqlclient18 

sudo apt-get install libmysqlclient-dev

sudo apt-get install libmysql-cil-dev

sudo apt-get install libsqlite3-dev

git clone https://github.com/zeromq/libzmq.git

sudo apt-get install autoconf

sudo apt-get install libtool 


sudo apt-get install libpcre3 libpcre3-dev

sudo apt-get install openssl libssl-dev

http://blog.csdn.net/csfreebird/article/details/9626577 install gcc 4.8.1
http://sourceforge.net/projects/boost/files/boost/1.55.0.beta.1/ install boost 1.55a1
http://sourceforge.net/projects/stlsoft/files/STLSoft%201.9/1.9.117/ stlsoft
http://sourceforge.net/projects/pantheios/files/Pantheios%20%28C%20and%20Cxx%29/1.0.1%20%28beta%20214%29/ pantheios
http://sourceforge.net/projects/fastformat/files/fastformat/0.7/0.7.1/0.7.1%20%28alpha%209%29/ fastformat
http://code.google.com/p/leveldb/downloads/list leveldb
http://code.google.com/p/protobuf/downloads/list protobuf
http://sourceforge.net/projects/cppcms/files/cppcms/1.0.4/ cppcms
http://sourceforge.net/projects/cppcms/files/cppdb/0.3.1/ cppdb
http://www.codeblocks.org/downloads/26 codeblocks
http://dev.mysql.com/downloads/connector/cpp/ mysql c++ conn



(二)、CppCMS的安装


在Terminal中输入:

cd cppcms-1.0.4/

mkdir build


cd build

cmake ..

make

make test

sudo make install  


(三)、leveldb的安装()

1、下载 leveldb-1.14.0.tar.gz(http://code.google.com/p/leveldb/downloads/detail?name=leveldb-1.14.0.tar.gz&can=2&q=)
2、tar zxvf  leveldb-1.14.0.tar.gz
3、cd leveldb-1.14.0
4、make
5、sudo cp -r include/leveldb   /usr/local/include
6、sudo cp libleveldb.a  /usr/local/lib  (或把libleveldb.a放到程序的统一路径下)

(五)、protobuf的安装(ok)
1、下载并解压protobuf-2.5.0
2、cd protobuf-2.5.0/
3、./configure
4、make
5、make check
6、sudo make install

结果
Libraries have been installed in:  
    /usr/local/lib  
Head files hava been installed in:  
  /usr/local/include/google/protobuf/  

(六)mysql-connector-c++驱动安装(ok)
1、下载mysql-connector-c++-1.1.3-linux-glibc2.3-x86-64bit.tar.gz
2、解压:tar -zxvf  mysql-connector-c++-1.1.3-linux-glibc2.3-x86-64bit.tar.gz
3、sudo cp mysql-connector-c++-1.1.3-linux-glibc2.3-x86-64bit/lib/*   /usr/local/lib
4、sudo cp -r mysql-connector-c++-1.1.3-linux-glibc2.3-x86-64bit/include/*    /usr/local/include

Linux 编译安装Boost  

sudo yum install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel -y

tar xvzf boost_1_50_0.tar.gz

cd boost_1_50_0

./bootstrap.sh

./b2

漫长的等待后

The Boost C++ Libraries were successfully built!
          
The following directory should be added to compiler include paths:
          
    /home/gang/BAK/boost_1_50_0
      
The following directory should be added to linker library paths:
      
    /home/gang/BAK/boost_1_50_0/stage/lib
安装
sudo./b2 install --prefix=/usr/local


安装 zeromq

tar -zxvf zeromq-2.2.0.tar.gz

cd zeromq-2.2.0

./configure    # 选择安装路径可以(./configure --prefix=/data/zeromq)

make

sudo make install

ldconfig

如果在编译过程中报错找不到

zmq.hpp

文件



zmq.hpp

拷贝到

/usr/local/include/

即可。

#tar zxvf libunwind-0.98.6.tar.gz
#cd libunwind-0.98.6
#./configure
#make
#make install

#tar zxvf google-perftools-0.94.1.tar.gz
#cd google*
#./configure
#make
#make install


libxs的安装

cd libxs
sudo ./autogen.sh
./configure
make
sudo make install


cppdb 的安装
cd
cmake .
make
sudo make install

git clone https://github.com/zeromq/libzmq.git
cd libzmq
sudo ./autogen.sh
./configure
make
sudo make install

mysql 数据库管理软件的安装

sudo apt-get install mysql-server

sudo apt-get install apache2

sudo apt-get install php5 libapache2-mod-php5

sudo /etc/init.d/apache2 restart

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin



在/etc/profile中配置一下变量

STLSOFT=/home/dm/lib/stlsoft-1.9.117
export STLSOFT

PANTHEIOS_ROOT=/home/dm/lib/pantheios-1.0.1-beta214
export PANTHEIOS_ROOT

FASTFORMAT_ROOT=/home/dm/lib/fastformat-0.7.1-alpha-9
export FASTFORMAT_ROOT



Leveldb是一个google实现的非常高效的kv数据库,

目前的版本1.2能够支持billion级别的数据量了。

在这个数量级别下还有着非常高的性能,主要归功于它的良好的设计。特别是LSM算法

LevelDB 是单进程的服务,性能非常之高,在一台4个Q6600的CPU机器上,

每秒钟写数据超过40w,而随机读的性能每秒钟超过10w。

此处随机读是完全命中内存的速度,如果是不命中 速度大大下降

LevelDB 只是一个 C/C++ 编程语言的库, 不包含网络服务封装,

所以无法像一般意义的存储服务器(如 MySQL)那样, 用客户端来连接它.

LevelDB 自己也声明, 使用者应该封装自己的网络服务器.

1、打开数据库


#include "leveldb/db.h"
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);

编译带上参数 -lleveldb -lpthread

2、关闭数据库
 delete db;

3、大部分的leveldb的函数都会返回Status,可检测他的状态status.ok()来查询是否执行成功

4、增删改
std::string value;
leveldb::Status s = db->Get(leveldb::ReadOptions(), key1, &value);
if (s.ok()) s = db->Put(leveldb::WriteOptions(), key2, value);
if (s.ok()) s = db->Delete(leveldb::WriteOptions(), key1);


5、原子操作
#include "leveldb/write_batch.h"
 
std::string value;
leveldb::Status s = db->Get(leveldb::ReadOptions(), key1, &value);
if (s.ok()) {
    leveldb::WriteBatch batch;
    batch.Delete(key1);
    batch.Put(key2, value);
    s = db->Write(leveldb::WriteOptions(), &batch);
}

你可能感兴趣的:(c++服务器端开发,游戏开发)