debian配置
2021.7.8
首先我们去阿里云的官网买了一个学生服务器,如下图,我们可以选择地区,系统镜像还有配置。我选择的是debian8.9 2核2G,CentOS作为服务器也很稳定其实。
购买成功后我们可以看到服务器镜像的 内网地址,外网地址和其它配置信息,方便和安全起见,可以重置密码。
默认是root, 我们只需要在自己的cmd(或者mac的终端,或者linux的终端) ssh root@内网地址 就可以远程登陆了。
一、先看一下基本环境
- 查看系统架构:
# uname -a
Linux iZ2ze61irhf5hpew9xk18eZ 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2+deb8u3 (2017-08-15) x86_64 GNU/Linux
# dpkg --print-architecture
amd64
# getconf LONG_BIT
64
# arch
x86_64
- GCC版本:
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.2-10' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.2 (Debian 4.9.2-10)
支持C++11
支持C++14
不支持C++17
- Python版本
# python --version
Python 2.7.9
# python3 --version
-bash: python3: command not found
- (没有预装java和go)
二、简单配置vim
# cd /usr/share/vim/ && ls
addons registry vim74 vimfiles vimrc vimrc.tiny
# cat vimrc
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
"syntax on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
" filetype plugin indent on
"endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
syntax on "开启语法高亮
set showcmd " 命令模式下,在底部显示,当前键入的指
set mouse=a " 支持使用鼠标
set encoding=utf-8
set t_Co=256 " 开启256色
set autoindent " 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致
set tabstop=4 " Tab键的空格数
set expandtab " Tab自动转化为空格
set softtabstop=4 " Tab转化为多少个空格
set number " 显示行号
set cursorline " 光标所在当前行高亮
set showmatch " 光标在括号上时,自动高亮对应匹配的括号
set matchtime=2 " 短暂跳转到匹配括号的时间
set hlsearch " 搜索时高亮显示匹配结果
inoremap ( ()<LEFT>
inoremap { {}<LEFT>
inoremap [ []<LEFT>
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
三、简单配置bashrc
因为我是root,所以都直接配置全局的好了
# vim /etc/bash.bashrc
# root @ iZ2ze61irhf5hpew9xk18eZ /etc [00:39:56]
# tail -3 /etc/bash.bashrc
alias ls='ls --color'
alias ll='ls -l --color'
PS1="\n\[$(tput sgr0)\]\[\033[38;5;11m\]\\$\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;51m\]\u\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;253m\]@\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;2m\]\H\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;226m\]\w\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;250m\][\t]\[$(tput sgr0)\]\n\[$(tput sgr0)\]\[\033[38;5;196m\]\\$\[$(tput sgr0)\] \[$(tput sgr0)\]"
# source /etc/bash.bashrc
四、生成ssh-key
我们用ssh-keygen -t rsa
命令生成公钥和私钥,可以在 ~/.ssh
目录中查看。然后将id_rsa.pub的内容添加到自己github的ssh列表中即可。
五、安装git
发现没有预装git
sudo apt-get update
sudo apt-get install git-core
设置username和email
用ssh从我的github中随便拉一个项目到本地服务器
// todo
六、安装Golang环境
- 去
https://golang.google.cn/dl/
下载源码并解压到/usr/local
wget https://golang.google.cn/dl/go1.16.5.linux-amd64.tar.gz #根据操作系统的系统架构和要安装golang的版本选择合适的版本进行下载
tar -C /usr/local/ -xzf go1.16.5.linux-amd64.tar.gz
2. 将/usr/local/go/bin加入到系统环境变量
#可以直接在bash终端中敲,但是建议写入某个bashrc文件比如/etc/bash.bashrc,这样的话每次远程登录都会自动把这个路径加入环境变量中
export PATH=$PATH:/usr/local/go/bin
GOROOT是go的安装目录,一般为/usr/local/go
,GOPATH是工作目录,一般为~/go
我们去 $HOME目录下去创建 go/src go/pkg 和 go/bin
cd
mkdir -p go/src
mkdir -p go/pkg
mkdir -p go/bin
简单测试一下,没有什么问题
七、安装一些常用的工具:
如tree, curl, wget
apt-get install tree
# ls
go go1.16.5.linux-amd64.tar.gz MyCpp
# root @ iZ2ze61irhf5hpew9xk18eZ ~ [16:43:55]
# tree go
go
├── bin
├── pkg
└── src
└── hello
├── helloworld
└── helloworld.go
4 directories, 2 files
八、安装MySQL
debian系统安装mysql直接apt-get install即可
apt-get install mysql-server mysql-client
期间会弹出一个对话框设置本地mysql root用户的密码,然后就可以用设置的密码登录了