OVERVIEW
- VMVareC++开发环境快速配置
- ip
- git
- vim
- github
- zsh
- gcc&g++&cmake
- ssh
- ifconfig
- mysql
- nginx
- redis
- gdb
VMVareC++开发环境快速配置
VMVareC++开发环境快速配置,为了省时间快速整理出文档方便以后快速配置,
按照这个流程直接可以快速得到一个舒适的C/C++开发环境,
ip
为了长期方便并且舒适使用该虚拟机,首先需要对虚拟机的ip进行配置,否则一段时间后再登录虚拟机ip地址可能会发生变化,
所以在VMWare中可直接配置以直接避免发生这种情况,修改DHCP租用时间为63天(最大实际长期有效)
git
注:某些clone操作需要科学上网工具,开启全局代理
sudo apt upgrade
sudo apt-get install git
vim
刚拿到手的虚拟机第一步肯定是马上vim编辑器了,否则连基本的文档编辑都无法进行怎么能行
sudo apt install vim
配置vim的个性化设置,看个人需要选择,
wget 47.93.11.51:88/install_vim.sh
bash install_vim.sh
install_vim.sh的内容:
#!/bin/bash
echo "This script will install and configure vim and zsh automatic."
echo "The time this takes is related to the network conditions, please wait patiently."
if [[ `whoami` == "root" ]];then
echo -e "\033[31mYou are running this script with Root\033[0m"
echo -e "\033[31mGenerally, we do not recommend using root for programming or directly controlling your Linux OS, especially when you are a beginner \033[0m"
echo -e "\033[31mSo, There is no necessary for you to configure with root."
read -p "Do you really want to do this?[N/y]" choice
if [[ ${choice} != y ]];then
echo "Bye."
exit 1
fi
fi
if which apt-get >/dev/null; then
sudo apt-get install -y vim universal-ctags xclip astyle python-setuptools git wget
elif which yum >/dev/null; then
sudo yum install -y gcc vim git ctags xclip astyle python-setuptools python-devel wget
fi
##Add HomeBrew support on Mac OS
if which brew >/dev/null;then
echo "You are using HomeBrew tool"
brew install vim ctags git astyle
fi
sudo easy_install -ZU autopep8
sudo ln -s /usr/bin/ctags /usr/local/bin/ctags
rm -rf ~/vim* 2>&1 >/dev/null
rm -rf ~/.vim* 2>&1 >/dev/null
mv -f ~/vim ~/vim_old
cd ~/ && git clone https://gitee.com/suyelu/vim.git
mv -f ~/.vim ~/.vim_old 2>&1 >/dev/null
mv -f ~/vim ~/.vim 2>&1 >/dev/null
mv -f ~/.vimrc ~/.vimrc_old 2>&1 >/dev/null
mv -f ~/.vim/.vimrc ~/
git clone https://gitee.com/suyelu/vundle.git ~/.vim/bundle/vundle
echo "程序正在自动安装相应插件" > kaikeba
echo "command-t插件需要等待时间较长,不要担心" >> kaikeba
echo "切勿强制退出该界面,否则会导致错误,需重新配置" >> kaikeba
echo "安装完毕将自动退出" >> kaikeba
echo "请耐心等待" >> kaikeba
vim kaikeba -c "BundleInstall" -c "q" -c "q"
rm kaikeba
echo "安装完成"
.vimrc的配置:
set sw=4
set ts=4
set et
set smarttab
set smartindent
set lbr
set fo+=mB
set sm
set selection=inclusive
set wildmenu
set mousemodel=popup
au FileType php setlocal dict+=~/.vim/dict/php_funclist.dict
au FileType css setlocal dict+=~/.vim/dict/css.dict
au FileType c setlocal dict+=~/.vim/dict/c.dict
au FileType cpp setlocal dict+=~/.vim/dict/cpp.dict
au FileType scale setlocal dict+=~/.vim/dict/scale.dict
au FileType javascript setlocal dict+=~/.vim/dict/javascript.dict
au FileType html setlocal dict+=~/.vim/dict/javascript.dict
au FileType html setlocal dict+=~/.vim/dict/css.dict
"
"syntastic相关
execute pathogen#infect()
let g:syntastic_python_checkers=['pylint']
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd']
"golang
"Processing... % (ctrl+c to stop)
let g:fencview_autodetect=0
set rtp+=$GOROOT/misc/vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 显示相关
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
set cul "高亮光标所在行
set cuc
set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示
set go= " 不要图形按钮
"color desert " 设置背景主题
color ron " 设置背景主题
"color torte " 设置背景主题
"set guifont=Courier_New:h10:cANSI " 设置字体
"autocmd InsertLeave * se nocul " 用浅色高亮当前行
autocmd InsertEnter * se cul " 用浅色高亮当前行
set ruler " 显示标尺
set showcmd " 输入的命令显示出来,看的清楚些
"set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议)
set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容
set laststatus=2 " 启动显示状态行(1),总是显示状态行(2)
"set foldenable " 允许折叠
""set foldmethod=manual " 手动折叠
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
" 显示中文帮助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 使用空格代替制表符
set expandtab
" 在行和段开始处使用制表符
set smarttab
" 显示行号
set number
" 历史记录数
set history=1000
"搜索逐字符高亮
set hlsearch
set incsearch
"语言设置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 总是显示状态行
set cmdheight=2
" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 字符间插入的像素行数目
"markdown配置
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd
au BufRead,BufNewFile *.{go} set filetype=go
au BufRead,BufNewFile *.{js} set filetype=javascript
"rkdown to HTML
nmap md :!~/.vim/markdown.pl % > %.html <CR><CR>
nmap fi :!firefox %.html & <CR><CR>
nmap \ \cc
vmap \ \cc
"将tab替换为空格
nmap tt :%s/\t/ /g<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件标题
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#!/bin/bash")
call append(line("."), "")
elseif &filetype == 'python'
call setline(1,"#!/usr/bin/env python")
call append(line("."),"# coding=utf-8")
call append(line(".")+1, "")
elseif &filetype == 'ruby'
call setline(1,"#!/usr/bin/env ruby")
call append(line("."),"# encoding: utf-8")
call append(line(".")+1, "")
" elseif &filetype == 'mkd'
" call setline(1,"<head><meta charset=\"UTF-8\"></head>")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: luochenhao")
call append(line(".")+2, " > Mail: 3453851623@qq.com")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if expand("%:e") == 'cpp'
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
if expand("%:e") == 'h'
call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
call append(line(".")+8, "#endif")
endif
if &filetype == 'java'
call append(line(".")+6,"public class ".expand("%:r"))
call append(line(".")+7,"")
endif
"新建文件后,自动定位到文件末尾
endfunc
autocmd BufNewFile * normal G
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:nmap <silent> <F9> <ESC>:Tlist<RETURN>
" shift tab pages
map <S-Left> :tabp<CR>
map <S-Right> :tabn<CR>
map! <C-Z> <Esc>zzi
map! <C-O> <C-Y>,
map <C-A> ggVG$"+y
map <F12> gg=G
map <C-w> <C-w>w
imap <C-k> <C-y>,
imap <C-t> <C-q><TAB>
imap <C-j> <ESC>
" 选中状态下 Ctrl+c 复制
"map <C-v> "*pa
imap <C-v> <Esc>"*pa
imap <C-a> <Esc>^
imap <C-e> <Esc>$
vmap <C-c> "+y
set mouse=v
"set clipboard=unnamed
"去空行
nnoremap <F2> :g/^\s*$/d<CR>
"比较文件
nnoremap <C-F2> :vert diffsplit
"nnoremap <Leader>fu :CtrlPFunky<Cr>
"nnoremap <C-n> :CtrlPFunky<Cr>
"列出当前目录文件
map <F3> :NERDTreeToggle<CR>
imap <F3> <ESC> :NERDTreeToggle<CR>
"打开树状文件目录
map <C-F3> \be
:autocmd BufRead,BufNewFile *.dot map <F5> :w<CR>:!dot -Tjpg -o %<.jpg % && eog %<.jpg <CR><CR> && exec "redr!"
"C,C++ 按F5编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
exec "!time python2.7 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
" exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc
"C,C++的调试
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
exec "!gdb ./%<"
endfunc
"代码格式优化化
map <F6> :call FormartSrc()<CR><CR>
"定义FormartSrc()
func FormartSrc()
exec "w"
if &filetype == 'c'
exec "!astyle --style=ansi -a --suffix=none %"
elseif &filetype == 'cpp' || &filetype == 'hpp'
exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1"
elseif &filetype == 'perl'
exec "!astyle --style=gnu --suffix=none %"
elseif &filetype == 'py'||&filetype == 'python'
exec "r !autopep8 -i --aggressive %"
elseif &filetype == 'java'
exec "!astyle --style=java --suffix=none %"
elseif &filetype == 'jsp'
exec "!astyle --style=gnu --suffix=none %"
elseif &filetype == 'xml'
exec "!astyle --style=gnu --suffix=none %"
else
exec "normal gg=G"
return
endif
exec "e! %"
endfunc
"结束定义FormartSrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""实用设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("autocmd")
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif
"当打开vim且没有文件时自动打开NERDTree
autocmd vimenter * if !argc() | NERDTree | endif
" 只剩 NERDTree时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" 设置当文件被改动时自动载入
set autoread
" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
"代码补全
set completeopt=preview,menu
"允许插件
"filetype plugin on
"共享剪贴板
"set clipboard+=unnamed
"自动保存
set autowrite
"set ruler " 打开状态栏标尺
"set cursorline " 突出显示当前行
set magic " 设置魔术
set guioptions-=T " 隐藏工具栏
set guioptions-=m " 隐藏菜单栏
""set foldcolumn=0
""set foldmethod=indent
""set foldlevel=3
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" 去掉输入错误的提示声音
set noeb
" 在处理未保存或只读文件的时候,弹出确认
set confirm
"禁止生成临时文件
set nobackup
set noswapfile
"搜索忽略大小写
set ignorecase
set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 为C程序提供自动缩进
"自动补全
"":inoremap ( ()<ESC>i
"":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
"":inoremap [ []<ESC>i
"":inoremap ] <c-r>=ClosePair(']')<CR>
"":inoremap " ""<ESC>i
"":inoremap ' ''<ESC>i
""function! ClosePair(char)
"" if getline('.')[col('.') - 1] == a:char
"" return "\<Right>"
"" else
"" return a:char
"" endif
""endfunction
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags的设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Sort_Type = "name" " 按照名称排序
let Tlist_Use_Right_Window = 1 " 在右侧显示窗口
let Tlist_Compart_Format = 1 " 压缩方式
let Tlist_Exist_OnlyWindow = 1 " 如果只有一个buffer,kill窗口也kill掉buffer
""let Tlist_File_Fold_Auto_Close = 0 " 不要关闭其他文件的tags
""let Tlist_Enable_Fold_Column = 0 " 不要显示折叠树
"let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的
"设置tags
set tags=tags;
set autochdir
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"其他东东
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"默认打开Taglist
let Tlist_Auto_Open=0
""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口
" minibufexpl插件的一般设置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
nmap tl :Tlist<cr>
"python补全
let g:pydiction_location = '~/.vim/after/complete-dict'
let g:pydiction_menu_height = 20
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
set iskeyword+=.
set termencoding=utf-8
set encoding=utf8
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030
autocmd FileType python set omnifunc=pythoncomplete#Complete
"set nocompatible " be iMproved
"filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'https://gitee.com/suyelu/vundle'
" My Bundles here:
"
" original repos on github
Bundle 'https://gitee.com/suyelu/vim-fugitive'
Bundle 'https://gitee.com/suyelu/sparkup', {'rtp': 'vim/'}
Bundle 'https://gitee.com/suyelu/indentLine'
let g:indentLine_char = '┊'
"ndle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'https://gitee.com/suyelu/L9'
Bundle 'https://gitee.com/suyelu/FuzzyFinder'
" non github repos
Bundle 'https://gitee.com/suyelu/command-t'
Bundle 'https://gitee.com/suyelu/Auto-Pairs'
Bundle 'https://gitee.com/suyelu/python-imports.vim'
Bundle 'https://gitee.com/suyelu/CaptureClipboard'
Bundle 'https://gitee.com/suyelu/ctrlp-modified.vim'
Bundle 'https://gitee.com/suyelu/last_edit_marker.vim'
Bundle 'https://gitee.com/suyelu/synmark.vim'
"Bundle 'Python-mode-klen'
Bundle 'https://gitee.com/suyelu/SQLComplete.vim'
Bundle 'https://gitee.com/suyelu/Javascript-OmniCompletion-with-YUI-and-j'
"Bundle 'JavaScript-Indent'
"Bundle 'Better-Javascript-Indentation'
Bundle 'https://gitee.com/suyelu/jslint.vim'
Bundle "https://gitee.com/suyelu/vim-javascript"
Bundle 'https://gitee.com/suyelu/Vim-Script-Updater'
Bundle 'https://gitee.com/suyelu/ctrlp.vim'
Bundle 'https://gitee.com/suyelu/ctrlp-funky'
Bundle 'https://gitee.com/suyelu/jsbeautify'
Bundle 'https://gitee.com/suyelu/The-NERD-Commenter'
"django
Bundle 'https://gitee.com/suyelu/django_templates.vim'
Bundle 'https://gitee.com/suyelu/Django-Projects'
"Bundle 'FredKSchott/CoVim'
"Bundle 'djangojump'
" ...
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
filetype plugin indent on " required!
"
"ctrlp设置
"
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.png,*.jpg,*.gif " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe,*.pyc,*.png,*.jpg,*.gif " Windows
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = '\v\.(exe|so|dll)$'
let g:ctrlp_extensions = ['funky']
let NERDTreeIgnore=['\.pyc']
set tags+=~/.vim/systags
github
github访问优化,打开hosts文件,并在最后加入以下两行信息,
sudo vim /etc/hosts
199.232.69.194 github.global.ssl.fastly.net
140.82.112.4 github.com
zsh
sudo apt install zsh #安装zsh
chsh -s /bin/zsh #修改默认shell为zsh
# 安装oh-my-zsh
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
# 安装zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# 使用命令vim 打开.zshrc文件,找到plugins=()这一行,将zsh-syntax-highlighting添加进去
plugins=(git zsh-syntax-highlighting)
##命令自动补全插件
mkdir ~/.oh-my-zsh/plugins/incr
wget http://mimosa-pudica.net/src/incr-0.2.zsh -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh
##命令自动推荐,根据历史记录
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
##目录自动跳转插件
sudo apt install autojump
# 使用命令vim打开.zshrc,打开后在最后插入以下内容:
#设置终端颜色,提示符,及上一条指令返回码提示
autoload -U colors && colors
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%1~ %{$reset_color%}%# "
RPROMPT="[%{$fg[yellow]%}%?%{$reset_color%}]"
# Useful support for interacting with Terminal.app or other terminal programs
[ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"
source ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
source /usr/share/autojump/autojump.sh
source ~/.oh-my-zsh/plugins/incr/incr*.zsh
gcc&g++&cmake
做Linux下的C/C++开发,gcc和g++肯定是必备的,这个命令将会安装一系列软件包,包括gcc,g++,和make。
sudo apt install build-essential
安装关于如何使用 GNU/Linux开发的手册。
sudo apt-get install manpages-dev
sudo apt install cmake
ssh
为了方便使用xshell或者vscode连接虚拟机,进行远程开发需要安装ssh服务,并开放相应的端口号,
安装ssh服务器
sudo apt install openssh-server
安装ssh客户端
sudo apt install openssh-client
sudo vim /etc/ssh/ssh_config
配置ssh客户端,去掉PasswordAuthentication yes前面的#号,保存退出
sudo vim /etc/ssh/sshd_config
配置ssh服务器,把PermitRootLogin prohibit-password改成PermitRootLogin yes,保存退出。
sudo /etc/init.d/ssh restart
重启ssh服务
ifconfig
sudo apt install net-tools -y
mysql
- 安装mysql
sudo apt-get -y install mysql-server
sudo apt-get -y install mysql-client
sudo apt-get -y install libmysqlclient-dev
sudo netstat -tap | grep mysql
sudo lsof -i:3306
- 修改或设置mysql密码:/etc/mysql/debian.cnf(根据mysql版本不同可能会自动生成密码 or 不生成)
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = MJQIewl5kQ6RwmOA
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = MJQIewl5kQ6RwmOA
socket = /var/run/mysqld/mysqld.sock
根据mysql自动生成提供的用户与密码进入mysql,修改root用户密码,
mysql -u debian-sys-maint -p
MJQIewl5kQ6RwmOA
update mysql.user set authentication_string=password('123456') where user='root'
quit
service mysql restart
sudo mysql -u root -p 直接按回车登录然后设置密码
use mysql; 然后敲回车(注意下面字母的大小写)
# 更新 plugin 及 authentication_string 字段,比如密码123456
UPDATE user SET plugin="mysql_native_password", authentication_string=PASSWORD("123456") WHERE user="root";
# 输出以下结果
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
# 保存更新结果
FLUSH PRIVILEGES;
# 退出并重启 mysql
exit;
sudo service mysql restart
service mysql start //启动mysql
service mysql restart //重新启动mysql
service mysql stop //关闭mysql
nginx
- Nginx安装方式1:
# nginx工作时候需要依赖三个库
# 三个参数=这三个库对应的源码安装目录
# 具体目录需要根据自己的电脑的库安装包的位置进行指定
./configure --with-openssl=../openssl-1.0.1t --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11
make
sudo make install
- Nginx安装方式2:
# 安装必要的第三方依赖包
sudo apt-get -y install libpcre3 libpcre3-dev
sudo apt-get -y install zlib1g-dev
sudo apt-get install openssl libssl-dev
# 下载比较新的稳定版本,自己放到合适的位置
wget http://nginx.org/download/nginx-1.16.1.tar.gz
# 解压配置编译安装
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx
make
sudo make install
Nginx的默认安装目录
/usr/local/nginx
conf -> 存储配置文件的目录
html -> 默认的存储网站(服务器)静态资源的目录 [图片, html, js, css]
logs -> 存储log日志
sbin -> 启动nginx的可执行程序
Nginx可执行程序的路径
/usr/local/nginx/sbin/nginx
# 快速启动的方式
# 1. 将/usr/local/nginx/sbin/添加到环境变量PATH中
# 2. /usr/local/nginx/sbin/nginx创建软连接, 放到PATH对应的路径中, 比如: /usr/bin
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
- Nginx启动命令
# 启动nginx
sudo nginx # 启动
ps -ef | grep nginx # 查看nginx运行状态
# 关闭nginx
sudo nginx -s stop # 第一种, 马上关闭
sudo nginx -s quit # 第二种, 等nginx做完本次操作之后关闭
# 重新加载nginx
sudo nginx -s reload # 修改了nginx的配置文件之后, 需要执行该命令
# 启动
sudo systemctl start nginx.service
# 停止
sudo systemctl stop nginx.service
# 重新加载
sudo systemctl reload nginx.service
# 显示nginx服务的状态
systemctl status nginx.service
# 在开机时启用nginx服务
sudo systemctl enable nginx.service
# 在开机时禁用nginx服务
sudo systemctl disable nginx.service
- Nginx启动配置
# 在 /lib/systemd/system/目录下面新建一个nginx.service文件。并赋予可执行的权限,
sudo vim /lib/systemd/system/nginx.service
# 编辑service内容
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
# 在启动服务之前,需要先重载systemctl命令
sudo systemctl daemon-reload
# 启动nginx
sudo systemctl start nginx.service
# 最后使用sudo ps -ef | grep nginx 查看是否有相应的nginx进程启动(包含master process、与worker process)
sudo ps -ef | grep nginx
redis
redis安装
wget http://download.redis.io/releases/redis-6.2.5.tar.gz
tar -zxvf redis-6.2.5.tar.gz
cd redis-6.2.5
make
# 安装依赖
cd deps
make hiredis linenoise lua jemalloc
cd hiredis
sudo make install
cd ../lua
sudo make install
# 安装redis
cd ../../src
sudo make install
sudo lsof -i:6379
redis配置文件
# redis服务器绑定谁之后, 谁就能访问redis服务器
# 任何客户端都能访问服务器, 需要注释该选项
bind 127.0.0.1 192.168.1.100
# 保护模式, 如果要远程客户端访问服务器, 该模式要关闭
protected-mode yes
# reids服务器启动时候绑定的端口, 默认为6379
port 6379
# 超时时长, 0位关闭该选项, >0则开启
timeout 0
# 服务器启动之后不是守护进程
daemonize no
# 如果服务器是守护进程, 就会生成一个pid文件
# ./ -> reids服务器启动时候对应的目录
pidfile ./redis.pid
# 日志级别
loglevel notice
# 如果服务器是守护进程, 才会写日志文件
logfile "" -> 这是没写
logfile ./redis.log
# redis中数据库的个数
databases 16
- 切换 select dbID [dbID == 0 ~ 16-1]
redis常用命令
# 服务器 - 启动
redis-server # 默认启动
redis-server confFileName # 根据配置文件的设置启动
# 客户端
redis-cli # 默认连接本地, 绑定了6379默认端口的服务器
redis-cli -p 端口号
redis-cli -h IP地址 -p 端口 # 连接远程主机的指定端口的redis
# 通过客户端关闭服务器
shutdown
# 客户端的测试命令
ping [MSG]
gdb
其实gdb自从8.3版本之后就已经默认支持了彩色显示,并且默认已经启用了,所以查看地址、文件名等符号时都是彩色的。
但是Ubuntu仓库中编译的gdb并没有启用代码高亮功能,运行help set style sources
他会告诉你it was not linked against GNU Source Highlight
,只有半吊子功能。想要真正的高亮,还得自己编译。
-
下载g++、make、autoconf等编译工具,不需多言。
-
安装高亮支持库:
sudo apt install libsource-highlight-dev
-
下载最新版的gdb .tar.xz源码http://ftp.gnu.org/gnu/gdb/并解压。
-
默认的
esc
高亮对黑色背景终端界面非常不友好,最好改成esc256
,具体做法是修改源码中的gdb/source-cache.c
文件,修改如下位置if (highlighter == nullptr) { - highlighter = new srchilite::SourceHighlight ("esc.outlang"); - highlighter->setStyleFile ("esc.style"); + highlighter = new srchilite::SourceHighlight ("esc256.outlang"); + highlighter->setStyleFile ("esc256.style"); } std::istringstream input (contents);
-
编译gdb并安装(假设安装到
/opt/gdb/
目录)cd <gdb源码目录> mkdir build cd build ../configure --prefix=/opt/gdb make -j $(nproc) sudo make install
-
最终在
/opt/gdb/bin/
目录会输出gdb
和gdbserver
等可执行文件,运行这里的gdb,代码高亮便默认启用了。方便起见,可以将该目录添加到PATH环境变量。