C++ 高性能服务器框架 -- Linux 服务器开发环境搭建

环境配置

-----------------------------------------------------------------------------------------------------------

  1. VisualBox安装 (虚拟机软件)
  2. Linux系统
  3. ohmyzsh (提高你shell终端命令行接口(Command-line interface )的神奇工具)
  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 ( 文件中)
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网络模式为 桥接网卡
(查看IP地址: ifconfig   注:如果ifconfig 不行,那就用 ip addr )

然后执行网卡重启 service network restart

(具体名称和网卡一致)
ohmyzsh

我是命令行界面的忠实粉丝…我不喜欢使用我的电脑鼠标!这促使我寻找出色的工具来增强我在CLI上的用户体验,一次偶然的机会机会在YouTube上观看了国外YouTuber使用该工具,促使我对他产生了兴趣.本教程基于Centos7.6,其他操作系统差不多

以下是oh-my-zsh部分功能:

  • 命令验证
  • 在所有正在运行的shell中共享命令历史记录
  • 拼写纠正
  • 主题提示(Agnoster,RobbyRussell,…)
  • 目录历史
  • 通过zshenv,zprofile,zshrc,zlogin和zlogout启动/关闭脚本
  • 强大的自动完成功能。您可以使用TAB键浏览不同的选项,然后使用enter键选择正确的文件夹。例如Bash会打印所有选项。
  • 添加插件:例如Git插件包含大量有用的Git别名。 此插件显示活动分支并提供有关Git状态的可视反馈:
  • 绿色:如果没有发生变化的分支
  • 黄色:未跟踪文件
  • 带有加号图标的黄色:准备提交的文件

yum install zsh
yum install git
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:$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

发布了8 篇原创文章 · 获赞 18 · 访问量 8884

猜你喜欢

转载自blog.csdn.net/weixin_38054045/article/details/104123243