运维工具使用技巧

2018-07-19  本文已影响108人  9c46ece5b7bd

工欲善其事必先利其器,这里总结一些自己常用的工具集锦。

1. 本地环境命令行效率工具

$ alias dig='dig +short'
$ dig www.baidu.com
www.a.shifen.com.
220.181.111.188
220.181.112.244

$ alias l.='ls -d .* --color=auto'
$ alias ll='ls -l --color=auto'
$ alias ls='ls --color=auto'

# k8s环境下的自动补齐
$ source <(kubectl completion bash)
$ kubectl get
certificatesigningrequest  cronjob                    horizontalpodautoscaler    node                       podsecuritypolicy          secret                     storageclass
clusterrolebinding         daemonset                  ingress                    persistentvolume           podtemplate                service
componentstatus            deployment                 job                        persistentvolumeclaim      replicaset                 serviceaccount
configmap                  endpoints                  namespace                  pod                        replicationcontroller      statefulset
controllerrevision         event                      networkpolicy              poddisruptionbudget        rolebinding                status

2.本地环境开发效率工具

# 修改vimrc相关配置[追加到/etc/vimrc]
$ cat /etc/vimrc
let &guicursor = &guicursor . ",a:blinkon0"
set ts=4 sw=2 expandtab
set autoindent smartindent
set foldenable foldmethod=indent

"映射键盘中的上线左右键,使之选择文档中的屏幕行,而非实际行"
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
"if has("vms")
"  set nobackup
"  else
"    set backup
"endif

set guifont=Monospace\ 12

if has("autocmd")
    filetype on
    autocmd FileType python setlocal ts=2 sts=4 sw=2 et
    autocmd FileType shell setlocal ts=2 sw=4
endif
autocmd BufNewFile *.sh,*.py,*.pl,*.pm exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
    call setline(1,"\#!/bin/bash")
    call append(line("."), "#Filename:".expand("%:t"))
    call append(line(".")+1, "#Author_by:Andy_xu @JR-OPS ")
    call append(line(".")+2, "#Contact:[mail:xuxuebiao@jd.com,phone:18209247284,QQ:371990778]")
    call append(line(".")+3, "#Date:".strftime("%Y-%m-%d %H:%M"))
    call append(line(".")+4, "#Description:")
    call append(line(".")+5, "URL='http://pd.jd.com'")
elsei &filetype == 'python'
    call setline(1,"#!/usr/bin/env python")
    call append(line("."),"#-*- coding: utf-8 -*-")
    call append(line(".")+1, "#Author-by:\t\tAndy-xu @JR-OPS")
    call append(line(".")+2, "#Contact:  \t\temail:xuxuebiao@jd.com,phone:18209247284,QQ:371990778")
    call append(line(".")+3, "#Date:     \t\t".strftime("%Y-%m-%d %H:%M"))
    call append(line(".")+4, "#Description:\t\t")
elsei &filetype == 'perl'
    call setline(1,"#!/usr/bin/perl -w ")
    call append(line("."),"# coding=utf-8")
    call append(line(".")+1, "#Author-by:Andy-xu  @JR-OPS")
endif
endfunc

""配色方案
if has("gui_running")
    colorscheme darkblue
else
    colorscheme desert
endif

# 也可以修改用户自己的vim配置
$ cat ~/.vimrc
set ts=2 sw=4 expandtab
set wildmenu
set wildmode=longest,list
set history=200
autocmd bufnewfile *.{cpp,c,h,cc,hpp,cs,js,go} so /export/xuxuebiao/C.tmpl
autocmd bufnewfile *.{cpp,c,h,cc,hpp,cs,js,go} exe "1," . 7 . "g/File Name:.*/s//File Name: " .expand("%")
autocmd bufnewfile *.{cpp,c,h,cc,hpp,cs,js,go} exe "1," . 7 . "g/Create Date:.*/s//Create Date: " .strftime("%Y-%m-%d %H:%m:%S")
autocmd Bufwritepre,filewritepre *.{cpp,c,h,cc,hpp,cs,js,go} execute "normal ma"
autocmd Bufwritepre,filewritepre *.{cpp,c,h,cc,hpp,cs,js,go} exe "1," . 7 . "g/Last Modified:.*/s//Last Modified: " .strftime("%Y-%m-%d %H:%m:%S")
autocmd bufwritepost,filewritepost *.{cpp,c,h,cc,hpp,cs,js} execute "normal a"

上一篇 下一篇

猜你喜欢

热点阅读