Category Archives: DevTools

Windows 10下国内网络安装 minikube

Minikube 代理 Windows 10下环境下安装

最近在学习k8s,按照官方文档安装,遇到一些网络相关的问题,在这里记录下。

安装步骤参考这个链接, 坑在网络这一块,在国内网络环境下安装比较困难。

方案1

使用阿里云编译的支持Docker Mirror版本的,链接在这里

方案2

使用自己的梯子,以hyperv为例,SS开启了允许来自LAN的连接,Proxy的bypass关掉,可能需要打开防火墙端口。

  • 以管理员身份打开CMD
  • 启动minikube,这里虚拟机里面的docker要pull镜像,给docker-env设置代理 minikube start --vm-driver hyperv --hyperv-virtual-switch="minikube" --docker-env HTTP_PROXY=http://192.168.2.105:1080 --docker-env HTTPS_PROXY=http://192.168.2.105:1080,这个命令就可以。
  • 部署好之后,找到minikube的IP,把minikube ip%userprofile%\.minikube\machines\minikube\config.json里面Env一段,加上"NO_PROXY=localhost,192.0.0.0/24"

顺利的话,输出是下面这样的。

PS C:\WINDOWS\system32> minikube start  --vm-driver hyperv --hyperv-virtual-switch="minikube" --docker-env HTTP_PROXY=http://192.168.2.105:1080 --docker-env HTTPS_PROXY=http://192.168.2.105:1080
o   minikube v0.34.1 on windows (amd64)
>   Creating hyperv VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
-   "minikube" IP address is 192.168.2.116
-   Configuring Docker as the container runtime ...
- env HTTP_PROXY=http://192.168.2.105:1080
- env HTTPS_PROXY=http://192.168.2.105:1080
-   Preparing Kubernetes environment ...
-   Pulling images required by Kubernetes v1.13.3 ...
-   Launching Kubernetes v1.13.3 using kubeadm ...
-   Configuring cluster permissions ...
-   Verifying component health .....
+   kubectl is now configured to use "minikube"
=   Done! Thank you for using minikube!

遇到的问题

  • 安装成功了,但是访问网络有503错误

minikube ssh进去看到一个docker镜像没有启动起来,docker logs containerID查看错误(最终没有解决),删掉%userprofile%\.minikube整个目录,minikube delete然后重新用上面的start 脚本启用

  • 安装过程遇到问题

启用过程加--v=7把verbose级别调到debug,看输出的log

  • 虚拟机内部pull mirror报错

这个是proxy设置错了,可以先minikube stop,修改%userprofile%\.minikube\machines\minikube\config.json里面的配置,然后重新start

  • stop卡住,从hyperv manager进去,账号root,不需要密码,然后shutdown now

  • 提示TLS handshake timeout, 把NOPROXY配置加上

  • 其他

多(重)喝(启)热(试)水(试)

Hangfire 实践

Hangfire实践

Hangfire是一个执行background job的组件,支持.Net Framework和.Net Core。 在一些中小型的项目中,如果没有专门做background job的服务的话,使用Hangfire是一个不错的选择。因为其可以直接host在WebSite中,直接跟着网站发布即可。

配置

配置是非常方便的,参考官方文档即可, 基于OWIN的都可以。

存储方面,Hangfire支持MSSQL, Redis, Mongo等。 我们使用的Redis的,由于Redis需要Pro版本, 可以第三方开源版本,比如这个,基于StackExchange.Redis实现的,支持的.Net版本不是很全,由于代码并不复杂,不支持的版本自己编译下就好。 安装的时候会引入很多新的组件,使用的时候要留意与现有组件版本冲突。

任务类型

Hangfire可以处理多种类型的Job。

  • 即时任务
  • 延时任务
  • 循环任务

Pro版本支持批量的执行的一些特性。

即时任务,就是个消息队列,支持Queue的优先级,比如某个Queue优先级较高且里面有数据,则会优先把这个Queue里面的处理完成。

延时任务,就是个定时任务,本质上和上面的没什么区别,不过Hangfire把他们分开处理了,从Redis里面的数据可以看到他们的数据结构不同。

Continuations,这个功能可以多做些事情,比如失败了做一些额外的事情。

任务配置

Hangfire里面的任务都为Action类型,直接Enqueue时说明调用什么方法即可。 对于Generic接口的方法调用, 配置下就可以支持从IoC里面读取配置。如果IoC没有,且要用带参数的构造函数就比较惨,在ASP.NET Core里面,手动注册其实现方法。 IServiceCollection.AddTransient,应该是这个。

其他

  • 有个基础功能的Dashboard,如果要开启远程登陆,要配置Authentication
  • 支持Job的失败重试
  • 记得看Deployment to PROD那一段的说明!

Git bash alias config

SourceTree是一个功能很强大的Git GUI工具,但是就是太慢,且在Windows下会出现莫名占用一个核心CPU。于是开始折腾Git bash,目前基本够用。其中alias部分的配置文件如下,供参考,放到 /username/.gitconfig里面即可。

[alias]
l = log --pretty=format:"%C(yellow)%h %ad%Cred%d %Creset%s%Cblue [%cn]" --decorate --date=short
a = add
ap = add -p
c = commit --verbose
ca = commit -a --verbose
cm = commit -m
cam = commit -a -m
m = commit --amend --verbose
d = diff
ds = diff --stat
dc = diff --cached
s = status
ss = status -s
co = checkout
cob = checkout -b

list branches sorted by last modified

b = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"

list aliases

la = "!git config -l | grep alias | cut -c 7-"

其中我最喜欢的是git lg,附图2张,右键查看大图(一个“MD程序员”上镜)。
git lg
git lg2

更新Zsh的设置,看起来更有用

-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..
1='cd -'
2='cd -2'
3='cd -3'
4='cd -4'
5='cd -5'
6='cd -6'
7='cd -7'
8='cd -8'
9='cd -9'
_=sudo
afind='ack -il'
d='dirs -v | head -10'
g=git
ga='git add'
gaa='git add --all'
gap='git apply'
gapa='git add --patch'
gau='git add --update'
gb='git branch'
gba='git branch -a'
gbd='git branch -d'
gbda='git branch --no-color --merged | command grep -vE "^(*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
gbl='git blame -b -w'
gbnm='git branch --no-merged'
gbr='git branch --remote'
gbs='git bisect'
gbsb='git bisect bad'
gbsg='git bisect good'
gbsr='git bisect reset'
gbss='git bisect start'
gc='git commit -v'
'gc!'='git commit -v --amend'
gca='git commit -v -a'
'gca!'='git commit -v -a --amend'
gcam='git commit -a -m'
'gcan!'='git commit -v -a --no-edit --amend'
'gcans!'='git commit -v -a -s --no-edit --amend'
gcb='git checkout -b'
gcd='git checkout develop'
gcf='git config --list'
gcl='git clone --recursive'
gclean='git clean -fd'
gcm='git checkout master'
gcmsg='git commit -m'
'gcn!'='git commit -v --no-edit --amend'
gco='git checkout'
gcount='git shortlog -sn'
gcp='git cherry-pick'
gcpa='git cherry-pick --abort'
gcpc='git cherry-pick --continue'
gcs='git commit -S'
gcsm='git commit -s -m'
gd='git diff'
gdca='git diff --cached'
gdct='git describe --tags git rev-list --tags --max-count=1'
gdcw='git diff --cached --word-diff'
gdt='git diff-tree --no-commit-id --name-only -r'
gdw='git diff --word-diff'
gf='git fetch'
gfa='git fetch --all --prune'
gfo='git fetch origin'
gg='git gui citool'
gga='git gui citool --amend'
ggpull='git pull origin $(git_current_branch)'
ggpur=ggu
ggpush='git push origin $(git_current_branch)'
ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
ghh='git help'
gignore='git update-index --assume-unchanged'
gignored='git ls-files -v | grep "^[[:lower:]]"'
git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
gk='\gitk --all --branches'
gke='\gitk --all $(git log -g --pretty=%h)'
gl='git pull'
glg='git log --stat'
glgg='git log --graph'
glgga='git log --graph --decorate --all'
glgm='git log --graph --max-count=10'
glgp='git log --stat -p'
glo='git log --oneline --decorate'
glog='git log --oneline --decorate --graph'
gloga='git log --oneline --decorate --graph --all'
glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
glp=_git_log_prettily
glum='git pull upstream master'
gm='git merge'
gma='git merge --abort'
gmom='git merge origin/master'
gmt='git mergetool --no-prompt'
gmtvim='git mergetool --no-prompt --tool=vimdiff'
gmum='git merge upstream/master'
gp='git push'
gpd='git push --dry-run'
gpoat='git push origin --all && git push origin --tags'
gpristine='git reset --hard && git clean -dfx'
gpsup='git push --set-upstream origin $(git_current_branch)'
gpu='git push upstream'
gpv='git push -v'
gr='git remote'
gra='git remote add'
grb='git rebase'
grba='git rebase --abort'
grbc='git rebase --continue'
grbi='git rebase -i'
grbm='git rebase master'
grbs='git rebase --skip'
grep='grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}'
grh='git reset HEAD'
grhh='git reset HEAD --hard'
grmv='git remote rename'
grrm='git remote remove'
grset='git remote set-url'
grt='cd $(git rev-parse --show-toplevel || echo ".")'
gru='git reset --'
grup='git remote update'
grv='git remote -v'
gsb='git status -sb'
gsd='git svn dcommit'
gsi='git submodule init'
gsps='git show --pretty=short --show-signature'
gsr='git svn rebase'
gss='git status -s'
gst='git status'
gsta='git stash save'
gstaa='git stash apply'
gstc='git stash clear'
gstd='git stash drop'
gstl='git stash list'
gstp='git stash pop'
gsts='git stash show --text'
gsu='git submodule update'
gts='git tag -s'
gtv='git tag | sort -V'
gunignore='git update-index --no-assume-unchanged'
gunwip='git log -n 1 | grep -q -c "--wip--" && git reset HEAD~1'
gup='git pull --rebase'
gupv='git pull --rebase -v'
gwch='git whatchanged -p --abbrev-commit --pretty=medium'
gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "--wip-- [skip ci]"'
history='fc -l 1'
l='ls -lah'
la='ls -lAh'
ll='ls -lh'
ls='ls --color=tty'
lsa='ls -lah'
md='mkdir -p'
please=sudo
po=popd
pu=pushd
rd=rmdir
which-command=whence


Git cheat sheet

  • Replace crlf

git config core.autocrlf true

source

  • Remote branch delete

git push origin --delete <branchName>

source

  • Apply new gitignore

To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"

To undo git rm –cached filename, use git add filename

source

  • Undo all uncommitted changes

git checkout .

source

  • file log

Git log -1 -- file.name

  • fix error Cant't ref..

$ git gc --prune=now

$ git remote prune origin

source

  • 恢复误删除文件, notepad++ 把换行\r\n换成;一次执行多个文件
  1. Use git log –diff-filter=D –summary to get all the commits which have deleted files and the files deleted;
  2. Use git checkout $commit~1 filename to restore the deleted file.

source

  • Prevent gc

git config --global gc.auto 0

source

  • View file log

Gitk <filename>

source

  • Getting existing git branches to track remote branches

git branch --track origin/branch_name

[source](http://stackoverflow.com/questions/1184518/getting-existing-git-branches-to-track-remote-branches>

  • rollback git repo to specific commit

git reset --hard <tag/branch/commit id>
git checkout HEAD -- my-file.txt
source
source2
source3

  • Log search

git log --grep="Build 0051"

source

  • reverting specific commits from git
    $ git revert --no-commit b49eb8e 1d8b062
    Files that were modified in those 2 commits will be changed in your working directory
    If any of those 2 commits had changed ‘a’ then you could discard the revert for it:
    $ git checkout a
    $ git commit -a -m "Revert commits b49eb8e and 1d8b062"

source