C++高性能服务器框架 – SYLAR – 01环境配置

sylar
2019.08.02 16:44:29阅读 6点赞 0收藏 0更多
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。

环境配置

  1. VisualBox安装
  2. Linux系统
  3. ohmyzsh
  4. VIM7.4+
  5. GCC 4.8+
  6. GDB 8.3
  7. CMAKE 2.8+
  8. ragel
  9. boost

环境安装包

sylar-env-1.0.1-1.el7.x86_64.rpm (在QQ群:8151915 群文件中)
Centos7.6环境直接安装,安装路径独立于系统路径,方便删除不影响系统软件

sudo rpm -ivh sylar-env-1.0.1-1.el7.x86_64.rpm yum install glibc-static yum install glibc-devel yum install glibc-headers yum install boost-devel yum install mysql-devel yum install git git clone https://github.com/sylar-yin/sylar.git cd sylar make make -j4

VisualBox安装

http://download.virtualbox.org/virtualbox/6.0.8/VirtualBox-6.0.8-130520-OSX.dmg

Linux系统安装

从centos官网下载ios文件,虚拟机加载ios文件,进行最小化安装即可
视频中采用的是centos7.6,链接地址 http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso

修改 /etc/sysconfig/network-scripts/ifcfg-enp0s3
ONBOOT=YES

修改VisualBox网络模式为 桥接网卡

然后执行网卡重启 service network restart

(具体名称和网卡一致)

ohmyzsh

  1. yum install zsh
  2. yum install git
  3. sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)”

VIM 安装

由于教程中使用了C11,所以必须使用VIM7.4 以上的版本才能正常显示C11中的一些语法(lambda).
视频中采用的是VIM8.1,链接地址 ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2

#安装依赖 yum install wget yum install ncurses-devel yum install gcc gcc-c++ yum install ctags wget ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2 tar xvf vim-8.1.tar.bz2 cd vim81 make install #验证安装成功 which vim /apps/sylar/bin/vim git clone https://github.com/sylar-yin/myvim.git cp myvim/.vim ~/ -rf cp myvim/.vimrc ~/ alias vctags="ctags -R --c++-kinds=+p --fields=+iaS --extra=+q" #添加到/etc/profile末尾

视频中的我使用的VIM配置github路径:https://github.com/sylar-yin/myvim

GCC安装

视频中使用的GCC为最新的稳定版本9.1
完整支持C11,C14,C++17,而且错误提示更友好
链接地址:http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.1.0/gcc-9.1.0.tar.xz

安装bison

没有安装bison,编译中会提示 “WARNING: ‘bison’ is missing on your system.”

sudo yum install bison

安装texinfo

没有安装texinfo,编译中会提示“WARNING: ‘makeinfo’ is missing on your system”

sudo yum install texinfo

将自定义安装路径添加到PATH

这里我将视频中要用到的程序都安装到一个自定义路径,不会与系统路径冲突。可以多版本并存。
需要将自定义的路径加入到PATH中
export PATH=/apps/sylar/bin:PATHexportLDLIBRARYPATH=/apps/sylar/lib:/apps/sylar/lib64:PATH export LD_LIBRARY_PATH=/apps/sylar/lib:/apps/sylar/lib64:LD_LIBRARY_PATH
将这条语句添加到~/.profile 或者 /etc/profile 文件最后。
执行source ~/.profile 或者 source /etc/profile
(我的自定义路径是/apps/sylar)

安装autoconf

gcc安装需要依赖automake-1.15以上版本,automake-1.15以上版本,需要依赖autoconf 2.69

下载地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz tar xvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/apps/sylar make -j make install #验证安装成功 which autoconf /apps/sylar/bin/autoconf

安装automake

gcc安装需要依赖automake-1.15以上版本
下载地址:http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz

wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz tar xvf automake-1.15.tar.gz cd automake-1.15 ./configure --prefix=/apps/sylar #修改Makefile 查找 /doc\/automake\-$(APIVERSION) #doc/automake-$(APIVERSION).1: $(automake_script) lib/Automake/Config.pm # $(update_mans) automake-$(APIVERSION) --no-discard-stderr #(3686行,加上--no-discard-stderr) make -j make install #验证安装成功 which automake /apps/sylar/bin/automake

GCC正式安装

GCC安装的时间会比较长,大概半小时-2小时,取决于机器性能,需要耐心等待

wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.1.0/gcc-9.1.0.tar.xz tar xvJf gcc-9.1.0.tar.xz cd gcc-9.1.0 sh contrib/download_prerequisites mkdir build cd build ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --prefix=/apps/sylar make -j make install #验证安装成功 which gcc /apps/sylar/bin/gcc

GDB安装

linux下调试工具, 版本8.3
由于8.3版本需要依赖gcc支持c++11,gdb必须等gcc安装完之后再安装

下载地址:http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.xz

wget http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.xz tar xvf gdb-8.3.tar.xz cd gdb-8.3 ./configure --prefix=/apps/sylar make -j make install #验证安装成功 which gdb /apps/sylar/bin/gdb

CMake安装

我使用的版本是CMake3.15

下载地址:https://github.com/Kitware/CMake/releases/download/v3.15.0-rc1/cmake-3.15.0-rc1.tar.gz

wget https://github.com/Kitware/CMake/releases/download/v3.15.0-rc1/cmake-3.15.0-rc1.tar.gz tar xvf cmake-3.15.0-rc1.tar.gz cd cmake-3.15.0-rc1 ./configure --prefix=/apps/sylar make -j make install #验证安装成功 which cmake /apps/sylar/bin/cmake

Ragel安装

有限状态机,编写出来的协议解析性能不弱于汇编
我使用的版本是Ragel 6.10,

下载地址:http://www.colm.net/files/ragel/ragel-6.10.tar.gz

wget http://www.colm.net/files/ragel/ragel-6.10.tar.gz tar xvf ragel-6.10.tar.gz cd ragel-6.10 ./configure --prefix=/apps/sylar make -j make install #验证安装成功 which ragel /apps/sylar/bin/ragel

boost安装

yum install boost-devel

其他安装

#killall 安装 yum install psmisc #openssl 安装 yum install openssl-devel #netstat 安装 yum install net-tools