linux

Linux Development Environment Configuration for iSulad

Posted on 2020-07-12,14 min read

Virtual machine installation

qemu-img create -f raw -o size=120G Fedora_Server.img
virsh dumpxml {guest-id, guestname or uuid} > Fedora_Server.xml
virsh define Fedora_Server.xml
virsh start Fedora_Server
virsh vncdisplay Fedora_Server

Network Configuration

vim /etc/sysconfig/network-scripts/ifcfg-ens3
systemctl enable NetworkManager
systemctl start NetworkManager
proxy

Awesome Tools Installation

dnf upgrade -y 
dnf autoremove -y
dnf install -y vim htop the_silver_searcher fd-find bat exa ccze git tig 
dnf install -y fzf glances tmux ShellCheck ranger aria2 axel cloc task jq zsh npm
dnf install -y cmatrix screenfetch mariadb-server mariadb mycli
git config --global user.name username
git config --global user.email email@xxx.com
git config --global http.sslVerify false

dnf install npm
npm install -g diff-so-fancy
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
git config --global color.ui true
git config --global color.diff-highlight.oldNormal    "red bold"
git config --global color.diff-highlight.oldHighlight "red bold 52"
git config --global color.diff-highlight.newNormal    "green bold"
git config --global color.diff-highlight.newHighlight "green bold 22"

git config --global color.diff.meta       "11"
git config --global color.diff.frag       "magenta bold"
git config --global color.diff.commit     "yellow bold"
git config --global color.diff.old        "red bold"
git config --global color.diff.new        "green bold"
git config --global color.diff.whitespace "red reverse"
git config --bool --global diff-so-fancy.markEmptyLines false
git config --bool --global diff-so-fancy.changeHunkIndicators false
git config --bool --global diff-so-fancy.stripLeadingSymbols false
git config --bool --global diff-so-fancy.useUnicodeRuler false
git config --global diff-so-fancy.rulerWidth 47    # git log's commit header width
sh -c "$(curl -kfsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
cat ~/.zshrc
plugins=(git zsh-autosuggestions extract zsh-syntax-highlighting history-substring-search history zsh-256color vi-mode z wd taskwarrior)
# git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
# cd $ZSH_CUSTOM/plugins && git clone https://github.com/chrissicool/zsh-256color

vim plugins/history-substring-search/history-substring-search.plugin.zsh
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

vim plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=3'

git clone https://github.com/junegunn/fzf.git
./install
vim ~/.zshrc
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_COMMAND='fd --hidden --follow -E ".git" -E "node_modules" . /etc /home'
export FZF_DEFAULT_OPTS='--height 90% --layout=reverse --bind=alt-j:down,alt-k:up,alt-i:toggle+down --border --preview "(bat --style=numbers --color=always {}) 2> /dev/null | head -500" --preview-window=down'

# use fzf in bash and zsh
# Use ~~ as the trigger sequence instead of the default **
# export FZF_COMPLETION_TRIGGER=' f'
#

# Options to fzf command
#export FZF_COMPLETION_OPTS=''
#

# Use fd (https://github.com/sharkdp/fd) instead of the default find
# command for listing path candidates.
# - The first argument to the function ($1) is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
#
_fzf_compgen_path() {
  fd --hidden --follow -E ".git" -E "node_modules" . /etc /home
}

# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
  fd --type d --hidden --follow -E ".git" -E "node_modules" . /etc /home
}

dnf install -y ctags cscope global
dnf install -y neovim
pip2 install --no-cache-dir --upgrade --force-reinstall neovim
pip3 install --no-cache-dir --upgrade --force-reinstall neovim


vim ~/.zshrc
alias vi='nvim'
alias vim='nvim'

curl -ksLf https://spacevim.org/install.sh | bash
cat ~/.SpaceVim.d/init.toml
[options]
    # set spacevim theme. by default colorscheme layer is not loaded,
    # if you want to use more colorscheme, please load the colorscheme
    # layer
    # colorscheme = "gruvbox"
    colorscheme = "NeoSolarized"
    colorscheme_bg = "dark"
    # Disable guicolors in basic mode, many terminal do not support 24bit
    # true colors
    enable_guicolors = true
    # Disable statusline separator, if you want to use other value, please
    # install nerd fonts
    statusline_separator = "arrow"
    statusline_inactive_separator = "bar"
    buffer_index_type = 4
    windows_index_type = 3
    enable_statusline_mode = true
     # left sections of statusline
    statusline_left_sections = [
       'winnr',
       'major mode',
       'filename',
       'fileformat',
       'minor mode lighters',
       'version control info',
       'search status'
    ]
    # right sections of statusline
    statusline_right_sections = [
       'cursorpos',
       'percentage',
       'input method',
       'date',
       'time'
    ]

    enable_tabline_filetype_icon = true
    enable_statusline_display_mode = true
    statusline_unicode_symbols = true
    realtime_leader_guide = 1
    enable_statusline_tag = true
    # Enable vim compatible mode, avoid changing origin vim key bindings
    vimcompatible = true
    automatic_update = true
    enable_neomake = false
    # enable_ale = true
    filemanager = "defx"
    # enable_ycm = 1
    # autocomplete_method = "coc"

# Enable autocomplete layer
# [[layers]]
# name = 'autocomplete'
# autocomplete_method = "ycm"
# auto-completion-return-key-behavior = "complete"
# auto-completion-tab-key-behavior = "smart"
# enable = false

[[custom_plugins]]
  name = 'neoclide/coc.nvim'
  merge = 0
  build =  'yarn install --frozen-lockfile'

# [[layers]]
  # name = 'lsp'
  # filetypes = [
    # 'c',
    # 'cpp'
  # ]

# [layers.override_cmd]
  # c = ['ccls', '--log-file=/tmp/ccls.log']
  # cpp = ['ccls', '--log-file=/tmp/ccls.log']

[[layers]]
name = 'shell'
default_position = 'right'

# [[layers]]
# name = "cscope"

[[layers]]
name = "VersionControl"
enable-gtm-status = true

[[layers]]
name = "checkers"
show_cursor_error = false

[[layers]]
 name = "colorscheme"

# [[layers]]
# name = "debug"

# [[layers]]
# name = "floobits"

# [[layers]]
# name = "fzf"

[[layers]]
name = "git"
git-plugin = "fugitive"

# [[layers]]
#   name = "lang#c"
#   clang_executable = "/usr/bin/clang"
#   [layer.clang_std]
#     c = "c11"
#     cpp = "c++1z"

# [[layers]]
# name = "lang#go"

[[layers]]
  name = "tmux"
  # tmux_navigator_modifier = "alt"

[[layers]]
  name = "leaderf"

[[layers]]
  name = "sudo"

[[layers]]
  name = "tags"

[[layers]]
 name = "tools"

[[layers]]
 name = 'core'
 # filetree_show_hidden = true

# [[layers]]
#  name = "core#statusline"
#  enable = false

[[layers]]
  name = "ui"
  enable_sidebar = true

# [[layers]]
# name = "gtags"
# gtagslabel = "ctags"

# [custom_plugins]]
# name = "Shougo/dein.vim"

# [[custom_plugins]]
  # name = 'liuchengxu/vista.vim'
set tabstop=4
set expandtab
set shiftwidth=4
nnoremap <F9> :set invpaste paste?<CR>
set pastetoggle=<F9>
set showmode
set cmdheight=1

" let g:EasyMotion_do_mapping = 1

" filetype plugin indent on
" syntax enable
"
" Default value is "normal", Setting this option to "high" or "low" does use the
" same Solarized palette but simply shifts some values up or down in order to
" expand or compress the tonal range displayed.
let g:neosolarized_contrast = "normal"

" Special characters such as trailing whitespace, tabs, newlines, when displayed
" using ":set list" can be set to one of three levels depending on your needs.
" Default value is "normal". Provide "high" and "low" options.
let g:neosolarized_visibility = "normal"

" I make vertSplitBar a transparent background color. If you like the origin
" solarized vertSplitBar style more, set this value to 0.
let g:neosolarized_vertSplitBgTrans = 1

" If you wish to enable/disable NeoSolarized from displaying bold, underlined
" or italicized" typefaces, simply assign 1 or 0 to the appropriate variable.
" Default values:
let g:neosolarized_bold = 1
let g:neosolarized_underline = 1
let g:neosolarized_italic = 0

" Used to enable/disable "bold as bright" in Neovim terminal. If colors of bold
" text output by commands like `ls` aren't what you expect, you might want to
" try disabling this option. Default value:
let g:neosolarized_termBoldAsBright = 1
# coc.nvim config
reference: https://github.com/neoclide/coc.nvim
https://github.com/neoclide/coc.nvim/wiki
https://github.com/MaskRay/ccls/wiki
https://clangd.llvm.org/

# configurate for coc.nvim
Open config file with command :CocConfig
{
  "languageserver": {
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "cuda", "objc", "objcpp"],
      "rootPatterns": [".ccls-root", "compile_commands.json"],
      "initializationOptions": {
        "cache": {
          "directory": ".ccls-cache"
        },
        "client": {
          "snippetSupport": true
        }
      }
    }
  }
}

#Set project for coc.nvim(compile_commands.json and .ccls)
cmake -H. -BDebug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
ln -s Debug/compile_commands.json .

cat .ccls
%compile_commands.json
%c -std=c11
%cpp -std=c++14
%c %cpp -pthread
%h %hpp --include=Global.h
-Iinc
cd ~/.cache/vimfiles/repos/github.com/Valloric/YouCompleteMe
git submodule update --init --recursive
dnf install -y cmake python3-devel gcc-c++ clang golang
python3 install.py --clang-completer

cd /root/.SpaceVim
-----------------------------------------------
modified: config/plugins_before/YouCompleteMe.vim
-----------------------------------------------
@@ -1,4 +1,4 @@
-"let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
+let g:ycm_global_ycm_extra_conf = '~/.cache/vimfiles/repos/github.com/Valloric/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
 "let g:ycm_confirm_extra_conf = 0
 let g:ycm_collect_identifiers_from_tags_files =
       \ get(g:, 'ycm_collect_identifiers_from_tags_files', 1)
-----------------------------------------------
modified: vimrc
-----------------------------------------------
@@ -25,3 +25,9 @@ if 1
     execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
 endif

cat ~/.Spacevim/vimrc
 " vim:set et sw=2
+set tabstop=4
+set expandtab
+set shiftwidth=4
+nnoremap <F9> :set invpaste paste?<CR>
+set pastetoggle=<F9>
+set showmode

vim ~/.cache/vimfiles/repos/github.com/Valloric/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py
-----------------------------------------------
modified: .ycm_extra_conf.py
-----------------------------------------------
@@ -85,6 +85,18 @@ get_python_inc(),
 'cpp/ycm/tests/gmock/include',
 '-isystem',
 'cpp/ycm/benchmarks/benchmark/include',
+'-I',
+'/usr/local/include',
+'-I',
+'/usr/include',
+'-isystem',
+'/usr/lib/gcc/x86_64-redhat-linux/9/include',
+'-isystem',
+'/usr/include/c++/9',
+'-isystem',
+'/usr/include/c++/9/bits',
+'-isystem',
+'/usr/include/linux',
 ]

# oh-my-tmux
$ cd
$ git clone https://github.com/gpakosz/.tmux.git
$ ln -s -f .tmux/.tmux.conf
$ cp .tmux/.tmux.conf.local .

dnf install -y tmuxinator
echo "export EDITOR='vim'" >> ~/.zshrc
echo "source ~/.bin/.tmuxinator.zsh" >> ~/.zshrc
cat ~/.bin/.tmuxinator.zsh
#compdef _tmuxinator tmuxinator

_tmuxinator() {
  local commands projects
  commands=(${(f)"$(tmuxinator commands zsh)"})
  projects=(${(f)"$(tmuxinator completions start)"})

  if (( CURRENT == 2 )); then
    _alternative \
      'commands:: _describe -t commands "tmuxinator subcommands" commands' \
      'projects:: _describe -t projects "tmuxinator projects" projects'
  elif (( CURRENT == 3)); then
    case $words[2] in
      copy|cp|c|debug|delete|rm|open|o|start|s|edit|e)
        _arguments '*:projects:($projects)'
      ;;
    esac
  fi

  return
}

complete -F _tmuxinator tmuxinator mux
alias mux="tmuxinator"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et

tmuxinator new YOUR_PROJECT
tmuxinator edit YOUR_PROJECT
tmuxinator start YOUR_PROJECT
tmuxinator stop YOUR_PROJECT

vim ~/.tmux.conf
...
# replace C-b by C-a instead of using both prefixes
set-option -g prefix2 `

unbind '"'
bind - splitw -v
unbind %
bind | splitw -h
# move status line to top
set -g status-position bottom

cd ~/.tmux
mkdir plugins
git clone https://github.com/tmux-plugins/tmux-resurrect.git
cd ~/.tmux/plugins
git clone https://github.com/tmux-plugins/tmux-continuum.git

run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux
run-shell ~/.tmux/plugins/tmux-continuum/continuum.tmux

vim  ~/.tmux.conf
...
# set -g @continuum-save-interval '1440'
set -g @continuum-save-interval '0'
set -g @continuum-restore 'on'

terminal true-color support

xshell tools - configuation - advance - select using true-color
reference:https://github.com/icymind/NeoSolarized
https://gist.github.com/XVilka/8346728

code font: JetBrains Mono/Cascadia Code/Consolas
https://www.jetbrains.com/lp/mono/

dnf install -y ccls bear
if failed to install coc.nvim, execute yarn config set "strict-ssl" false -g

[coc.nvim] error: Some plugin change completeopt on insert mode
rm -rf find ~ -name 'deoplete*'

start iSulad on high Fedora version (eg:31)

# sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"    # use cgroup v1
# sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=1"    # use cgroup v2

$ sudo dnf install -y grubby
$ sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
$ sudo reboot

Developing/Debuging iSulad

dnf install valgrind gdb gdb-gdbserver tcpdump ystemtap ltrace strace
dnf group install 'Development Tools' 
dnf install gcc rpm-build rpm-devel rpmlint make python bash coreutils diffutils patch rpmdevtools

ulimit -c unlimited
echo "1" > /proc/sys/kernel/core_uses_pid
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern

valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --leak-resolution=high --show-reachable=yes --log-file=valgrind_memcheck.log -v isulad

iSulad Network Debug

openssl x509 -in cert.pem -noout -text
./testssl.sh IP:port
sslscan --tlsall IP:port
openssl s_client -connect IP:port
tcpdump port $port
tcpdump -i xxx port $port
tshark -i xxx