-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.json
1 lines (1 loc) · 347 KB
/
index.json
1
[{"categories":["Editor"],"contents":"Hi there, as the refer article author said, it is 2019, but now, me, 2020.\nwe use YCM for years, but with the introduction of Language Server Protocol(LSP),\nthere are new options worth exploring, I tried on OSX and ArchLinux, it\u0026rsquo;s great for me, maybe it\u0026rsquo;ll fit you too.\n Reference: https://octetz.com/docs/2019/2019-04-24-vim-as-a-go-ide/\n Go\u0026rsquo;s offical LSP is gopls, pronounced \u0026ldquo;go please\u0026rdquo;.\nPrerequisites vim or neovim, this article covers vim. yarn installed for coc.nvim. vim-plug installed $GOPATH and $GOBIN set, see: https://golang.org/cmd/go/#hdr-Environment_variables go env -w GOBIN=\u0026quot;/home/\u0026lt;username\u0026gt;/go/bin\u0026quot; vim config file: ~/.config/nvim/init.vim is neovim\u0026rsquo;s and ~/.vimrc is vim\u0026rsquo;s. Install vim-go rm YCM, rm the line in .vimrc and save, then: :PlugClean Add config: call plug#begin(\u0026#39;~/.vim/plugged\u0026#39;) \u0026#34; \u0026lt; Other Plugins, if they exist \u0026gt; Plug \u0026#39;fatih/vim-go\u0026#39; call plug#end()\u0026#34; vim +PlugInstall and vim +GoInstallBinaries vim a go file to verify vim-go working well. Install coc.nvim call plug#begin(\u0026#39;~/.vim/plugged\u0026#39;) \u0026#34; \u0026lt; Other Plugins, if they exist \u0026gt; Plug \u0026#39;fatih/vim-go\u0026#39; Plug \u0026#39;neoclide/coc.nvim\u0026#39;, {\u0026#39;do\u0026#39;: \u0026#39;yarn install --frozen-lockfile\u0026#39;} call plug#end()\u0026#34; :PlugInstall Copy the following into .vimrc:\n\u0026#34; ------------------------------------------------------------------------------------------------- \u0026#34; coc.nvim default settings \u0026#34; ------------------------------------------------------------------------------------------------- \u0026#34; if hidden is not set, TextEdit might fail. set hidden \u0026#34; Better display for messages set cmdheight=2 \u0026#34; Smaller updatetime for CursorHold \u0026amp; CursorHoldI set updatetime=300 \u0026#34; don\u0026#39;t give |ins-completion-menu| messages. set shortmess+=c \u0026#34; always show signcolumns set signcolumn=yes \u0026#34; Use tab for trigger completion with characters ahead and navigate. \u0026#34; Use command \u0026#39;:verbose imap \u0026lt;tab\u0026gt;\u0026#39; to make sure tab is not mapped by other plugin. inoremap \u0026lt;silent\u0026gt;\u0026lt;expr\u0026gt; \u0026lt;TAB\u0026gt; \\ pumvisible() ? \u0026#34;\\\u0026lt;C-n\u0026gt;\u0026#34; : \\ \u0026lt;SID\u0026gt;check_back_space() ? \u0026#34;\\\u0026lt;TAB\u0026gt;\u0026#34; : \\ coc#refresh() inoremap \u0026lt;expr\u0026gt;\u0026lt;S-TAB\u0026gt; pumvisible() ? \u0026#34;\\\u0026lt;C-p\u0026gt;\u0026#34; : \u0026#34;\\\u0026lt;C-h\u0026gt;\u0026#34; function! s:check_back_space() abort let col = col(\u0026#39;.\u0026#39;) - 1 return !col || getline(\u0026#39;.\u0026#39;)[col - 1] =~# \u0026#39;\\s\u0026#39; endfunction \u0026#34; Use \u0026lt;c-space\u0026gt; to trigger completion. inoremap \u0026lt;silent\u0026gt;\u0026lt;expr\u0026gt; \u0026lt;c-space\u0026gt; coc#refresh() \u0026#34; Use `[c` and `]c` to navigate diagnostics nmap \u0026lt;silent\u0026gt; [c \u0026lt;Plug\u0026gt;(coc-diagnostic-prev) nmap \u0026lt;silent\u0026gt; ]c \u0026lt;Plug\u0026gt;(coc-diagnostic-next) \u0026#34; Remap keys for gotos nmap \u0026lt;silent\u0026gt; gd \u0026lt;Plug\u0026gt;(coc-definition) nmap \u0026lt;silent\u0026gt; gy \u0026lt;Plug\u0026gt;(coc-type-definition) nmap \u0026lt;silent\u0026gt; gi \u0026lt;Plug\u0026gt;(coc-implementation) nmap \u0026lt;silent\u0026gt; gr \u0026lt;Plug\u0026gt;(coc-references) \u0026#34; Use U to show documentation in preview window nnoremap \u0026lt;silent\u0026gt; U :call \u0026lt;SID\u0026gt;show_documentation()\u0026lt;CR\u0026gt; \u0026#34; Remap for rename current word nmap \u0026lt;leader\u0026gt;rn \u0026lt;Plug\u0026gt;(coc-rename) \u0026#34; Remap for format selected region vmap \u0026lt;leader\u0026gt;f \u0026lt;Plug\u0026gt;(coc-format-selected) nmap \u0026lt;leader\u0026gt;f \u0026lt;Plug\u0026gt;(coc-format-selected) \u0026#34; Show all diagnostics nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;a :\u0026lt;C-u\u0026gt;CocList diagnostics\u0026lt;cr\u0026gt; \u0026#34; Manage extensions nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;e :\u0026lt;C-u\u0026gt;CocList extensions\u0026lt;cr\u0026gt; \u0026#34; Show commands nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;c :\u0026lt;C-u\u0026gt;CocList commands\u0026lt;cr\u0026gt; \u0026#34; Find symbol of current document nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;o :\u0026lt;C-u\u0026gt;CocList outline\u0026lt;cr\u0026gt; \u0026#34; Search workspace symbols nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;s :\u0026lt;C-u\u0026gt;CocList -I symbols\u0026lt;cr\u0026gt; \u0026#34; Do default action for next item. nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;j :\u0026lt;C-u\u0026gt;CocNext\u0026lt;CR\u0026gt; \u0026#34; Do default action for previous item. nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;k :\u0026lt;C-u\u0026gt;CocPrev\u0026lt;CR\u0026gt; \u0026#34; Resume latest coc list nnoremap \u0026lt;silent\u0026gt; \u0026lt;space\u0026gt;p :\u0026lt;C-u\u0026gt;CocListResume\u0026lt;CR\u0026gt; more info about config above: coc.nvim\u0026rsquo;s recommendations.\ncopy or modify following to tell vim-go to not map gb as its shortcut for go definition.\n\u0026#34; disable vim-go :GoDef short cut (gd) \u0026#34; this is handled by LanguageClient [LC] let g:go_def_mapping_enabled = 0 this is disabled to allow coc.vim to do the gd resolution.\nOK, save and exit vim\nInstall coc.nvim: vim +PlugInstall\nmy output:\nyarn install v1.22.4 [1/5] Validating package.json... [2/5] Resolving packages... [3/5] Fetching packages... info fsevents@2.1.3: The platform \u0026#34;linux\u0026#34; is incompatible with this module. info \u0026#34;fsevents@2.1.3\u0026#34; is an optional dependency and failed compatibility check. Excluding it from installation. [4/5] Linking dependencies... warning \u0026#34; \u0026gt; @typescript-eslint/eslint-plugin@2.33.0\u0026#34; has incorrect peer dependency \u0026#34;eslint@^5.0.0 || ^6.0.0\u0026#34;. warning \u0026#34; \u0026gt; @typescript-eslint/eslint-plugin-tslint@2.33.0\u0026#34; has incorrect peer dependency \u0026#34;eslint@^5.0.0 || ^6.0.0\u0026#34;. warning \u0026#34; \u0026gt; @typescript-eslint/eslint-plugin-tslint@2.33.0\u0026#34; has unmet peer dependency \u0026#34;tslint@^5.0.0 || ^6.0.0\u0026#34;. warning \u0026#34; \u0026gt; @typescript-eslint/parser@2.33.0\u0026#34; has incorrect peer dependency \u0026#34;eslint@^5.0.0 || ^6.0.0\u0026#34;. [5/5] Building fresh packages... warning Your current version of Yarn is out of date. The latest version is \u0026#34;1.22.5\u0026#34;, while you\u0026#39;re on \u0026#34;1.22.4\u0026#34;. info To upgrade, run the following command: $ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash $ npm-run-all clean build yarn run v1.22.4 $ rimraf lib build Done in 0.11s. yarn run v1.22.4 $ tsc -p tsconfig.json Done in 6.46s. Done in 37.76s. Edit the CocConfig: :CocConfig\n{ \u0026#34;languageserver\u0026#34;: { \u0026#34;golang\u0026#34;: { \u0026#34;command\u0026#34;: \u0026#34;gopls\u0026#34;, \u0026#34;rootPatterns\u0026#34;: [\u0026#34;go.mod\u0026#34;, \u0026#34;.vim/\u0026#34;, \u0026#34;.git/\u0026#34;, \u0026#34;.hg/\u0026#34;], \u0026#34;filetypes\u0026#34;: [\u0026#34;go\u0026#34;] } } } restart vim. ok, me done. what about u?\n","permalink":"https://huifeng.me/posts/vimuselspandvimgormycm/","tags":["vim","lsp","vim-go","ycm"],"title":"Vim Switch YCM to LSP, coc.nvim And Vimgo"},{"categories":null,"contents":"# 题目:Do you know IPFS? # Writeup 0. Do you know IPFS? ( flag = flag{.*} len(flag) = 0x26 , The form of flag is lowercase) 1. 通过ipfs获取所有资源pic1的资源文件 # pic1.jpg ipfs get QmZkF524d8HWfF8k2yLrZwFz9PtaYgCwy3UqJP5Ahk5aXH ipfs get Qme7fkoP2scbqRPaVv6JEiaMjcPZ58NYMnUxKAvb2paey2 ipfs get QmU59LjvcC1ueMdLVFve8je6vBY48vkEYDQZFiAbpgX9mf ipfs get QmXh6p3DGKfvEVwdvtbiH7SPsmLDfL7LXrowAZtQjkjw73 ipfs get QmXFSNiJ8BdbUKPAsu3oueziyYqeYhi3iyQPXgVSvqTBtN ipfs get QmfUbHZQ95XKu9vd5XCerhKPsogRdYHkwx8mVFh5pwfNzE 2. 拼图并获得 pic1 的 hash mv QmXh6p3DGKfvEVwdvtbiH7SPsmLDfL7LXrowAZtQjkjw73 1 mv QmXFSNiJ8BdbUKPAsu3oueziyYqeYhi3iyQPXgVSvqTBtN 6 mv QmZkF524d8HWfF8k2yLrZwFz9PtaYgCwy3UqJP5Ahk5aXH 2 mv Qme7fkoP2scbqRPaVv6JEiaMjcPZ58NYMnUxKAvb2paey2 3 mv QmU59LjvcC1ueMdLVFve8je6vBY48vkEYDQZFiAbpgX9mf 4 mv QmfUbHZQ95XKu9vd5XCerhKPsogRdYHkwx8mVFh5pwfNzE 5 用 cat 1 2 3 4 5 6 \u0026gt; test.jpg 的方式拼图,1和6的位置是确定的,1可以直观的看到图片头,6可以通过十六进制确定它是文件尾,剩下的 2345 直接拼接可以看到图片的衔接点是不一样的,调整顺序很快可以找到1后面的第一块合适的内容,以此类推,拼出 pic1.jpg 因为除了结尾,每个图片分片大小是26624,我们需要把 pic1.jpg 通过 ipfs 分片上传,这里是很容易忽视的一个点,你很可能会认为需要的hash值是 sha256 或别的什么,然而,这里要是 ipfs 的hash,每当你上传一个文件,ipfs都会给你返回一个该文件的hash,通过这个唯一hash可以避免ipfs里存储重复文件。执行 ipfs add -s size-26624 pic1.jpg 获得到了pic1.jpg 的hash 3. 获得 pic2 的hash 题目说明已经给出了图片的sha256,我们只需要将这个转换为ipfs的Qm开头的hash即可,在原sha256串的前面加1220的头,然后转换为base58即可得到 pic2.jpg 的 Qm 打头的hash:\npython3 Python 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)] on darwin Type \u0026#34;help\u0026#34;, \u0026#34;copyright\u0026#34;, \u0026#34;credits\u0026#34; or \u0026#34;license\u0026#34; for more information. \u0026gt;\u0026gt;\u0026gt; import base58 \u0026gt;\u0026gt;\u0026gt; base58.b58encode_int(int(\u0026#34;1220659c2a2c3ed5e50f848135eea4d3ead3fa2607e2102ae73fafe8f82378ce1d1e\u0026#34;),16) Traceback (most recent call last): File \u0026#34;\u0026lt;stdin\u0026gt;\u0026#34;, line 1, in \u0026lt;module\u0026gt; ValueError: invalid literal for int() with base 10: \u0026#39;1220659c2a2c3ed5e50f848135eea4d3ead3fa2607e2102ae73fafe8f82378ce1d1e\u0026#39; \u0026gt;\u0026gt;\u0026gt; base58.b58encode_int(int(\u0026#34;1220659c2a2c3ed5e50f848135eea4d3ead3fa2607e2102ae73fafe8f82378ce1d1e\u0026#34;, 16)) b\u0026#39;QmVBHzwuchpfHLxEqNrBb3492E73DHE99yFCxx1UYcJ6R3\u0026#39; \u0026gt;\u0026gt;\u0026gt; base58.b58encode_int(int(\u0026#34;659c2a2c3ed5e50f848135eea4d3ead3fa2607e2102ae73fafe8f82378ce1d1e\u0026#34;, 16)) b\u0026#39;7qeHqmdC3foiMbRCoysZPyJEbZMgaVbHAtx6KK9J6QM3\u0026#39; \u0026gt;\u0026gt;\u0026gt; base58.b58encode_int(int(\u0026#34;1220659c2a2c3ed5e50f848135eea4d3ead3fa2607e2102ae73fafe8f82378ce1d1e\u0026#34;, 16)) b\u0026#39;QmVBHzwuchpfHLxEqNrBb3492E73DHE99yFCxx1UYcJ6R3\u0026#39; 4. 计算获得md5校验和,得到flag 伪代码: md5.sum(Qmcode.pic1.jpg+Qmcode.pic2.jpg)\n将获得的md5校验和用flag{}括起来就是flag\nEOF\n","permalink":"https://huifeng.me/posts/qwbctfwriteupofipfs/","tags":["CTF","blockchain","ipfs"],"title":"强网杯CTF 2020 区块链题目 IPFS Writeup"},{"categories":["Go"],"contents":" \u0026ldquo;The Go Programming Language\u0026rdquo; 《Go 语言圣经》 第九章 memo5.go 那道例题,困扰了我很久,我承认我理解能力,对Go的掌握程度都没达到我的预期,简单点说,我没我想的那么聪慧。所以我只好花了快5天时间,去理解这个例题,最后,我终于能把每行代码都解释明白了。我记性不好,所以在这里留个档,方便自己也方便同样学习这一例题的人们。如果有错误的地方,我理解有误的地方,欢迎指出。\n 为了能理解 memo5.go ,我特意画了一张图,我再次感受到了那条我听过但忘记谁说过的一个什么劳什子定理:“当你能够把问题画下来的时候,你已经解决了一半的问题。”\n这里是图(回头放)\n这是图的源文件(进去再下载):https://github.com/wedojava/gopl_study/blob/master/ch9/memo5/analysis.xlsx\n这是源码位置:\n memo5: https://github.com/wedojava/gopl_study/tree/master/ch9/memo5 memotest: https://github.com/wedojava/gopl_study/tree/master/ch9/memotest Ok,下面开始正题,我的理解是这样的:\n 整个程序的通信是由 channel 来承担,传递数据的最终形态就是 value+err ,就是 result struct。 Memo struct 里就一个 uncached channel ,用来放请求 request , Entry 里 res 用来放查询结果,ready 是为了方便 call 和 deliver 通信而存在的 channel 。 左边是需求方,甲方(Memo struct),右边是乙方(Entry struct),甲方要数据,乙方提供数据,所以就有了: 甲方通过自己的 channel 提出了 request , 乙方查看 request 里的 key 有没有对应的 cache,有就 deliver ,没有就 call 。 call 完了后给 deliver 一个信号,deliver 就把新 call 出来的内容放到 response channel 里去。 最终的结果是:乙方 e 把结果打包为 result, 塞到response channel 里。 而甲方一直在 response 边等着呢,一旦 e 把东西放进去, response 立即会收到result,一轮甲乙双方的交互结束。 TO BE CONTINUE \u0026hellip;\nEOF\n","permalink":"https://huifeng.me/posts/goplchapter9memo5/","tags":["gopl","go","study"],"title":"gopl.io chapter 9 memo5 study"},{"categories":["Go"],"contents":"Go 的并发很核心,理解不难,听懂也简单,但是用好它,很难!至少我现在觉得这东西好绕,当然这也说明我们没有学透彻,学明白,下面把学到的一些东西记录下来。算是二次理解。\nConcurrency is go programing is a core tech, easy to understand but hard to use in best practices.\nReference: https://www.kancloud.cn/mutouzhang/go/596822\nTips: Some words Go的并发理念可以这样概括:为了简单起见,在可能的情况下使用通道,并且像免费资源一样处理goroutine(而不需要过多过早的考虑资源占用情况)。 通道本质上比内存访问同步基元更具可组合性。 将锁分散在各个结构中听起来像是一场噩梦。 Ownership Transfer [USE CHANNEL]\nIf some code section generate datas, you wanna use it in other section. =\u0026gt; this means you wanna transfer this ownership of data to other section. =\u0026gt; USE CHANNEL!\nBenefits: You can create buffer channels to implement memory queues with cheap resources.\n Guard Internal Struct [USE MUTEX]\nDon\u0026rsquo;t use channel but sync.Mutex!\nBenefits: Hide implementation details of locking section, reduce complexity to caller.\nPoint: Try your best to limit the lock to a small area\n type Counter struct { mu sync.Mutex value int } func(c *Counter) Increment() { c.mu.Lock() defer c.mu.Unlock() c.value++ } Coordinate Multiple Pieces Of Logic [USE SELECT]\n如果你发现自己在努力了解并发代码的工作原理,为什么会发生死锁或竞争,并且你正在使用Mutex,这可能是你需要切换到通道的一个很好的信号。 TO BE CONTINUE\u0026hellip;\n","permalink":"https://huifeng.me/posts/concurrencyingostudy/","tags":["go","golang","concurrency","并发"],"title":"Concurrency In Go Study"},{"categories":["Hugo"],"contents":"First of all, I will never use coding.net or gitee for my blog repos deploy, they are not confortable to me, so sad, so bad.\nMy hugo have three repos:\n hugo(hugo resource, private repo) - root zozo(theme/zozo, private repo) - submodule public(html files, public repo) - submodule Maybe, you have this structure too.\nI clone my repo hugo to my other desktop, but theme and public folders are blank.\nNow, fix it!\nReference: https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97\nhttps://gohugo.io/hosting-and-deployment/hosting-on-github/\nHow: 1. Just for submodules folders empty make sure .gitmodule is correct. maybe .gitmodule sames right, but cannot work, git submodule sync. run git submodule init then git submodule update to update 2. Even not cloned Just run git clone https://github.com/wedojava/blog.git --recurse-submodules, after this, submodules will be fetched done. then, you may make some changes, need push, just do it, but notion that, cd your submodule folders and push them first may give you best wishes.\nIssue: If some submodule cannot push and at the weird branch, just go to that path, run git switch master then git push or git pull.\n Yes, just so easy as there. Here you go.\n","permalink":"https://huifeng.me/posts/clonehugotootherdesktop/","tags":["hugo","clone","git","deploy","submodule"],"title":"Clone Hugo To Other Desktop"},{"categories":["Git"],"contents":"# Constantly # git remote add git remote add origin https://e.coding.net/wedojava/hugo/zozo.git # git remote 重新设置 git remote set-url origin https://e.coding.net/wedojava/hugo/zozo.git git push -u origin master git clone https://github.com/varkai/hugo-theme-zozo themes/zozo git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke git submodule add -b master https://gitee.com/wedojava/wedojava.git public git config --global user.email \u0026#34;wedojava@gmail.com\u0026#34; # Roll Back Reference:\nhttps://github.com/includeios/document/issues/12\nhttps://www.liaoxuefeng.com/wiki/896043488029600/897013573512192\nhttps://ruby-china.org/topics/11637\nhttps://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/561978/\nhttps://www.cnblogs.com/keystone/p/10700617.html\nMethod 1.1 git reset --hard HEAD^ 回退到上个版本 git reset --hard commit_id 退到/进到 指定commit_id git push origin HEAD --force 把回退的某个版本提交的远程 Method 1.2 git reset --hard dbf5efdb3cd8ea5d576f2e29fe0db1951d0e3e3b # 强制推送到远程分支, 会抹去远程库的提交信息, 不要这么干 # git push -f origin master Method 2 # 回退到指定版本, 需要解决冲突 git revert e7c8599d29b61579ef31789309b4e691d6d3a83f # 放弃回退(加--hard会重置已 commit和工作区的内容) # git reset --hard origin/master # log 可以查看所有分支的所有操作记录(包括(包括commit和reset的操作),包括已经被删除的commit记录,git log则不能察看已经删除了的commit记录\ngit reflog 打印你记录你的每一次操作记录 ","permalink":"https://huifeng.me/posts/gittips/","tags":["git"],"title":"Git Tips"},{"categories":["hugo","hexo"],"contents":" 干货:从hexo转到hugo写了个python3的脚本: migrate hexo to hugo,毕竟快一年没用Python了,如果有问题欢迎骚扰.\n 更多参考:https://gohugo.io/hosting-and-deployment/hosting-on-github/\n目标 不再花钱买VPS了 不再依赖太多,安装太多东西在本地,just go env enough! 简单快速 部署 推荐部署到 Coding 或者GitHub,Gitee 的自定义域名是要 Pro 会员才可以,花钱的。\n关于整个项目的部署我觉得可以这么搞:\n以我在 Coding 上为例,其他类似吧,用了 Coding 发现他项目下包含仓库的结构比较舒服。\n 新建项目:hugo 进入项目,新建仓库:huifeng.me (私有) 还呆在项目里,新建仓库:public(公开) 通过 hugo new site huifeng.me 新建的仓库放的是所有源码了,但是页面皮肤和public文件夹不包含进去。\n大概的流程是这样:\nhugo new site huifeng.me git remote add origin \u0026lt;your_repo_url\u0026gt; git push -u origin master git submodule add https://github.com/varkai/hugo-theme-zozo themes/zozo # 上面这样本来是挺好的做法,更新就进去 git pull 就好,可是我还是修改了原有样式,所以有了下面的修改 # 下面两行这样是为了我根据自己想要修改了样式不至于无处保存。 cd ./themes/zozo git remote set-url origin https://e.coding.net/wedojava/hugo/zozo.git # 下面的操作是参考的这里: # https://gohugo.io/hosting-and-deployment/hosting-on-github/#step-by-step-instructions cd ../../ hugo cd public git add . git commit -m \u0026#34;first public\u0026#34; git remote add origin https://e.coding.net/wedojava/hugo/public.git cd .. echo \u0026#34;public\u0026#34; \u0026gt;\u0026gt; .gitignore 保存下面脚本并修改 +x 权限:\n#!/bin/sh # If a command fails then the deploy stops set -e printf \u0026#34;\\033[0;32mDeploying updates to GitHub...\\033[0m\\n\u0026#34; # Build the project. hugo # if using a theme, replace with `hugo -t \u0026lt;YOURTHEME\u0026gt;` # Go To Public folder cd public # Add changes to git. git add . # Commit changes. msg=\u0026#34;rebuilding site $(date)\u0026#34; if [ -n \u0026#34;$*\u0026#34; ]; then msg=\u0026#34;$*\u0026#34; fi git commit -m \u0026#34;$msg\u0026#34; # Push source and build repos. git push origin master and run: ./deploy.sh \u0026quot;Your optional commit message\u0026quot;\nEOF\n","permalink":"https://huifeng.me/posts/hexo2hugo/","tags":["hexo","hugo","github","gitee","coding","blog"],"title":"Hexo转到hugo,有些经验和脚本希望能帮到大家"},{"categories":["Newwork"],"contents":"test if device can up sshd service if\n# show ip ssh SSH Disabled - version 1.99 %Please create RSA keys to enable SSH (and of atleast 768 bits for SSH v2). Authentication methods:publickey,keyboard-interactive,password Authentication timeout: 120 secs; Authentication retries: 3 Minimum expected Diffie Hellman key size : 1024 bits IOS Keys in SECSH format(ssh-rsa, base64 encoded): NONE means\u0026rsquo; ssh supported just need config\n config domain name #conf t (config)#ip domain-name domain222test generate rsa (config)#crypto key generate rsa The name for the keys will be: CE22.domain222test Choose the size of the key modulus in the range of 360 to 4096 for your General Purpose Keys. Choosing a key modulus greater than 512 may take a few minutes. How many bits in the modulus [512]: 2048 % Generating 2048 bit RSA keys, keys will be non-exportable... [OK] (elapsed time was 8 seconds) user account add username: demo and password: demo (config)#username demo secret demo Up ssh protocal on vty line (config)#line vty 0 (config-line)#transport input ssh // Up ssh login (config-line)#login local // auth by local config sshd (config)#ip ssh time-out 120 (config)#ip ssh authentication-retries 1 (config)#ip ssh version 2 ","permalink":"https://huifeng.me/posts/cisco-sshd-conf/","tags":["cisco"," ssh"," sshd"," config"," network"],"title":"Cisco sshd config"},{"categories":["Linux"],"contents":"This post is the log for compile source and install some package to linux, yeah, it\u0026rsquo;ll fit to offline install while you\u0026rsquo;re download packages before.\nDownload openssh-7.5p1 (This is the last version support: ssh protocal \u0026lt; 1.5 ) -\u0026gt; Download now\n zlib-devel -\u0026gt; Download now\n openssl-fip -\u0026gt; Download now\n openssl-1.0.2u -\u0026gt; Download now\n Install via source Install requirements yum install -y zlib-devel pam-devel tcp_wrappers-devel OR install via source, such as zlib:\ntar zxf zlib-1.2.11.tar.gz cd zlib-1.2.11.tar.gz ./configure make make install Install openssl-fip Refer: http://www.openssl.org/docs/fips\ntar zxf openssl-fips-2.0.16.tar.gz cd openssl-fips-2.0.16 ./config make make install Install openssl tar zxf openssl-OpenSSL_1_0_2u.tar.gz cd openssl-OpenSSL_1_0_2u ./config fips --shared make make install openssl succeeded install printing:\nOpenSSL shared libraries have been installed in: /usr/local/ssl If this directory is not in a standard system path for dynamic/shared libraries, then you will have problems linking and executing applications that use OpenSSL libraries UNLESS: * you link with static (archive) libraries. If you are truly paranoid about security, you should use static libraries. * you use the GNU libtool code during linking (http://www.gnu.org/software/libtool/libtool.html) * you use pkg-config during linking (this requires that PKG_CONFIG_PATH includes the path to the OpenSSL shared library directory), and make use of -R or -rpath. (http://www.freedesktop.org/software/pkgconfig/) * you specify the system-wide link path via a command such as crle(1) on Solaris systems. * you add the OpenSSL shared library directory to /etc/ld.so.conf and run ldconfig(8) on Linux systems. * you define the LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH (HP), DYLD_LIBRARY_PATH (MacOS X) or PATH (Cygwin and DJGPP) environment variable and add the OpenSSL shared library directory to it. One common tool to check the dynamic dependencies of an executable or dynamic library is ldd(1) on most UNIX systems. See any operating system documentation and manpages about shared libraries for your version of UNIX. The following manpages may be helpful: ld(1), ld.so(1), ld.so.1(1) [Solaris], dld.sl(1) [HP], ldd(1), crle(1) [Solaris], pldd(1) [Solaris], ldconfig(8) [Linux], chatr(1) [HP]. cp libcrypto.pc /usr/local/ssl/lib/pkgconfig chmod 644 /usr/local/ssl/lib/pkgconfig/libcrypto.pc cp libssl.pc /usr/local/ssl/lib/pkgconfig chmod 644 /usr/local/ssl/lib/pkgconfig/libssl.pc cp openssl.pc /usr/local/ssl/lib/pkgconfig chmod 644 /usr/local/ssl/lib/pkgconfig/openssl.pc Link openssl library to system libs, if step3, openssl config contains --prefix=/usr, skip below. echo \u0026#34;/usr/local/ssl/lib\u0026#34; \u0026gt;\u0026gt; /etc/ld.so.conf ldconfig Install openssh tar zxf openssh cd openssh ./configure --prefix=/usr/local/ssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ --with-sandbox=n make make install *. If error occur as 系统没有找到openssl库 , you need execute the command: ldconfig.\nMy Succeeded Install log ## 1. Download packages. ## 2. Install requirements yum install -y zlib-devel pam-devel tcp_wrappers-devel # OR install zlib via source tar zxf zlib-1.2.11.tar.gz cd zlib-1.2.11.tar.gz ./configure make make install ## 3. Install openssl-fip http://www.openssl.org/docs/fips tar zxf openssl-fips-2.0.16.tar.gz cd openssl-fips-2.0.16 ./config make make install ## 4.Install openssl tar zxf openssl-OpenSSL_1_0_2u.tar.gz cd openssl-OpenSSL_1_0_2u ./config fips --shared make make install ---------------------------- install printing ---------------------------- OpenSSL shared libraries have been installed in: /usr/local/ssl If this directory is not in a standard system path for dynamic/shared libraries, then you will have problems linking and executing applications that use OpenSSL libraries UNLESS: * you link with static (archive) libraries. If you are truly paranoid about security, you should use static libraries. * you use the GNU libtool code during linking (http://www.gnu.org/software/libtool/libtool.html) * you use pkg-config during linking (this requires that PKG_CONFIG_PATH includes the path to the OpenSSL shared library directory), and make use of -R or -rpath. (http://www.freedesktop.org/software/pkgconfig/) * you specify the system-wide link path via a command such as crle(1) on Solaris systems. * you add the OpenSSL shared library directory to /etc/ld.so.conf and run ldconfig(8) on Linux systems. * you define the LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH (HP), DYLD_LIBRARY_PATH (MacOS X) or PATH (Cygwin and DJGPP) environment variable and add the OpenSSL shared library directory to it. One common tool to check the dynamic dependencies of an executable or dynamic library is ldd(1) on most UNIX systems. See any operating system documentation and manpages about shared libraries for your version of UNIX. The following manpages may be helpful: ld(1), ld.so(1), ld.so.1(1) [Solaris], dld.sl(1) [HP], ldd(1), crle(1) [Solaris], pldd(1) [Solaris], ldconfig(8) [Linux], chatr(1) [HP]. cp libcrypto.pc /usr/local/ssl/lib/pkgconfig chmod 644 /usr/local/ssl/lib/pkgconfig/libcrypto.pc cp libssl.pc /usr/local/ssl/lib/pkgconfig chmod 644 /usr/local/ssl/lib/pkgconfig/libssl.pc cp openssl.pc /usr/local/ssl/lib/pkgconfig chmod 644 /usr/local/ssl/lib/pkgconfig/openssl.pc ---------------------------- install printing end ---------------------------- ## 5. 将新编译的openssl library 加入系统动态库链接中, 如果在第4步openssl 编译过程中,将其设定为OS默认安装目录(--prefix=/usr),那么此步骤无需执行! echo \u0026#34;/usr/local/ssl/lib\u0026#34; \u0026gt;\u0026gt; /etc/ld.so.conf ldconfig ## 6. Install openssh tar zxf openssh cd openssh ./configure --prefix=/usr/local/ssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ --with-sandbox=n make make install ### If error occur as `系统没有找到openssl库` means command need: `ldconfig`. EOF\n","permalink":"https://huifeng.me/posts/installopensshonredhatviasource/","tags":["redhat"," linux"," lib"," pcap"],"title":"Install openssh to redhat 6.3 via source"},{"categories":["Tools"],"contents":"如何添加系统右键菜单? 我把我的全收集在这里!\nReference: https://www.zhihu.com/question/48091139\nHow to Save the code below as foobar.reg and execute it.\nNotice ! Modify path ! Modify the path to your path! For instance: C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\git\\\\current\\\\git-bash.exe to \\\\you\\\\dope\\\\path\\\\sth.exe. Save the content as .reg file and execute it as administrator. Install and Uninstall Context Sublime-text Install:\nWindows Registry Editor Version 5.00 [HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with \u0026amp;Sublime] @=\u0026#34;Open with \u0026amp;Sublime\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\sublime-text\\\\3211\\\\sublime_text.exe\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with \u0026amp;Sublime\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\sublime-text\\\\3211\\\\sublime_text.exe\\\u0026#34; \\\u0026#34;%1\\\u0026#34;\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with \u0026amp;Sublime] @=\u0026#34;Open with \u0026amp;Sublime\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\sublime-text\\\\3211\\\\sublime_text.exe\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with \u0026amp;Sublime\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\sublime-text\\\\3211\\\\sublime_text.exe\\\u0026#34; \\\u0026#34;%1\\\u0026#34;\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with \u0026amp;Sublime] @=\u0026#34;Open with \u0026amp;Sublime\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\sublime-text\\\\3211\\\\sublime_text.exe\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with \u0026amp;Sublime\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\sublime-text\\\\3211\\\\sublime_text.exe\\\u0026#34; \\\u0026#34;%V\\\u0026#34;\u0026#34; Uninstall:\nWindows Registry Editor Version 5.00 [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with \u0026amp;Sublime] [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with \u0026amp;Sublime\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with \u0026amp;Sublime] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with \u0026amp;Sublime\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with \u0026amp;Sublime] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with \u0026amp;Sublime\\command] emacs Install:\nWindows Registry Editor Version 5.00 [HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with emacs] @=\u0026#34;Open with emacs\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\emacs\\\\current\\\\bin\\\\runemacs.exe\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with emacs\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\emacs\\\\current\\\\bin\\\\runemacs.exe\\\u0026#34; \\\u0026#34;%1\\\u0026#34;\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with emacs] @=\u0026#34;Open with emacs\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\emacs\\\\current\\\\bin\\\\runemacs.exe\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with emacs\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\emacs\\\\current\\\\bin\\\\runemacs.exe\\\u0026#34; \\\u0026#34;%1\\\u0026#34;\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with emacs] @=\u0026#34;Open with emacs\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\emacs\\\\current\\\\bin\\\\runemacs.exe\u0026#34; [HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with emacs\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\foobar\\\\scoop\\\\apps\\\\emacs\\\\current\\\\bin\\\\runemacs.exe\\\u0026#34; \\\u0026#34;%V\\\u0026#34;\u0026#34; Uninstall:\nWindows Registry Editor Version 5.00 [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with emacs] [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with emacs\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with emacs] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with emacs\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with emacs] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with emacs\\command] Vim Install:\nWindows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\\*\\shell\\nvim] @=\u0026#34;Open With NVIM\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\neovim\\\\current\\\\bin\\\\nvim-qt.exe\u0026#34; [HKEY_CLASSES_ROOT\\*\\shell\\nvim\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\neovim\\\\current\\\\bin\\\\nvim-qt.exe\\\u0026#34; \\\u0026#34;%1\\\u0026#34;\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\nvim] @=\u0026#34;Open With NVIM\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\neovim\\\\current\\\\bin\\\\nvim-qt.exe\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\nvim\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\neovim\\\\current\\\\bin\\\\nvim-qt.exe\\\u0026#34; \\\u0026#34;%V\\\u0026#34;\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\shell\\nvim] @=\u0026#34;Open With NVIM\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\neovim\\\\current\\\\bin\\\\nvim-qt.exe\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\shell\\nvim\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\neovim\\\\current\\\\bin\\\\nvim-qt.exe\\\u0026#34; \\\u0026#34;%1\\\u0026#34;\u0026#34; Unistall:\nWindows Registry Editor Version 5.00 [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with NVIM] [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\Open with NVIM\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with NVIM] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\Open with NVIM\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with NVIM] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\Open with NVIM\\command] Git bash Inistall:\nWindows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\\Directory\\shell\\git_shell] @=\u0026#34;Git Ba\u0026amp;sh Here\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\git\\\\current\\\\git-bash.exe\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\shell\\git_shell\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\git\\\\current\\\\git-bash.exe\\\u0026#34; \\\u0026#34;--cd=%1\\\u0026#34;\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\git_shell] @=\u0026#34;Git Ba\u0026amp;sh Here\u0026#34; \u0026#34;Icon\u0026#34;=\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\git\\\\current\\\\git-bash.exe\u0026#34; [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\git_shell\\command] @=\u0026#34;\\\u0026#34;C:\\\\Users\\\\Notebook\\\\scoop\\\\apps\\\\git\\\\current\\\\git-bash.exe\\\u0026#34; \\\u0026#34;--cd=%v.\\\u0026#34;\u0026#34; Unistall:\nWindows Registry Editor Version 5.00 [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\git_bash] [-HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\git_bash\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\git_bash] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell\\git_bash\\command] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\git_bash] [-HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell\\git_bash\\command] Difference Method 1 you need to edit via regedit to change the value to your git-bash path.\nMethod 2 you just edit here and run it.\nEOF\n","permalink":"https://huifeng.me/posts/context-right-menu/","tags":["Cygwin"," Mintty"," 右键"," vim"," gvim"," nvim"," neovim"," emacs"," context"],"title":"Right way install Context (right menu)"},{"categories":["Go"],"contents":"Some tips I don\u0026rsquo;t know!\n By convention, the package name is the same as the last element of the import path. For instance, the \u0026quot;math/rand\u0026quot; package comprises files that begin with the statement package rand.\n Naked return statements should be used only in short functions. They can harm readability in longer functions.\n Outside a function, every statement begins with a keyword (var, func, and so on) and so the := construct is not available.\n Basic types:\n byte // alias for uint8 rune // alias for int32 // represents a Unicode code point The int, uint, and uintptr types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. When you need an integer value you should use int unless you have a specific reason to use a sized or unsigned integer type. For:\n The init and post statements are optional, like this: for ; sum \u0026lt; 1000; {... is correct. An array\u0026rsquo;s length is part of its type, so arrays cannot be resized.\n Slices are like references to arrays: A slice does not store any data, it just describes a section of an underlying array.\n The make function allocates a zeroed array and returns a slice that refers to that array:\n a := make([]int, 5) // a len=5 cap=5 [0 0 0 0 0] b := make([]int, 0, 5) // b len=0 cap=5 [] c := b[:2] // c len=2 cap=5 [0 0] d := c[2:5] // d len=3 cap=3 [0 0 0] Range:\n When ranging over a slice, two values are returned for each iteration. The first is the index, and the second is a copy of the element at that index. ","permalink":"https://huifeng.me/posts/go-a-tour-of-go-note.md/","tags":["Go"," tips"],"title":"《A Tour of Go》 Study note"},{"categories":["Network"],"contents":"Install Reference:\n GNS3 Installation on Linux 👈 no useful to Archlinux and Manjaro and no better than above! so sad! Dynamips (Cisco Router Emulator) 👈 Official document for Dynamips Install and configure GNS3 on Arch Linux 👈 Very detailed and procise! Install GNS3 on Arch / Manjaro Linux (The Right Way) 👈 Very detailed and procise! Arch-GNS3-Helper My Steps 1. Install GNS3 sudo pacman -Syu sudo pacman -S yay yay -S gns3-server --noconfirm yay -S gns3-gui --noconfirm 2. Install Dynamips git clone git://github.com/GNS3/dynamips.git cd dynamips mkdir build cd build cmake .. make make install Verify :\n$ cd $HOME $ dynamips 2\u0026gt; /dev/null | grep version Cisco Router Simulation Platform (version 0.2.19-amd64/Linux stable) $ getcap $(which dynamips) /usr/bin/dynamips = cap_net_admin,cap_net_raw+ep 3. Install VPCS yay -S vpcs --noconfrim Check:\n$ cd $HOME $ type vpcs vpcs is /usr/bin/vpcs $ vpcs -v | grep version Welcome to Virtual PC Simulator, version 0.8 beta1 Expriement Base conf en conf t hostname R1 line console 0 # Go to console. no exec-time # Stop unwished withdraw due to long periods of inactivity. logging synchronous # Stop interrupte by log while input. exit no ip domain lookup # Stop DNS analysis auto,another wise it waste time to get info to non-critical words. Config ip info conf t int g1/0 ip addr 1.1.1.1 255.255.255.0 no shutdown exit exit sh ip int brief ","permalink":"https://huifeng.me/posts/gns3-experience-simple-expriements/","tags":["GNS3"," Network"],"title":"GNS3 Experience Setup and usage in linux"},{"categories":["Hack"],"contents":"{% centerquote 王小波 %} 人的一切痛苦,本质上都是对自己无能的愤怒。 {% endcenterquote %}\n[TOC]\nENV:\nWindows* x86\npython 2.7.17\n# Memory dump 使用第三方软件抓取内存dump 针对于物理机,通常可以使用如下工具来抓取内存dump:\nKnTTools F-Response Mandiant Memoryze HBGary FastDump MoonSols Windows Memory Toolkit AccessData FTK Imager EnCase/WinEn Belkasoft Live RAM Capturer ATC-NY Windows Memory Reader Winpmem Win32dd/Win64dd DumpIt\nDumpit Dump memory by Dumpit, you can download it from https://my.comae.io\n# Volatility https://github.com/volatilityfoundation/volatility https://github.com/volatilityfoundation/volatility3 https://github.com/volatilityfoundation/volatility/wiki/Installation\n Clone it Download it from: https://www.volatilityfoundation.org/26\nOr I recommand to do:\ngit clone https://github.com/volatilityfoundation/volatility.git Dependencies pycrypto2.6: Download pycrypto2.6 for python2.7\n distorm3-3.3.4: Download distorm for x86\n pyinstaller:\n py -2 -m pip install pyinstaller C:\\Python27\\Scripts\\pyinstaller.exe -F pyinstaller.spec construct pip install construct Usage mimikatz git clone https://github.com/volatilityfoundation/volatility.git download mimikatz.py to ./volatility/plugins/ from https://github.com/RealityNet/hotoloti/blob/master/volatility/mimikatz.py\ndownload mimikatz.py directly\n# Get profile volatility.exe -f win7.raw imageinfo # Get password volatility.exe -f win7.raw --profile=Win7SP0x86 mimikatz # Get pslist and find out lsass\u0026#39; PID (the first number after `lsass.exe`) volatility.exe -f win7.raw --profile=Win7SP0x86 pslist | findstr \u0026#34;lsass\u0026#34; # Study logs About lsass.exe Key point links: LSA - [lsass.exe entry]: lsasrv.dll Msv - [LM, NTLM, SHA1]: lsasrv.dll Wdigest - [password]: wdigest.dll Kerberos: kerberos.dll Tspkg: TSpkg.dll SSP: msv1_0.dll LiveSsp: msv1_0.dll Dpapi: dpapisrv.dll or lsasrv.dll All links: 00:\u0026#39;lsass.exe\u0026#39; 01:\u0026#39;ntdll.dll\u0026#39; 02:\u0026#39;kernel32.dll\u0026#39; 03:\u0026#39;KERNELBASE.dll\u0026#39; 04:\u0026#39;msvcrt.dll\u0026#39; 05:\u0026#39;RPCRT4.dll\u0026#39; 06:\u0026#39;SspiSrv.dll\u0026#39; 07:\u0026#39;lsasrv.dll\u0026#39; 08:\u0026#39;sechost.dll\u0026#39; 09:\u0026#39;SspiCli.dll\u0026#39; 10:\u0026#39;ADVAPI32.dll\u0026#39; 11:\u0026#39;USER32.dll\u0026#39; 12:\u0026#39;GDI32.dll\u0026#39; 13:\u0026#39;LPK.dll\u0026#39; 14:\u0026#39;USP10.dll\u0026#39; 15:\u0026#39;SAMSRV.dll\u0026#39; 16:\u0026#39;cryptdll.dll\u0026#39; 17:\u0026#39;MSASN1.dll\u0026#39; 18:\u0026#39;wevtapi.dll\u0026#39; 19:\u0026#39;IMM32.DLL\u0026#39; 20:\u0026#39;MSCTF.dll\u0026#39; 21:\u0026#39;cngaudit.dll\u0026#39; 22:\u0026#39;AUTHZ.dll\u0026#39; 23:\u0026#39;ncrypt.dll\u0026#39; 24:\u0026#39;bcrypt.dll\u0026#39; 25:\u0026#39;msprivs.DLL\u0026#39; 26:\u0026#39;netjoin.dll\u0026#39; 27:\u0026#39;bcryptprimitives.dll\u0026#39; 28:\u0026#39;negoexts.DLL\u0026#39; 29:\u0026#39;Secur32.dll\u0026#39; 30:\u0026#39;cryptbase.dll\u0026#39; 31:\u0026#39;kerberos.DLL\u0026#39; 32:\u0026#39;CRYPTSP.dll\u0026#39; 33:\u0026#39;WS2_32.dll\u0026#39; 34:\u0026#39;NSI.dll\u0026#39; 35:\u0026#39;mswsock.dll\u0026#39; 36:\u0026#39;wship6.dll\u0026#39; 37:\u0026#39;\u0026#39; 38:\u0026#39;netlogon.DLL\u0026#39; 39:\u0026#39;\u0026#39; 40:\u0026#39;logoncli.dll\u0026#39; 41:\u0026#39;schannel.DLL\u0026#39; 42:\u0026#39;\u0026#39; 43:\u0026#39;wdigest.DLL\u0026#39; 44:\u0026#39;rsaenh.dll\u0026#39; 45:\u0026#39;tspkg.DLL\u0026#39; 46:\u0026#39;pku2u.DLL\u0026#39; 47:\u0026#39;RpcRtRemote.dll\u0026#39; 48:\u0026#39;efslsaext.dll\u0026#39; 49:\u0026#39;scecli.DLL\u0026#39; 50:\u0026#39;credssp.dll\u0026#39; 51:\u0026#39;WINSTA.dll\u0026#39; 52:\u0026#39;IPHLPAPI.DLL\u0026#39; 53:\u0026#39;WINNSI.DLL\u0026#39; 54:\u0026#39;netutils.dll\u0026#39; 55:\u0026#39;wkscli.dll\u0026#39; 56:\u0026#39;USERENV.dll\u0026#39; 57:\u0026#39;profapi.dll\u0026#39; 58:\u0026#39;wshtcpip.dll\u0026#39; 59:\u0026#39;dssenh.dll\u0026#39; 60:\u0026#39;GPAPI.dll\u0026#39; 61:\u0026#39;cryptnet.dll\u0026#39; 62:\u0026#39;WLDAP32.dll\u0026#39; 63:\u0026#39;SHLWAPI.dll\u0026#39; 64:\u0026#39;SensApi.dll\u0026#39; 65:\u0026#39;WINHTTP.dll\u0026#39; 66:\u0026#39;webio.dll\u0026#39; 67:\u0026#39;dhcpcsvc6.DLL\u0026#39; 68:\u0026#39;dhcpcsvc.DLL\u0026#39; 69:\u0026#39;ole32.dll\u0026#39; 70:\u0026#39;CFGMGR32.dll\u0026#39; 71:\u0026#39;rasadhlp.dll\u0026#39; 72:\u0026#39;fwpuclnt.dll\u0026#39; __len__:73 How to find out Signatures? I found it by https://github.com/skelsec/pypykatz/tree/master/pypykatz/lsadecryptor/packages\nmsv templates Target Windows Version Signature XP ~ 2k3 b'\\x4c\\x8b\\xdf\\x49\\xc1\\xe3\\x04\\x48\\x8b\\xcb\\x4c\\x03\\xd8' 2k3 ~ Vista b'\\x4c\\x8b\\xdf\\x49\\xc1\\xe3\\x04\\x48\\x8b\\xcb\\x4c\\x03\\xd8' Vista ~ Win7 b'\\x33\\xff\\x45\\x85\\xc0\\x41\\x89\\x75\\x00\\x4c\\x8b\\xe3\\x0f\\x84' Win7 ~ Win8 b'\\x33\\xf6\\x45\\x89\\x2f\\x4c\\x8b\\xf3\\x85\\xff\\x0f\\x84' Win8 ~ Win_Blue b'\\x33\\xff\\x41\\x89\\x37\\x4c\\x8b\\xf3\\x45\\x85\\xc0\\x74' Win_Blue ~ WIN_10_1507 b'\\x8b\\xde\\x48\\x8d\\x0c\\x5b\\x48\\xc1\\xe1\\x05\\x48\\x8d\\x05' WIN_10_1507 ~ WIN_10_1703 b'\\x33\\xff\\x41\\x89\\x37\\x4c\\x8b\\xf3\\x45\\x85\\xc0\\x74' WIN_10_1703 ~ WIN_10_1803 b'\\x33\\xff\\x45\\x89\\x37\\x48\\x8b\\xf3\\x45\\x85\\xc9\\x74' WIN_10_1803 ~ WIN_10_1903 b'\\x33\\xff\\x41\\x89\\x37\\x4c\\x8b\\xf3\\x45\\x85\\xc9\\x74' WIN_10_1903 b'\\x33\\xff\\x41\\x89\\x37\\x4c\\x8b\\xf3\\x45\\x85\\xc0\\x74' Get Credman Reference: howto ~ credential manager saved credentials\n Get credentials from target: xcopy /h /i /s %appdata%\\Microsoft\\Credentials .\\test\\AppDataCredentials xcopy /h /i /s %localappdata%\\Microsoft\\Credentials .\\test\\localAppDataCredentials xcopy /h /i /s %appdata%\\Microsoft\\Protect .\\test\\AppDataProtect Analisis at local mimikatz.exe \u0026#34;dpapi::cred /in:C:\\\\Users\\\\snow\\\\credman\\\\AppDataCredentials\\\\042450E3F8E1A3F429E61FE2963AA249\u0026#34; \u0026#34;exit\u0026#34; Return:\n.#####. mimikatz 2.2.0 (x86) #18362 Aug 14 2019 01:31:19 .## ^ ##. \u0026#34;A La Vie, A L\u0026#39;Amour\u0026#34; - (oe.eo) ## / \\ ## /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com ) ## \\ / ## \u0026gt; http://blog.gentilkiwi.com/mimikatz \u0026#39;## v ##\u0026#39; Vincent LE TOUX ( vincent.letoux@gmail.com ) \u0026#39;#####\u0026#39; \u0026gt; http://pingcastle.com / http://mysmartlogon.com ***/ mimikatz(commandline) # dpapi::cred /in:C:\\\\Users\\\\snow\\\\credman\\\\AppDataCredent ials\\\\042450E3F8E1A3F429E61FE2963AA249 **BLOB** dwVersion : 00000001 - 1 guidProvider : {df9d8cd0-1501-11d1-8c7a-00c04fc297eb} dwMasterKeyVersion : 00000001 - 1 guidMasterKey : {dc7aadf6-32ff-4aca-a053-80df0e637e00} dwFlags : 20000000 - 536870912 (system ; ) dwDescriptionLen : 0000003a - 58 szDescription : Enterprise Credential Data algCrypt : 00006610 - 26128 (CALG_AES_256) dwAlgCryptLen : 00000100 - 256 dwSaltLen : 00000020 - 32 pbSalt : 1071acb779a51788ab4f9bc7acc34ec8881b52608c931a4bc6a08b5db ae8f9ba dwHmacKeyLen : 00000000 - 0 pbHmackKey : algHash : 0000800e - 32782 (CALG_SHA_512) dwAlgHashLen : 00000200 - 512 dwHmac2KeyLen : 00000020 - 32 pbHmack2Key : 308761fa960dbd4d7f4ee788d44117a7b823b35092df3683e7023672c f551ef0 dwDataLen : 000000d0 - 208 pbData : 599b8ddcf80b900c90df0fe02dd31102a5e327b0967ba9d716cf5f5ff d605abaf6c9712ab9b87b8e873706b74e75d92b0c060c9572883fc5952210c0571057529022cc01c eda17e94577ac39339af3efff54c75a47c6d8a32af6f96681d19bf2f0878f16ca78e7105cdff3739 1c55bf80ad6f331a38bb995c8128c69d38e7988b59104e535e7cc33e1d6f487c26abe63eee8bec3d fce368dd470324b6c7623d89b42afe3ce933eee3d9998a104c35c065002968dd458ca7ecdea32fb7 b44820bee867be744b2b36a23107dda01c44ee1 dwSignLen : 00000040 - 64 pbSign : 6beb703e4a1c1b76c0a084f90199217ab4744e7ff5ff261330ab45a9b 987e20e50d6e899f0cc90c4769aa06fd054d4866b61d9ec341b6fd9a03e7d60fe6fee27 mimikatz(commandline) # exit Bye! Get sth importent: dwFlags : 20000000 - 536870912 (system ; ) guidMasterKey : {dc7aadf6-32ff-4aca-a053-80df0e637e00} Decrypt: volatility usage If u install by apt-get or download an executable file:\nvolatility -f WIN7.raw imageinfo # 操作系统信息 volatility -f WIN7.raw --profile=Win7SP0x86 pslist # 查看进程 volatility -f WIN7.raw --profile=Win7SP0x86 hivelist # 缓存在内存中的注册表 volatility -f WIN7.raw --profile=Win7SP0x86 hivedump -o # 注册表的 virtual 地址 volatility -f WIN7.raw --profile=Win7SP0x86 printkey -K \u0026#34;SAM\\Domains\\Account\\Users\\Names\u0026#34; # SAM 表中都有哪些用户 volatility -f WIN7.raw --profile=Win7SP0x86 printkey -K “SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon” # 最后登录 If get it via git or source: To see available options, run python vol.py -h or python vol.py --info\npython vol.py --plugins=volatility/plugins --profile=Win7SP1x86 -f C:\\test\\win7.raw imageinfo # find out `lsass`\u0026#39;s pid -\u0026gt; 568 python vol.py --plugins=volatility/plugins --profile=Win7SP1x86 -f C:\\test\\win7.raw memdump -p 568 -D c:\\test python vol.py --plugins=volatility/plugins --profile=Win7SP1x86 -f C:\\test\\win7.raw mimikatz python C:\\Users\\Notebook\\Git\\python\\vol_mimikatz\\volatility\\vol.py --plugins=C:\\Users\\Notebook\\Git\\python\\vol_mimikatz\\volatility\\volatility\\plugins --profile=Win7SP1x86 -f C:\\test\\win7.raw mimikatz ","permalink":"https://huifeng.me/posts/volatility-mimikatz/","tags":["Volatility"," Mimikatz"],"title":"Volatility and Mimikatz"},{"categories":["C/C++"],"contents":" Reference:\n Screenshot C++ win32 api https://gist.github.com/rdp/9821698 How can I take a screenshot and save it as JPEG on Windows? Converting a BMP Image to a PNG Image Retrieving the Class Identifier for an Encoder c++链接时,无法解析的外部符号 _GdipAlloc等一系列报错 I implemented screen shot from two methods, this post decription the way use [C/C++ win32 api] to get it, Python edition for screen shot is more easy than this, I\u0026rsquo;ll release it late also.\nJust tips I got via this project\u0026rsquo;s developing! Get Screen\u0026rsquo;s Resolution method one INT width = GetSystemMetrics(SM_CXSCREEN); // 屏幕宽 INT height = GetSystemMetrics(SM_CYSCREEN); // 屏幕高 + method two HDC hScreen = GetDC(NULL); RECT rect = { 0, 0, GetDeviceCaps(hScreen, HORZRES), GetDeviceCaps(hScreen, VERTRES) }; POINT a, b; a.x = LPRECT(\u0026amp;rect)-\u0026gt;left; a.y = LPRECT(\u0026amp;rect)-\u0026gt;top; b.x = LPRECT(\u0026amp;rect)-\u0026gt;right; b.y = LPRECT(\u0026amp;rect)-\u0026gt;bottom; Add #pragma comment(lib,\u0026quot;gdiplus.lib\u0026quot;) to fix link error: error LNK2019: unresolved external symbol _GdipAlloc@4 etc. Better way to connect string: #include \u0026lt;stdio.h\u0026gt;sprintf_s(filepath, \u0026#34;%s%s%s\u0026#34;, \u0026#34;dirPath\u0026#34;, \u0026#34;filename\u0026#34;, \u0026#34;.bmp\u0026#34;); Convert CHAR* to WCHAR* (char* to wchar_t *): #include \u0026lt;stdio.h\u0026gt;wchar_t* wfilepath = new wchar_t[50]; swprintf(wfilepath, 50, L\u0026#34;%hs\u0026#34;, \u0026#34;filepath\u0026#34;); Capture Screen One quick start Refer to Screenshot C++ win32 api, it is the quick and easy way to see while or not you can capture a screen by program C. Just run and paste to Paint. You can get achivement quickly and easy to get how to shot screen.\nAnother way to get it (Method one) Refer to https://gist.github.com/rdp/9821698 I follow the gist replies, and fixed memory leak resulted above: NOTICE: Set properties in visule studio [Configuration]-\u0026gt;[General]-\u0026gt;[Character Set]-\u0026gt;Use Multi-Byte Character Set\n// compile this like g++ go2.c -lgdi32 [if you\u0026#39;re using mingw] #include \u0026lt;windows.h\u0026gt;#include \u0026lt;stdio.h\u0026gt; // Helper function to retrieve current position of file pointer: inline int GetFilePointer(HANDLE FileHandle) { return SetFilePointer(FileHandle, 0, 0, FILE_CURRENT); } //--------------------------------------------------------------------------- // Screenshot // -\u0026gt; FileName: Name of file to save screenshot to // -\u0026gt; lpDDS: DirectDraw surface to capture // \u0026lt;- Result: Success // extern bool SaveBMPFile(char* filename, HBITMAP bitmap, HDC bitmapDC, int width, int height) { bool Success = false; HDC SurfDC = NULL; // GDI-compatible device context for the surface HBITMAP OffscrBmp = NULL; // bitmap that is converted to a DIB HDC OffscrDC = NULL; // offscreen DC that we can select OffscrBmp into LPBITMAPINFO lpbi = NULL; // bitmap format info; used by GetDIBits LPVOID lpvBits = NULL; // pointer to bitmap bits array HANDLE BmpFile = INVALID_HANDLE_VALUE; // destination .bmp file BITMAPFILEHEADER bmfh; // .bmp file header // We need an HBITMAP to convert it to a DIB: if ((OffscrBmp = CreateCompatibleBitmap(bitmapDC, width, height)) == NULL) return false; // The bitmap is empty, so let\u0026#39;s copy the contents of the surface to it. // For that we need to select it into a device context. We create one. if ((OffscrDC = CreateCompatibleDC(bitmapDC)) == NULL) return false; // Select OffscrBmp into OffscrDC: HBITMAP OldBmp = (HBITMAP)SelectObject(OffscrDC, OffscrBmp); // Now we can copy the contents of the surface to the offscreen bitmap: BitBlt(OffscrDC, 0, 0, width, height, bitmapDC, 0, 0, SRCCOPY); // GetDIBits requires format info about the bitmap. We can have GetDIBits // fill a structure with that info if we pass a NULL pointer for lpvBits: // Reserve memory for bitmap info (BITMAPINFOHEADER + largest possible // palette): if ((lpbi = (LPBITMAPINFO)(new char[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)])) == NULL) return false; ZeroMemory(\u0026amp;lpbi-\u0026gt;bmiHeader, sizeof(BITMAPINFOHEADER)); lpbi-\u0026gt;bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // Get info but first de-select OffscrBmp because GetDIBits requires it: SelectObject(OffscrDC, OldBmp); if (!GetDIBits(OffscrDC, OffscrBmp, 0, height, NULL, lpbi, DIB_RGB_COLORS)) return false; // Reserve memory for bitmap bits: if ((lpvBits = new char[lpbi-\u0026gt;bmiHeader.biSizeImage]) == NULL) return false; // Have GetDIBits convert OffscrBmp to a DIB (device-independent bitmap): if (!GetDIBits(OffscrDC, OffscrBmp, 0, height, lpvBits, lpbi, DIB_RGB_COLORS)) return false; // Create a file to save the DIB to: if ((BmpFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) return false; DWORD Written; // number of bytes written by WriteFile // Write a file header to the file: bmfh.bfType = 19778; // \u0026#39;BM\u0026#39; // bmfh.bfSize = ??? // we\u0026#39;ll write that later bmfh.bfReserved1 = bmfh.bfReserved2 = 0; // bmfh.bfOffBits = ??? // we\u0026#39;ll write that later if (!WriteFile(BmpFile, \u0026amp;bmfh, sizeof(bmfh), \u0026amp;Written, NULL)) return false; if (Written \u0026lt; sizeof(bmfh)) return false; // Write BITMAPINFOHEADER to the file: if (!WriteFile(BmpFile, \u0026amp;lpbi-\u0026gt;bmiHeader, sizeof(BITMAPINFOHEADER), \u0026amp;Written, NULL)) return false; if (Written \u0026lt; sizeof(BITMAPINFOHEADER)) return false; // Calculate size of palette: int PalEntries; // 16-bit or 32-bit bitmaps require bit masks: if (lpbi-\u0026gt;bmiHeader.biCompression == BI_BITFIELDS) PalEntries = 3; else // bitmap is palettized? PalEntries = (lpbi-\u0026gt;bmiHeader.biBitCount \u0026lt;= 8) ? // 2^biBitCount palette entries max.: (int)(1 \u0026lt;\u0026lt; lpbi-\u0026gt;bmiHeader.biBitCount) // bitmap is TrueColor -\u0026gt; no palette: : 0; // If biClrUsed use only biClrUsed palette entries: if (lpbi-\u0026gt;bmiHeader.biClrUsed) PalEntries = lpbi-\u0026gt;bmiHeader.biClrUsed; // Write palette to the file: if (PalEntries) { if (!WriteFile(BmpFile, \u0026amp;lpbi-\u0026gt;bmiColors, PalEntries * sizeof(RGBQUAD), \u0026amp;Written, NULL)) return false; if (Written \u0026lt; PalEntries * sizeof(RGBQUAD)) return false; } // The current position in the file (at the beginning of the bitmap bits) // will be saved to the BITMAPFILEHEADER: bmfh.bfOffBits = GetFilePointer(BmpFile); // Write bitmap bits to the file: if (!WriteFile(BmpFile, lpvBits, lpbi-\u0026gt;bmiHeader.biSizeImage, \u0026amp;Written, NULL)) return false; if (Written \u0026lt; lpbi-\u0026gt;bmiHeader.biSizeImage) return false; // The current pos. in the file is the final file size and will be saved: bmfh.bfSize = GetFilePointer(BmpFile); // We have all the info for the file header. Save the updated version: SetFilePointer(BmpFile, 0, 0, FILE_BEGIN); if (!WriteFile(BmpFile, \u0026amp;bmfh, sizeof(bmfh), \u0026amp;Written, NULL)) return false; if (Written \u0026lt; sizeof(bmfh)) return false; delete[] lpvBits; return true; } bool ScreenCapture(int x, int y, int width, int height, char* filename) { // get a DC compat. w/ the screen HDC hDc = CreateCompatibleDC(0); // make a bmp in memory to store the capture in HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height); // join em up SelectObject(hDc, hBmp); // copy from the screen to my bitmap BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY); // save my bitmap bool ret = SaveBMPFile(filename, hBmp, hDc, width, height); // free the bitmap memory DeleteObject(hBmp); DeleteDC(hDc); return ret; } int main() { char filename[100] = \u0026#34;testScreenCap.bmp\u0026#34;; int width = GetSystemMetrics(SM_CXSCREEN); int height = GetSystemMetrics(SM_CYSCREEN); bool ifSuccess = ScreenCapture(0, 0, width, height, filename); if (ifSuccess) { printf(\u0026#34;wrote to testScreenCap.bmp\u0026#34;); } return 0; } Another way to get it (Method two) NOTICE: Set [Configuration]-\u0026gt;[General]-\u0026gt;[Character Set]-\u0026gt;Use Multi-Byte Character Set\n#include \u0026lt;windows.h\u0026gt; int CaptureImage(HWND hWnd, CHAR* dirPath, CHAR* filename); int main() { CHAR path[100] = \u0026#34;D:\\\\\u0026#34;; CHAR filename[100] = \u0026#34;hello\u0026#34;; CaptureImage(GetDesktopWindow(), path, filename); // 保存为 E:hello.bmp return 0; } /** * GDI 截取指定窗口 * * 参数 hwnd 要截屏的窗口句柄 * 参数 dirPath 截图存放目录 * 参数 filename 截图名称 */ int CaptureImage(HWND hwnd, CHAR * dirPath, CHAR * filename) { HDC mdc; HBITMAP hbmp; CHAR FilePath[MAX_PATH]; HDC hdcScreen; HDC hdcWindow; HDC hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; RECT rcClient; BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bi; DWORD dwBmpSize; HANDLE hDIB; CHAR* lpbitmap; HANDLE hFile; DWORD dwSizeofDIB; DWORD dwBytesWritten; hdcScreen = GetDC(NULL); // 全屏幕DC hdcWindow = GetDC(hwnd); // 截图目标窗口DC // 创建兼容内存DC hdcMemDC = CreateCompatibleDC(hdcWindow); if (!hdcMemDC) { goto done; } // 获取客户端区域用于计算大小 GetClientRect(hwnd, \u0026amp;rcClient); // 设置延展模式 SetStretchBltMode(hdcWindow, HALFTONE); // 来源 DC 是整个屏幕而目标 DC 是当前的窗口 (HWND) if (!StretchBlt(hdcWindow, 0, 0, rcClient.right, rcClient.bottom, hdcScreen, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY)) { goto done; } // 通过窗口DC 创建一个兼容位图 hbmScreen = CreateCompatibleBitmap( hdcWindow, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top ); if (!hbmScreen) { goto done; } // 将位图块传送到我们兼容的内存DC中 SelectObject(hdcMemDC, hbmScreen); if (!BitBlt( hdcMemDC, // 目的DC 0, 0, // 目的DC的 x,y 坐标 rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, // 目的 DC 的宽高 hdcWindow, // 来源DC 0, 0, // 来源DC的 x,y 坐标 SRCCOPY)) // 粘贴方式 { goto done; } // 获取位图信息并存放在 bmpScreen 中 GetObject(hbmScreen, sizeof(BITMAP), \u0026amp;bmpScreen); bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpScreen.bmWidth; bi.biHeight = bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight; // 在 32-bit Windows 系统上, GlobalAlloc 和 LocalAlloc 是由 HeapAlloc 封装来的 // handle 指向进程默认的堆. 所以开销比 HeapAlloc 要大 hDIB = GlobalAlloc(GHND, dwBmpSize); lpbitmap = (char*)GlobalLock(hDIB); // 获取兼容位图的位并且拷贝结果到一个 lpbitmap 中. GetDIBits( hdcWindow, // 设备环境句柄 hbmScreen, // 位图句柄 0, // 指定检索的第一个扫描线 (UINT)bmpScreen.bmHeight, // 指定检索的扫描线数 lpbitmap, // 指向用来检索位图数据的缓冲区的指针 (BITMAPINFO*)\u0026amp; bi, // 该结构体保存位图的数据格式 DIB_RGB_COLORS // 颜色表由红、绿、蓝(RGB)三个直接值构成 ); wsprintf(FilePath, \u0026#34;%s\\%s.bmp\u0026#34;, dirPath, filename); // 创建一个文件来保存文件截图 hFile = CreateFile( FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); // 将 图片头(headers)的大小, 加上位图的大小来获得整个文件的大小 dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); // 设置 Offset 偏移至位图的位(bitmap bits)实际开始的地方 bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER); // 文件大小 bmfHeader.bfSize = dwSizeofDIB; // 位图的 bfType 必须是字符串 \u0026#34;BM\u0026#34; bmfHeader.bfType = 0x4D42; //BM dwBytesWritten = 0; WriteFile(hFile, (LPSTR)\u0026amp; bmfHeader, sizeof(BITMAPFILEHEADER), \u0026amp;dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)\u0026amp; bi, sizeof(BITMAPINFOHEADER), \u0026amp;dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, \u0026amp;dwBytesWritten, NULL); // 解锁堆内存并释放 GlobalUnlock(hDIB); GlobalFree(hDIB); // 关闭文件句柄 CloseHandle(hFile); // 清理资源 done: DeleteObject(hbmScreen); DeleteObject(hdcMemDC); ReleaseDC(NULL, hdcScreen); ReleaseDC(hwnd, hdcWindow); return 0; } Convert BMP to JPG or PNG Usefull cases:\n How can I take a screenshot and save it as JPEG on Windows? Converting a BMP Image to a PNG Image Retrieving the Class Identifier for an Encoder c++链接时,无法解析的外部符号 _GdipAlloc等一系列报错 After two cases above coded, link error like referenced in function \u0026quot;public: static void * __cdecl Gdiplus::GdiplusBase::operator new(unsigned int)\u0026quot; (??2GdiplusBase@Gdiplus@@SAPAXI@Z) occured, you can code #pragma comment(lib,\u0026quot;gdiplus.lib\u0026quot;) at the top of your .cpp file to solve it. if you wanna another format, exchange image/png to the list below:\n image/bmp image/jpeg image/gif image/tiff image/png Code for convert bmp to png:\n#pragma comment(lib,\u0026#34;gdiplus.lib\u0026#34;) #include \u0026lt;windows.h\u0026gt;#include \u0026lt;gdiplus.h\u0026gt;#include \u0026lt;stdio.h\u0026gt;using namespace Gdiplus; INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid); // helper function INT convert2png(); // By reference: // https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-converting-a-bmp-image-to-a-png-image-use INT convert2png() { // Initialize GDI+. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(\u0026amp;gdiplusToken, \u0026amp;gdiplusStartupInput, NULL); CLSID encoderClsid; Status stat; Image* image = new Image(L\u0026#34;hello.bmp\u0026#34;); // Get the CLSID of the PNG encoder. GetEncoderClsid(L\u0026#34;image/png\u0026#34;, \u0026amp;encoderClsid); //GetEncoderClsid(L\u0026#34;image/jpeg\u0026#34;, \u0026amp;encoderClsid); stat = image-\u0026gt;Save(L\u0026#34;hello.png\u0026#34;, \u0026amp;encoderClsid, NULL); //stat = image-\u0026gt;Save(L\u0026#34;hello.jpg\u0026#34;, \u0026amp;encoderClsid, NULL); if (stat == Ok) printf(\u0026#34;hello.png was saved successfully\\n\u0026#34;); else printf(\u0026#34;Failure: stat = %d\\n\u0026#34;, stat); delete image; GdiplusShutdown(gdiplusToken); return 0; } // By reference: // https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-retrieving-the-class-identifier-for-an-encoder-use int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(\u0026amp;num, \u0026amp;size); if (size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if (pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for (UINT j = 0; j \u0026lt; num; ++j) { if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure } My Final Result Code Here are some of my insights about official documents:\n Official document are often useful, such as my searching for convert bmp to jpg, the shortest and best code from microsoft docs. Just refer inform posts, maybe it\u0026rsquo;s a quick way to resolve our problem, but, we can knowing it, but don’t know why, only officical document can tell you all if you patience enough. For programe c/c++, for development environment differ, we also have to exhaust our effort to fix too many bugs, lost time for developing env, but not for developing business. So, share my env config here.\nMy Development environment configuration Target Platform Version: 8.1 Platform Toolset: Visual Studio 2015 - Windows XP (v140_xp) Character Set: Use Multi-Byte Character Set Complete code You can save the code below as a .cpp file to run, it can catpure your screen and save hello.bmp and hello.png files respectively. Good luck!\n#pragma comment(lib,\u0026#34;gdiplus.lib\u0026#34;) #include \u0026lt;windows.h\u0026gt;#include \u0026lt;gdiplus.h\u0026gt;#include \u0026lt;stdio.h\u0026gt;using namespace Gdiplus; int CaptureImage(HWND hWnd, CHAR* dirPath, CHAR* filename); INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid); // helper function INT convert2png(); int main() { CHAR path[100] = \u0026#34;.\\\\\u0026#34;; CHAR filename[100] = \u0026#34;hello\u0026#34;; CaptureImage(GetDesktopWindow(), path, filename); // 保存为 E:hello.bmp convert2png(); return 0; } // By reference: // https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-converting-a-bmp-image-to-a-png-image-use INT convert2png() { // Initialize GDI+. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(\u0026amp;gdiplusToken, \u0026amp;gdiplusStartupInput, NULL); CLSID encoderClsid; Status stat; Image* image = new Image(L\u0026#34;hello.bmp\u0026#34;); // Get the CLSID of the PNG encoder. GetEncoderClsid(L\u0026#34;image/png\u0026#34;, \u0026amp;encoderClsid); //GetEncoderClsid(L\u0026#34;image/jpeg\u0026#34;, \u0026amp;encoderClsid); stat = image-\u0026gt;Save(L\u0026#34;hello.png\u0026#34;, \u0026amp;encoderClsid, NULL); //stat = image-\u0026gt;Save(L\u0026#34;hello.jpg\u0026#34;, \u0026amp;encoderClsid, NULL); if (stat == Ok) printf(\u0026#34;hello.png was saved successfully\\n\u0026#34;); else printf(\u0026#34;Failure: stat = %d\\n\u0026#34;, stat); delete image; GdiplusShutdown(gdiplusToken); return 0; } // By reference: // https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-retrieving-the-class-identifier-for-an-encoder-use int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(\u0026amp;num, \u0026amp;size); if (size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if (pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for (UINT j = 0; j \u0026lt; num; ++j) { if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure } /** * GDI 截取指定窗口 * * 参数 hwnd 要截屏的窗口句柄 * 参数 dirPath 截图存放目录 * 参数 filename 截图名称 */ int CaptureImage(HWND hwnd, CHAR* dirPath, CHAR* filename) { HDC mdc; HBITMAP hbmp; CHAR FilePath[MAX_PATH]; HDC hdcScreen; HDC hdcWindow; HDC hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; RECT rcClient; BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bi; DWORD dwBmpSize; HANDLE hDIB; CHAR* lpbitmap; HANDLE hFile; DWORD dwSizeofDIB; DWORD dwBytesWritten; hdcScreen = GetDC(NULL); // 全屏幕DC hdcWindow = GetDC(hwnd); // 截图目标窗口DC // 创建兼容内存DC hdcMemDC = CreateCompatibleDC(hdcWindow); if (!hdcMemDC) { goto done; } // 获取客户端区域用于计算大小 GetClientRect(hwnd, \u0026amp;rcClient); // 设置延展模式 SetStretchBltMode(hdcWindow, HALFTONE); // 来源 DC 是整个屏幕而目标 DC 是当前的窗口 (HWND) if (!StretchBlt(hdcWindow, 0, 0, rcClient.right, rcClient.bottom, hdcScreen, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY)) { goto done; } // 通过窗口DC 创建一个兼容位图 hbmScreen = CreateCompatibleBitmap( hdcWindow, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top ); if (!hbmScreen) { goto done; } // 将位图块传送到我们兼容的内存DC中 SelectObject(hdcMemDC, hbmScreen); if (!BitBlt( hdcMemDC, // 目的DC 0, 0, // 目的DC的 x,y 坐标 rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, // 目的 DC 的宽高 hdcWindow, // 来源DC 0, 0, // 来源DC的 x,y 坐标 SRCCOPY)) // 粘贴方式 { goto done; } // 获取位图信息并存放在 bmpScreen 中 GetObject(hbmScreen, sizeof(BITMAP), \u0026amp;bmpScreen); bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpScreen.bmWidth; bi.biHeight = bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight; // 在 32-bit Windows 系统上, GlobalAlloc 和 LocalAlloc 是由 HeapAlloc 封装来的 // handle 指向进程默认的堆. 所以开销比 HeapAlloc 要大 hDIB = GlobalAlloc(GHND, dwBmpSize); lpbitmap = (char*)GlobalLock(hDIB); // 获取兼容位图的位并且拷贝结果到一个 lpbitmap 中. GetDIBits( hdcWindow, // 设备环境句柄 hbmScreen, // 位图句柄 0, // 指定检索的第一个扫描线 (UINT)bmpScreen.bmHeight, // 指定检索的扫描线数 lpbitmap, // 指向用来检索位图数据的缓冲区的指针 (BITMAPINFO*)\u0026amp; bi, // 该结构体保存位图的数据格式 DIB_RGB_COLORS // 颜色表由红、绿、蓝(RGB)三个直接值构成 ); wsprintf(FilePath, \u0026#34;%s\\%s.bmp\u0026#34;, dirPath, filename); // 创建一个文件来保存文件截图 hFile = CreateFile( FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); // 将 图片头(headers)的大小, 加上位图的大小来获得整个文件的大小 dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); // 设置 Offset 偏移至位图的位(bitmap bits)实际开始的地方 bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER); // 文件大小 bmfHeader.bfSize = dwSizeofDIB; // 位图的 bfType 必须是字符串 \u0026#34;BM\u0026#34; bmfHeader.bfType = 0x4D42; //BM dwBytesWritten = 0; WriteFile(hFile, (LPSTR)\u0026amp; bmfHeader, sizeof(BITMAPFILEHEADER), \u0026amp;dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)\u0026amp; bi, sizeof(BITMAPINFOHEADER), \u0026amp;dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, \u0026amp;dwBytesWritten, NULL); // 解锁堆内存并释放 GlobalUnlock(hDIB); GlobalFree(hDIB); // 关闭文件句柄 CloseHandle(hFile); // 清理资源 done: DeleteObject(hbmScreen); DeleteObject(hdcMemDC); ReleaseDC(NULL, hdcScreen); ReleaseDC(hwnd, hdcWindow); return 0; } ","permalink":"https://huifeng.me/posts/c-capturescreen-screenshot/","tags":["C++"," C"," win32"," screen"," shot"," capture"],"title":"Capture Screen or Screen Shot [C/C++ win32 api]"},{"categories":["HAProxy"],"contents":" Reference: http://cbonte.github.io/haproxy-dconv/1.9/configuration.html#2.5\n No introduce, no advanced usage, also no tutor for how to install, just config to implement proxy.\nThe case there is so easy so you can get sense of achivement quickly.\nMy Goal If I type ssh username@127.0.0.1 -p80 at vps1(127.0.0.1), it\u0026rsquo;ll connect to vps2(123.123.123.123:22)!\nConditions vps1\u0026rsquo;s port 80 is open vps2\u0026rsquo;s port 22 is open haproxy was installed in vps1(127.0.0.1) Configuration global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners stats timeout 30s user haproxy group haproxy daemon # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private # See: https://ssl-config.mozilla.org/#server=haproxy\u0026amp;server-version=2.0.3\u0026amp;config=intermediate ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets defaults log global mode http # option httplog # option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http frontend tcp-33-front bind *:33 mode tcp default_backend tcp-33-back backend tcp-33-back mode tcp server tcp-33 123.123.123.123:22 check listen test bind *:80 mode tcp server centos 123.123.123.123:22 check port 22 inter 5000 fall 5 Then, run the command below to verify the syntex is right.\nhaproxy -f /etc/haproxy/haproxy.cfg -c No error occur, yeap, run it!\nhaproxy -f /etc/haproxy/haproxy.cfg Now, you can run ssh -p33 vagrant@127.0.0.1 or ssh -p80 vagrant@127.0.0.1 to connect to vps2(123.123.123.123) on ssh:22.\nSimple Working Principle This is core config:\nfrontend tcp-33-front bind *:33 mode tcp default_backend tcp-33-back backend tcp-33-back mode tcp server tcp-33 123.123.123.123:22 check listen test bind *:80 mode tcp server centos 123.123.123.123:22 check port 22 inter 5000 fall 5 also, you can just use one part of it!\nlisten style: All data access to port 80 will pass to 22!\nlisten test bind *:80 mode tcp server centos 123.123.123.123:22 check port 22 inter 5000 fall 5 OR\nAll data access to port 33 will pass to 22!\nfrontend tcp-33-front bind *:33 mode tcp default_backend tcp-33-back backend tcp-33-back mode tcp server tcp-33 123.123.123.123:22 check haproxy process look up: ps -ef | grep haproxy .\nBind ports! Reference: http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#bind\n It is possible to specify a list of address:port combinations delimited by commas. There is no fixed limit to the number of addresses and ports which can be listened on in a frontend, as well as there is no limit to the number of \u0026ldquo;bind\u0026rdquo; statements in a frontend.\n SO, YOU CAN WRITE frontend like this:\nbind :33, :44 bind 10.0.0.1:55, 10.0.0.1:66 EOF\n","permalink":"https://huifeng.me/posts/haproxy-simple-usage/","tags":["HAProxy"," proxy"," example"],"title":"HAProxy Simple Usage"},{"categories":["C/C++"],"contents":"Continuous update!\nMisc VC6.0 non-console program output debugging method: download DebugView and run, insert code below to you program: OutputDebugString(charParam); OutputDebugStringW(wchar_tParam); how to fix, while VC6.0 console in the debugger after can not be closed:\n vc++6.0中调试程序后出来的控制台关不掉怎么办 somewhat maybe your OS based on x64 \u0026ldquo;a string \u0026quot; + 123 -\u0026gt; \u0026ldquo;a string 123\u0026rdquo;:\n i = 1; char stringMerged[100] = { 0 }; sprintf(stringMerged, \u0026#34;%s%d\u0026#34;, filename, i); // stringMerged == \u0026#34;a string \u0026#34;, i == 123 // now, stringMerged == \u0026#34;a string 123\u0026#34; \u0026lsquo;wcslen\u0026rsquo; : cannot convert parameter 1 from \u0026lsquo;char [260]\u0026rsquo; to \u0026lsquo;const unsigned short *\u0026rsquo;\n get argv[1]:\n char* filename = new char[argv[1].length() + 1]; strcpy(filename, keyword.c_str()); // now, filename is the first arg\u0026#39;s value get arguments from WinMain()\u0026rsquo;s lpCmdLine: method one: #include \u0026lt;stdlib.h\u0026gt;... int argc = __argc;; char** argv = __argv; ... + mothod two: [CommandLineToArgvW function](https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw) Example for the using above: #include \u0026#34;stdafx.h\u0026#34;#include \u0026lt;windows.h\u0026gt;#include \u0026lt;stdio.h\u0026gt; // for sprintf#include \u0026lt;stdlib.h\u0026gt; // Forward declarations: int main(int argc, char* argv[]); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char** argv = __argv; main(argc, argv); return 0; } int main(int argc, char* argv[]) { char args[100] = \u0026#34;appName.exe\u0026#34;; if(argc == 2) { sprintf(args, \u0026#34;%s %s\u0026#34;, args, argv[1]); } if(argc == 3) { sprintf(args, \u0026#34;%s %s %s\u0026#34;, args, argv[1], argv[2]); } WinExec(args,SW_HIDE); return 0; } Useful functions Create Dir: #define R_OK 4 /* Test for read permission. */#define W_OK 2 /* Test for write permission. */#define X_OK 1 /* Test for execute permission. */#define F_OK 0 /* Test for existence. */int DirCreate(string path) { // if _access(path.c_str(), R_OK) == 0 the folder exist! if (_access(path.c_str(), R_OK) == -1) // vc6.0 { int flag = _mkdir(path.c_str()); // mkdir successfully return 0 return flag; } return 0; } Get Tmp folder: char tmp[200]; int GetTmp() { DWORD dwRetVal = 0; TCHAR szTempFileName[MAX_PATH]; TCHAR lpTempPathBuffer[MAX_PATH]; HANDLE hFile = INVALID_HANDLE_VALUE; dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer); if (dwRetVal \u0026lt; MAX_PATH || (dwRetVal != 0)) { memset(tmp, 0, 200); wcstombs(tmp, lpTempPathBuffer, wcslen(lpTempPathBuffer) + 1); } return 0; } Convert types const char* to char*: strdup(\u0026#34;My string literal!\u0026#34;); // method one // or (char*)\u0026#34;My string literal!\u0026#34; // method two char* argv[] to int: char *p; capNum = strtol(argv[2], \u0026amp;p, 10); char [] to wchar_t* char filepath[100] = { 0 }; filepath = \u0026#34;filename\u0026#34;; wchar_t* wfilepath = new wchar_t[50]; swprintf(wfilepath, L\u0026#34;%hs\u0026#34;, filepath); // vc6.0 swprintf(wfilepath, 50, L\u0026#34;%hs\u0026#34;, filepath); // vs2015 vs2019 char* to string: char *buf = \u0026#34;test\u0026#34;; string s = buf; // or char *buf = \u0026#34;test\u0026#34;; std::string s(buf); // or char *buf = \u0026#34;test\u0026#34;; std::string s(buf, sizeof(buf)); ","permalink":"https://huifeng.me/posts/program-c-basic-tips/","tags":["C++"," C"," win32"," debug"," functions"," convert"," char"," int"],"title":"Program C Basic Tips [C/C++]"},{"categories":["Nginx"],"contents":"{% centerquote %} 让你的网站 https 起来吧! {% endcenterquote %}\n1. Enable TLS Reference: https://letsencrypt.org https://certbot.eff.org\n 1.1. Setup Certbot Enable EPEL repo:\n$ sudo yum install epel-release $ sudo yum install subscription-manager $ subscription-manager repos --enable \u0026quot;rhel-*-optional-rpms\u0026quot; --enable \u0026quot;rhel-*-extras-rpms\u0026quot; If you are using CentOS, you can enable the optional channel by running:\n$ sudo yum -y install yum-utils $ sudo yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional After doing this, you can install Certbot by running:\n$ sudo yum install certbot python2-certbot-nginx If No package certbot available. occur, try the below:\n$ sudo yum install certbot-nginx 1.2. Enable TLS $ sudo certbot --nginx {% note default %}\nBut, Notice! If you install nginx by source make, you need to set options like above:\n$ sudo certbot --nginx --nginx-ctl /usr/local/nginx/nginx --nginx-server-root /usr/local/nginx {% endnote %}\nThen currect resulted is similar below:\nIMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/kelimelerdunyasi.org/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/kelimelerdunyasi.org/privkey.pem Your cert will expire on 2019-07-23. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the \u0026quot;certonly\u0026quot; option. To non-interactively renew *all* of your certificates, run \u0026quot;certbot renew\u0026quot; - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le 2. Automating renewal 2.1.Test Test automatic renewal for your certificates by running this command:\n$ sudo certbot renew --dry-run return:\nSaving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/kelimelerdunyasi.org.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cert not due for renewal, but simulating renewal for dry run Plugins selected: Authenticator nginx, Installer nginx Starting new HTTPS connection (1): acme-staging-v02.api.letsencrypt.org Renewing an existing certificate Performing the following challenges: http-01 challenge for kelimelerdunyasi.org Waiting for verification... Cleaning up challenges Resetting dropped connection: acme-staging-v02.api.letsencrypt.org - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - new certificate deployed with reload of nginx server; fullchain is /etc/letsencrypt/live/kelimelerdunyasi.org/fullchain.pem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ** DRY RUN: simulating \u0026#39;certbot renew\u0026#39; close to cert expiry ** (The test certificates below have not been saved.) Congratulations, all renewals succeeded. The following certs have been renewed: /etc/letsencrypt/live/kelimelerdunyasi.org/fullchain.pem (success) ** DRY RUN: simulating \u0026#39;certbot renew\u0026#39; close to cert expiry ** (The test certificates above have not been saved.) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. If return contain Congratulations, all renewals succeeded. means configuration is current.\n2.2. Automating renewal setup sudo crontab -e Insert line below:\n00 00 * * 1 certbot renew --post-hook \u0026#34;/usr/local/nginx/nginx -s reload\u0026#34; Than, certificate will renewal every week.\n2.3. Verify the certificate Visit https://www.ssllabs.com to verify certificate\n EOF\n","permalink":"https://huifeng.me/posts/how-to-enable-tls-in-nginx-by-letsencrypt/","tags":["nginx"," https"," tls"],"title":"How to enable TLS in Nginx by Let's Encrypt"},{"categories":["Hexo"],"contents":"{% centerquote 王小波 %} 人的一切痛苦,本质上都是对自己无能的愤怒。 {% endcenterquote %}\nWhy Utterances? The most similar comments to github issue. Emoji add free as github issue. Markdown support. Data storage can be trusted and stable, thanks to github. But my choice is Valine Oh my, after study utterances, I have to changed my choice to Valine:\n utterances need to modify many theme files, I think I\u0026rsquo;ll forget where to restore it. utterances\u0026rsquo;s replies are not smart enough. utterances has more differ from github issue after all, it lost some great features like reply. utterances cannot display count of comments at home page. Valine not the best one but enough for me, except add emoji free to bottom line. So, this post is just a study and successful attempt for utterances.\nWhy not Gitment or Gitalk? Reference:\n https://github.com/imsun/gitment#is-it-safe-to-make-my-client-secret-public https://blog.wolfogre.com/posts/security-problem-of-gitment/ How to use Utterances? Fill out: utterances -\u0026gt; configuration, you can get a script.\nThen:\ntouch \u0026lt;your theme path\u0026gt;/layout/_third-party/comments/utterances.swig vim \u0026lt;your theme path\u0026gt;/layout/_third-party/comments/utterances.swig Add code below to utterances.swig:\n{% if theme.utterances.enable %} \u0026lt;script src=\u0026#34;https://utteranc.es/client.js\u0026#34; repo=\u0026#34;{{ theme.utterances.repo }}\u0026#34; issue-term=\u0026#34;{{ theme.utterances.issue_term }}\u0026#34; label=\u0026#34;{{ theme.utterances.label }}\u0026#34; theme=\u0026#34;{{ theme.utterances.theme }}\u0026#34; crossorigin=\u0026#34;anonymous\u0026#34; async\u0026gt; \u0026lt;/script\u0026gt; {% endif %} vim \u0026lt;your theme path\u0026gt;/layout/_partials/comments.swig Refer to the following to modify comments.swig:\n{% elseif theme.valine.enable and theme.valine.appid and theme.valine.appkey %} \u0026lt;div class=\u0026#34;comments\u0026#34; id=\u0026#34;comments\u0026#34;\u0026gt; \u0026lt;/div\u0026gt; + + {% elseif theme.utterances.enable %} + \u0026lt;div class=\u0026#34;comments\u0026#34; id=\u0026#34;comments\u0026#34;\u0026gt; + {% include \u0026#39;../_third-party/comments/utterances.swig\u0026#39; %} + \u0026lt;/div\u0026gt; {% endif %} vim \u0026lt;your theme path\u0026gt;/_config.yml Add following to _config.yml:\nutterances: enable: true repo: # owner/repo issue_term: # pathname, url, title, og:title [ISSUE NUMBER] or [SPECIFIC TERM] theme: # github-light or github-dark label: 💬Comments # The label must exist in your repo, mine is 💬Comments {% note danger %} Tips:\n currect format: repo: # owner/repo wrong format: repo: # https://github.com/owner/repo.git {% endnote %} Reference:\n https://www.njphper.com/posts/a4cd94b2.html https://wangjiezhe.com/posts/2018-10-29-Hexo-NexT-3/\n EOF\n","permalink":"https://huifeng.me/posts/use-utteranc-as-hexo-comments/","tags":["hexo"," Utterances"," next"],"title":"Use utterances as Hexo Next theme comments"},{"categories":["python"],"contents":"I coped with character type coversion to let it looks like c type, and search bytes from *.dll to modify it. so, there is sth I learned and written down here.\n# Binary I/O operation Define!\ndef hex_read(filepath: str) -\u0026gt; bytearray: if os.path.isfile(filepath): with open(filepath, \u0026#39;rb\u0026#39;) as f: data = bytearray(f.read()) return data Usage:\ndll_data = hex_read(\u0026#39;D:\\\\test\\\\test.dll\u0026#39;) Find bytes and replace it:\nindex_start = dll_data.find(b\u0026#39;\\x85\\x69\\xf0\\x7f\u0026#39;) index_end = index_start + 100 if index_start != -1: data_old = dll_data[index_start:index_end] data_new = replacebytes # replacebytes is the content you want to replace dll_data_new = dll_data.replace(data_old, data_new) with open(\u0026#39;D:\\\\test\\\\test.dll\u0026#39;, \u0026#39;wb\u0026#39;) as f: f.write(dll_data_new) ","permalink":"https://huifeng.me/posts/binary-io-operation/","tags":["binary"," bytes"," read"," write"," python"," bytearray"],"title":"Binary I/O operation"},{"categories":["python"],"contents":" Reference:\n https://docs.python.org/zh-cn/3/library/stdtypes.html https://docs.python.org/zh-cn/3/library/struct.html # Python Types Coversion hey, there are some usefull features below, I will update at intervals:\nbit_length() New in version 3.1:\nIn [73]: n = -37 In [74]: bin(n) Out[74]: '-0b100101' In [75]: n.bit_length() Out[75]: 6 hex to int:\nIn [59]: int('0x22357', 16) Out[59]: 140119 int to hex:\nIn [32]: hex(141128) Out[32]: '0x22748' packed binary data to int:\nIn [70]: struct.unpack(\u0026quot;I\u0026quot;, b'\\x57\\x23\\x02\\x00') Out[70]: (140119,) In [71]: type(struct.unpack(\u0026quot;I\u0026quot;, b'\\x57\\x23\\x02\\x00')) Out[71]: tuple In [72]: struct.unpack(\u0026quot;I\u0026quot;, b'\\x57\\x23\\x02\\x00')[0] Out[72]: 140119 what is param \u0026ldquo;I\u0026rdquo;? Read More about struct int to packed binary data:\nIn [91]: struct.pack('I', 140119) Out[91]: b'W#\\x02\\x00' In [92]: struct.pack('I', 140119).hex() Out[92]: '57230200' ","permalink":"https://huifeng.me/posts/hex-b-str-int-switch-in-python/","tags":["hex"," byte"," string"," int"," python"," covert"],"title":"Hex byte string int coversion"},{"categories":["翻墙"],"contents":"Reference: https://toutyrater.github.io/prep/install.html\n# 1. Install Install or update by script:\nwget https://install.direct/go.sh sudo bash go.sh Return:\nPORT:111 UUID:9d1712fd-f641-4be9-b2ca-99c9dc000aeb # 2. Config 2.1. WebSocket+TLS+Web Stable but not fast!\nServer /etc/v2ray/config.json :\n{ \u0026#34;inbounds\u0026#34;: [{ \u0026#34;port\u0026#34;: 111, \u0026#34;listen\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;clients\u0026#34;: [ { \u0026#34;id\u0026#34;: \u0026#34;9d1712fd-f641-4be9-b2ca-99c9dc000aeb\u0026#34;, \u0026#34;level\u0026#34;: 1, \u0026#34;alterId\u0026#34;: 64 } ] }, \u0026#34;streamSettings\u0026#34;: { \u0026#34;network\u0026#34;: \u0026#34;ws\u0026#34;, \u0026#34;wsSettings\u0026#34;: { \u0026#34;path\u0026#34;: \u0026#34;/wahaha\u0026#34; } } }], \u0026#34;outbounds\u0026#34;: [{ \u0026#34;protocol\u0026#34;: \u0026#34;freedom\u0026#34;, \u0026#34;settings\u0026#34;: {} }] } Client:\n{ \u0026#34;inbounds\u0026#34;: [ { \u0026#34;port\u0026#34;: 1080, \u0026#34;listen\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;protocol\u0026#34;: \u0026#34;socks\u0026#34;, \u0026#34;sniffing\u0026#34;: { \u0026#34;enabled\u0026#34;: true, \u0026#34;destOverride\u0026#34;: [\u0026#34;http\u0026#34;, \u0026#34;tls\u0026#34;] }, \u0026#34;settings\u0026#34;: { \u0026#34;auth\u0026#34;: \u0026#34;noauth\u0026#34;, \u0026#34;udp\u0026#34;: false } } ], \u0026#34;outbounds\u0026#34;: [ { \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;vnext\u0026#34;: [ { \u0026#34;address\u0026#34;: \u0026#34;mydomain.me\u0026#34;, \u0026#34;port\u0026#34;: 443, \u0026#34;users\u0026#34;: [ { \u0026#34;id\u0026#34;: \u0026#34;9d1712fd-f641-4be9-b2ca-99c9dc000aeb\u0026#34;, \u0026#34;alterId\u0026#34;: 64 } ] } ] }, \u0026#34;streamSettings\u0026#34;: { \u0026#34;network\u0026#34;: \u0026#34;ws\u0026#34;, \u0026#34;security\u0026#34;: \u0026#34;tls\u0026#34;, \u0026#34;wsSettings\u0026#34;: { \u0026#34;path\u0026#34;: \u0026#34;/ray\u0026#34; } } } ] } 2.2. mKCP Server /etc/v2ray/config.json :\n{ \u0026#34;inbounds\u0026#34;: [ { \u0026#34;port\u0026#34;: 16823, \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;clients\u0026#34;: [ { \u0026#34;id\u0026#34;: \u0026#34;b831381d-6324-4d53-ad4f-8cda48b30811\u0026#34;, \u0026#34;alterId\u0026#34;: 64 } ] }, \u0026#34;streamSettings\u0026#34;: { \u0026#34;network\u0026#34;: \u0026#34;mkcp\u0026#34;, \u0026#34;kcpSettings\u0026#34;: { \u0026#34;uplinkCapacity\u0026#34;: 5, \u0026#34;downlinkCapacity\u0026#34;: 100, \u0026#34;congestion\u0026#34;: true, \u0026#34;header\u0026#34;: { \u0026#34;type\u0026#34;: \u0026#34;wechat-video\u0026#34; } } } } ], \u0026#34;outbounds\u0026#34;: [ { \u0026#34;protocol\u0026#34;: \u0026#34;freedom\u0026#34;, \u0026#34;settings\u0026#34;: {} } ] } Client:\n{ \u0026#34;inbounds\u0026#34;: [ { \u0026#34;port\u0026#34;: 1080, \u0026#34;protocol\u0026#34;: \u0026#34;socks\u0026#34;, \u0026#34;sniffing\u0026#34;: { \u0026#34;enabled\u0026#34;: true, \u0026#34;destOverride\u0026#34;: [\u0026#34;http\u0026#34;, \u0026#34;tls\u0026#34;] }, \u0026#34;settings\u0026#34;: { \u0026#34;auth\u0026#34;: \u0026#34;noauth\u0026#34; } } ], \u0026#34;outbounds\u0026#34;: [ { \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;vnext\u0026#34;: [ { \u0026#34;address\u0026#34;: \u0026#34;serveraddr.com\u0026#34;, \u0026#34;port\u0026#34;: 16823, \u0026#34;users\u0026#34;: [ { \u0026#34;id\u0026#34;: \u0026#34;b831381d-6324-4d53-ad4f-8cda48b30811\u0026#34;, \u0026#34;alterId\u0026#34;: 64 } ] } ] }, \u0026#34;streamSettings\u0026#34;: { \u0026#34;network\u0026#34;: \u0026#34;mkcp\u0026#34;, \u0026#34;kcpSettings\u0026#34;: { \u0026#34;uplinkCapacity\u0026#34;: 5, \u0026#34;downlinkCapacity\u0026#34;: 100, \u0026#34;congestion\u0026#34;: true, \u0026#34;header\u0026#34;: { \u0026#34;type\u0026#34;: \u0026#34;none\u0026#34; } } } } ] } ","permalink":"https://huifeng.me/posts/v2ray-install-and-config/","tags":["v2ray"," config"," websocket"," tls"," caddy"," kcp"],"title":"V2ray install and config"},{"categories":["Hexo"],"contents":"There are steps to make Hexo works well with caddy, github webhooks and service script write by python3.\nWhy not nginx, because I know well about it, I think, and now I want to try caddy.\nWhy not git to deploy it? This is the way to use git for deployment. But it was outdated or I think, use webhooks and caddy maybe the pop and better way than that.\nThis is not as common use for webhooks, the main idear for easy to write hexo blog is follow:\n One github\u0026rsquo;s repository cloned at your local system: Only write your md files at there. Two folders at VPS to clone your md files and generate by hexo for deploy.\nAdvantage: Write blog so easy, just write down and push to github. Generate at server, so you never need install hexo to your local system, so you can write and push anywhere have git installed Generate at server, so it will stable and faster than local.\nDisadvantage: Many settings and preparations at VPS.\n My System environment:\n Local: Windows 10 VPS: Ubuntu 18.04 LTS OK, let\u0026rsquo;s GO!\nOutline:\n Preparation for your host: git Preparation for your VPS: git, Node.js, Hexo, webhook scripts Install and config Caddy to your VPS My Tree:\n LocalMachine: blog/blog_md - for blogs write. VPS: /var/www/blog - for generated files public ~/blog - Init by hexo,we generate here. ~/blog_static - git clone from repository, the repository is used for push and target webhooks. ~/blog_static/blog_md - subfolder of repository, contains blog md files. ~/webhook-server.py - listen for webhook. ~/webhook.sh - call by webhook-server.py for deploy. # 1. VPS Preparations This step is the preparation for using github webhook.\n1.1. Install git and node.js Git is very simple and nothing to say, simply say Node.js.\nRun the command below to show a list of versions available for download and install the last LTS version:\ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash nvm ls-remote nvm install 10.16.0 nvm on # or nvm use 10.16.0 node -v Return: v10.16.0\n1.2. Install Hexo on VPS npm install -g hexo-cli npm install hexo-server -g cd \u0026lt;blog folder\u0026gt; hexo init If error occur ERROR Local hexo not found in \u0026lt;blog folder\u0026gt;, run:\nnpm install hexo --save Then:\nnpm install If occur: found 1 moderate severity vulnerability, run:\nnpm audit fix --force Then:\nhexo init 1.3. Github hooks 1.3.1. Add webhook at respository where your md files placed Payload URL resemble: http://huifeng.me:123/webhook Content type: the default content type of application/json is fine. 1.3.2. Write a python webhook-server.py: 1st Way authenticate the hook conveniently (Recommend)\nA easy way for enable secret: GitHub Webhook (micro) Framework It also can do anything about webhooks, but documents is so poor.\nEnvironment Prepare:\nsudo apt install python3-pip pip3 install flask pip3 install github_webhook My final webhook-server.py (run as python3):\nimport os from github_webhook import Webhook from flask import Flask app = Flask(__name__) # Standard Flask app webhook = Webhook(app, endpoint=\u0026#34;/testendpoint\u0026#34;, secret=\u0026#39;testsecret\u0026#39;) # Defines \u0026#39;/postreceive\u0026#39; endpoint @app.route(\u0026#34;/\u0026#34;) # Standard Flask endpoint def hello_world(): return \u0026#34;Hello, World!\u0026#34; @webhook.hook() # Defines a handler for the \u0026#39;push\u0026#39; event def on_push(data): #print(\u0026#34;Got push with: {0}\u0026#34;.format(data)) print(os.popen(\u0026#34;sh ~/webhook.sh\u0026#34;).read()) if __name__ == \u0026#34;__main__\u0026#34;: try: port_number = int(sys.argv[1]) except: port_number = 8888 app.run(host=\u0026#34;0.0.0.0\u0026#34;, port=port_number, debug=False) Key settings:\n If code is webhook = Webhook(app, endpoint=\u0026quot;/testendpoint\u0026quot;, secret='testsecret'):\n Payload URL setting is resemble: http://huifeng.me:8888/testendpoint Secret setting is testsecret If with no secret setting:\n webhook = Webhook(app, endpoint=\u0026quot;/testendpoint\u0026quot;) If nothing defined yourself, code is webhook = Webhook(app):\n Default way: /postreceive Without secret verification. 2nd Way without authenticate but simple (Optional)\nWithout authenticate but easy, a way to study but suggust not use in Ops.\n#!/usr/bin/env python # -*- coding: utf-8 -*- import json import os import traceback from flask import Flask, request app = Flask(__name__) @app.route(\u0026#39;/webhook\u0026#39;, methods=[\u0026#39;POST\u0026#39;]) def update(): if request.method == \u0026#39;POST\u0026#39;: try: print request.headers print request.json print os.popen(\u0026#34;sh ~/webhook.sh\u0026#34;).read() except: print traceback.format_exc() return json.dumps({\u0026#34;msg\u0026#34;: \u0026#34;error method\u0026#34;}) if __name__ == \u0026#39;__main__\u0026#39;: try: port_number = int(sys.argv[1]) except: port_number = 8888 app.run(host=\u0026#34;0.0.0.0\u0026#34;, port=port_number, debug=False) You can enable secret by yourself(Optional choise) or jump to 1st Way: Give the abilitiy to authenticate the hook by sercet. we can modify the python code above, the core is:\nimport hmac header_signature = request.META.get(\u0026#39;HTTP_X_HUB_SIGNATURE\u0026#39;) signature = header_signature.split(\u0026#39;=\u0026#39;) mac = hmac.new(\u0026#39;YOUR GITHUB WEBHOOK SECRET\u0026#39;.encode(\u0026#39;utf-8\u0026#39;), request.body, hash_type).hexdigest() if hmac.compare_digest(mac, signature): print os.popen(\u0026#34;sh ~/webhook.sh\u0026#34;).read() But, the code above need test, not the final code to run, just a thought!\n1.3.3. Write a shell webhook.sh: #!/usr/bin/env bash cd ~/blog_static git pull https://github.com/wedojava/Blog.git rm -rf ~/blog/source/_posts/* cp -rp ~/blog_static/blog_md/* ~/blog/source/_posts/ cd ~/blog hexo clean hexo generate rm -rf /var/www/blog/* cp -rp ~/blog/public/* /var/www/blog/ 1.3.4. Run in background: nohup python webhook-server.py \u0026amp; Don\u0026rsquo;t warry, you can read logs in file nohup where webhook-server.py located.\nIf your server\u0026rsquo;s environment is not suitable, run the command follow:\nsudo apt install python-pip pip install request flask I suggest test before run in background,you can run the command below to assess the return lines:\npython webhook-server.py # 2. Install and config Caddy to your VPS 2.1. Directory and permissions prepare Reference: https://caddyserver.com/docs\n Reference:https://github.com/caddyserver/caddy/tree/master/dist/init/linux-systemd\nMain idea: Give website folder appropriate ownership and permission, so if git pushed, python script can catch the webhook event and load shell script to pull, move etc.\n(If your VPS not setted default)Set up the user, group, and directories that will be needed:\nsudo groupadd -g 33 www-data sudo useradd \\ -g www-data --no-user-group \\ --home-dir /var/www --no-create-home \\ --shell /usr/sbin/nologin \\ --system --uid 33 www-data Create caddy folder and give it appropriate ownership and permissions:\nsudo mkdir /etc/caddy sudo chown -R root:root /etc/caddy sudo mkdir /etc/ssl/caddy sudo chown -R root:www-data /etc/ssl/caddy sudo chmod 0770 /etc/ssl/caddy Place your caddy configuration file (\u0026ldquo;Caddyfile\u0026rdquo;) in the proper directory and give it appropriate ownership and permissions:\nsudo cp /path/to/Caddyfile /etc/caddy/ sudo chown root:root /etc/caddy/Caddyfile sudo chmod 644 /etc/caddy/Caddyfile Create the home directory for the server and give it appropriate ownership and permissions:\nsudo mkdir /var/www sudo chown www-data:www-data /var/www sudo chmod 755 /var/www Let\u0026rsquo;s assume you have the contents of your website in a directory called \u0026lsquo;blog\u0026rsquo;. Put your website into place for it to be served by caddy:\nsudo mkdir /var/www/blog sudo chown -R \u0026lt;youruser\u0026gt;:\u0026lt;yourgroup\u0026gt; /var/www/blog sudo chmod -R 755 /var/www/blog 2.2. Config Caddyfile DIffer from other service, for caddy you can make config file first to ensure which plugin is necessary, after config the file, caddy install option will also becoming your mind, you can study how to set it by caddy offical doc: https://caddyserver.com/docs\n/etc/caddy/Caddyfile may resembles below:\nhuifeng.me { root /var/www/blog tls yourusername@gmail.com index index.html # minify gzip log /var/www/access.log { rotate_size 50 # Rotate a log when it reaches 50 MB rotate_age 90 # Keep rotated log files for 90 days rotate_keep 20 # Keep at most 20 rotated log files rotate_compress # Compress rotated log files in gzip format } limits { header 100KB body /download 100MB } errors /var/www/error.log { # 404 404/index.html rotate_size 50 # Rotate a log when it reaches 50 MB rotate_age 90 # Keep rotated log files for 90 days rotate_keep 20 # Keep at most 20 rotated log files rotate_compress # Compress rotated log files in gzip format } } 2.3. Install via script This step requires root privileges, so:\nsu curl https://getcaddy.com | bash -s personal http.cache,http.minify exit Enable Caddy as service:\nNotice!\nIf you assume the following:\n that you want to run caddy as user www-data and group www-data caddy binary in the system wide binary directory: /usr/local/bin/caddy your caddy configuration file (\u0026ldquo;Caddyfile\u0026rdquo;) in the proper directory /etc/caddy/Caddyfile your caddy tls(Letsencrypt-issued certificates) want to write in: /etc/ssl/caddy please preceed:\n# 从 github 下载 systemd 配置文件 sudo curl -s https://raw.githubusercontent.com/mholt/caddy/master/dist/init/linux-systemd/caddy.service -o /etc/systemd/system/caddy.service sudo systemctl daemon-reload # 重新加载 systemd 配置 sudo systemctl enable caddy.service # 设置 caddy 服务自启动 sudo systemctl status caddy.service # 查看 caddy 状态 Else:\nedit /etc/systemd/system/caddy.service to set your right user, group, and so on.\n # 3. Some Tips: If you use caddy, sometimes, web is blank, also viewed by source, maybe, your Caddyfile have something wrong or your vps cannot support some feature well, so, comment out line by line and test. For me, I commented minify, ext while the blank page occured, and it fixed.\n About Github hooks, if python and shell is allright, but still cannot works well, try to change github setting of webhooks, set Payload URL as http://your-url not https.\n EOF\nThanks for https://www.jianshu.com/p/75274647c4b0\n","permalink":"https://huifeng.me/posts/deploy-hexo-to-vps-by-caddy-and-webhooks/","tags":["VPS"," hexo"," 部署"," caddy"," python"],"title":"Deploy Hexo to VPS By Caddy And Webhooks(Python)"},{"categories":["Linux"],"contents":"1. 服务器环境 系统:CentOS 7.6 防火墙:firewalld\n1.1. 防火墙配置 此防火墙为 CentOS 7.6 自带自启动,默认没有任何通路出去,你只能从外面ping的通,ssh连接,其他什么也做不了。\n下面我们开放两个端口,一个是 80/TCP ,一个是自定义的ssh连接端口 123/TCP.\nRun:\n$ firewall-cmd --permanent --add-port=80/tcp $ firewall-cmd --permanent --add-port=123/tcp firewall-cmd:是Linux提供的操作firewall的一个工具; \u0026ndash;permanent:表示设置为持久; \u0026ndash;add-port:标识添加的端口; \u0026ndash;zone=public:指定的zone为public(不加此参数默认都是添加到这里). 默认的,通过命令行添加的规则会添加到文件: /etc/firewalld/zones/public.xml .\n添加完毕上面的规则后,样子看起来如下:\n\u0026lt;?xml version=\u0026#34;1.0\u0026#34; encoding=\u0026#34;utf-8\u0026#34;?\u0026gt; \u0026lt;zone\u0026gt; \u0026lt;short\u0026gt;Public\u0026lt;/short\u0026gt; \u0026lt;description\u0026gt;For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.\u0026lt;/description\u0026gt; \u0026lt;service name=\u0026#34;dhcpv6-client\u0026#34;/\u0026gt; \u0026lt;service name=\u0026#34;ssh\u0026#34;/\u0026gt; \u0026lt;port protocol=\u0026#34;tcp\u0026#34; port=\u0026#34;80\u0026#34;/\u0026gt; \u0026lt;port protocol=\u0026#34;tcp\u0026#34; port=\u0026#34;61744\u0026#34;/\u0026gt; \u0026lt;/zone\u0026gt; 1.2. firewall常用命令 重启、关闭、开启firewalld.service服务:\nservice firewalld restart 重启 service firewalld start 开启 service firewalld stop 关闭 查看firewall服务状态:\nsystemctl status firewall 查看firewall的状态:\nfirewall-cmd --state 查看防火墙规则:\nfirewall-cmd --list-all 关闭firewall:\nservice firewalld stop systemctl disable firewalld.service #禁止firewall开机启动 2. Docker 安装和配置 Quick reference:\n https://docs.docker.com/get-started/ https://docs.docker.com/install/linux/docker-ce/centos/ 主要依赖帮助页操作的,下面的是我操作过程中的命令:\n2.1.Uninstall old versions $ sudo yum remove docker \\ docker-client \\ docker-client-latest \\ docker-common \\ docker-latest \\ docker-latest-logrotate \\ docker-logrotate \\ docker-selinux \\ docker-engine-selinux \\ docker-engine 2.2. Install using the repository $ sudo yum install -y yum-utils \\ device-mapper-persistent-data \\ lvm2 $ sudo yum-config-manager \\ --add-repo \\ https://download.docker.com/linux/centos/docker-ce.repo $ sudo yum-config-manager --enable docker-ce-edge $ sudo yum-config-manager --enable docker-ce-test $ sudo yum install docker-ce 2.3. Uninstall Docker CE Uninstall the Docker package:\n$ sudo yum remove docker-ce Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:\n$ sudo rm -rf /var/lib/docker 3. Nginx 安装和配置 3.1. Install by docker https://hub.docker.com/_/nginx?tab=description\n再三考虑,Docker用于生产环境心里没底,主要是两个方面:\n 成本问题,总之还是需要更成熟稳定的东西 安全问题,服务器安装的东西越少,漏洞越少,越安全。 3.2. Install from source Download from http://nginx.org/en/download.html\nThen:\n$ tar zxf nginx....tar.gz $ cd nginx.... Download and unzip required packages:\nwget \u0026#34;https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz\u0026#34;; wget \u0026#34;https://www.openssl.org/source/openssl-1.0.1j.tar.gz\u0026#34;; wget \u0026#34;http://zlib.net/zlib-1.2.11.tar.gz\u0026#34;; tar zxf openssl-1.0.1j.tar.gz; tar zxf pcre-8.42.tar.gz; tar zxf zlib-1.2.11.tar.gz Prepare user for nginx:\n$ sudo groupadd -r nginx $ sudo useradd -s /sbin/nologin -g nginx -r nginx Generate config string throw http://nginx.org/en/docs/configure.html\n./configure \\ --sbin-path=/usr/local/nginx/nginx \\ --conf-path=/usr/local/nginx/nginx.conf \\ --pid-path=/usr/local/nginx/nginx.pid \\ --user=nginx \\ --group=nginx \\ --with-http_ssl_module \\ --with-http_sub_module \\ --with-pcre=../pcre-8.42 \\ --with-zlib=../zlib-1.2.11 \\ --with-openssl=../openssl-1.0.1j After above result blow:\nConfiguration summary + using PCRE library: ../pcre-8.42 + using OpenSSL library: ../openssl-1.0.1j + using zlib library: ../zlib-1.2.11 nginx path prefix: \u0026#34;/usr/local/nginx\u0026#34; nginx binary file: \u0026#34;/usr/local/nginx/nginx\u0026#34; nginx modules path: \u0026#34;/usr/local/nginx/modules\u0026#34; nginx configuration prefix: \u0026#34;/usr/local/nginx\u0026#34; nginx configuration file: \u0026#34;/usr/local/nginx/nginx.conf\u0026#34; nginx pid file: \u0026#34;/usr/local/nginx/nginx.pid\u0026#34; nginx error log file: \u0026#34;/usr/local/nginx/logs/error.log\u0026#34; nginx http access log file: \u0026#34;/usr/local/nginx/logs/access.log\u0026#34; nginx http client request body temporary files: \u0026#34;client_body_temp\u0026#34; nginx http proxy temporary files: \u0026#34;proxy_temp\u0026#34; nginx http fastcgi temporary files: \u0026#34;fastcgi_temp\u0026#34; nginx http uwsgi temporary files: \u0026#34;uwsgi_temp\u0026#34; nginx http scgi temporary files: \u0026#34;scgi_temp\u0026#34; Install:\n$ make \u0026amp;\u0026amp; make install Control Nginx by systemctl:\nReference: https://blog.csdn.net/qq_17054659/article/details/77186249\nCreate nginx.service:\nsudo touch /usr/lib/systemd/system/nginx.service And edit:\nsudo vim /usr/lib/systemd/system/nginx.service As:\n[Unit] Description=nginx - high performance web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStartPre=/usr/local/nginx/nginx -t -c /usr/local/nginx/nginx.conf ExecStart=/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf ExecReload=/usr/local/nginx/nginx -s reload ExecStop=/usr/local/nginx/nginx -s stop ExecQuit=/usr/local/nginx/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target Change mode:\nsudo chmod 754 /usr/lib/systemd/system/nginx.service Make it become effective:\nsudo systemctl daemon-reload Now,systemctl start/stop/reload/quit nginx.service can be use for control nginx convenient.\n 4. Install PHP 7 On CentOS 7.6 Reference: http://php.net/manual/zh/install.unix.nginx.php\n4.1. Prepare for install Download php:\n$ wget http://php.net/distributions/php-7.3.1.tar.gz $ tar zxf php-7.3.1.tar.gz $ cd php-7.3.1 sudo yum install libxml2-devel Prepare user for php-fpm:\n$ sudo groupadd -r www-data $ sudo useradd -s /sbin/nologin -g www-data -r www-data 4.2. Install PHP 7 Go to PHP folder which we just un ziped.\n./configure --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data make \u0026amp;\u0026amp; sudo make install Then, the end return lines like:\nWrote PEAR system config file at: /usr/local/etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_path /home/vagrant/php-7.0.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin ln -s -f phar.phar /usr/local/bin/phar Installing PDO headers: /usr/local/include/php/ext/pdo/ Run:\nsudo /home/vagrant/php-7.0.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin sudo ln -s -f phar.phar /usr/local/bin/phar Copy ini and execute file(All of these files are in php folder we unziped.):\ncp php.ini-production /usr/local/php/php.ini cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf cp sapi/fpm/php-fpm /usr/local/bin Fix bug:\n$ sudo /usr/local/bin/php-fpm [12-May-2016 04:39:05] ERROR: Unable to globalize \u0026#39;/usr/local/NONE/etc/php-fpm.d/*.conf\u0026#39; (ret=2) from /usr/local/etc/php-fpm.conf at line 125. [12-May-2016 04:39:05] ERROR: failed to load configuration file \u0026#39;/usr/local/etc/php-fpm.conf\u0026#39; [12-May-2016 04:39:05] ERROR: FPM initialization failed Modify /usr/local/etc/php-fpm.conf the last line:\n/NONE/etc/php-fpm.d/*.conf as:\netc/php-fpm.d/*.conf copy default conf file:\ncp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf Modify user and group as:\nuser = www-data group = www-data All right! Run php-fpm:\n/usr/local/bin/php-fpm 以上,如何让 PHP 和 NginX 协同工作,请参考:\nhttp://huifeng.me/2016/05/18/LEMP-step-to-step/\n","permalink":"https://huifeng.me/posts/install-nginx-php7-and-config-firewalld-in-centos-7.6/","tags":["centos"," linux"," firewalld"," docker"," php"," nginx"],"title":"Install nginx php7 and config firewalld in CentOS 7.6"},{"categories":null,"contents":"Contact: Mail:wedojava@gmail.com\n Donate: ","permalink":"https://huifeng.me/about/","tags":null,"title":"About Me"},{"categories":["Microsoft"],"contents":"You can download logParser from microsoft : https://www.microsoft.com/en-us/download/confirmation.aspx?id=24659\n# 1. In short, run: LogParser \u0026#34;select [#Fields: date-time] as date, sender-address, recipient-address, recipient-count, return-path, client-hostname, client-ip, server-hostname, server-ip, original-client-ip, original-server-ip, event-id, total-bytes, connector-id, message-subject, source into C:\\ExChange\\log_all\\result.csv from C:\\ExChange\\log_all\\MessageTracking\\*.LOG\u0026#34; -i:CSV -headerRow:on -nSkipLines:4 code above can export all logs to one csv file.\n -nSkipLines:4 : filter 4 lines at begin.the log files\u0026rsquo; first 4 lines is the head of file,no need for export. [#Fields: date-time] as date : style like #Fields: date-time is complex title for csv, make it like [#Fields: date-time] can get the true info from log files. # 2. how to get the right titles? LogParser \u0026#34;select TOP 1 * into C:\\ExChange\\log_all\\result.csv from C:\\ExChange\\log_all\\MessageTracking\\MSGTRK.LOG\u0026#34; -i:CSV -headerRow:on -nSkipLines:4 Refer : https://blog.miniasp.com/post/2008/10/02/Useful-tool-Powerful-Log-Parser.aspx\n","permalink":"https://huifeng.me/posts/exchange-logs-to-csv-by-logparser/","tags":["exchange"," logs"," csv"," logparser"],"title":"how to export exchange logs to csv by logparser"},{"categories":["翻墙"],"contents":"其实我配好的是 Ubuntu 桌面版,如何使用 V2ray,不管什么桌面其实基本大同小异,路子很重要, 路子对了,剩下的就简单了,搞明白后恍然大悟,这么简单就怪自己当时没仔细看文档啊!!!\n本篇是介绍 V2ray 客户端的使用配置的, 服务端的安装请参照本站另一文.\n本篇只讲重点,很多内容官方文档都有说明.\n个人体验是, 如果文档吃透了, 其实命令行的方式启用 V2ray 是最简单的.\n注意,下面的内容都是针对一种情况:我们要配置的机器本来是不能出墙的!\n能出去一切都好办了,对吧.\n1. 我的客户端配置 1.1. config.json { \u0026#34;log\u0026#34;: { \u0026#34;access\u0026#34;: \u0026#34;\u0026#34;, \u0026#34;error\u0026#34;: \u0026#34;\u0026#34;, \u0026#34;loglevel\u0026#34;: \u0026#34;warning\u0026#34; }, \u0026#34;inbound\u0026#34;: { \u0026#34;port\u0026#34;: 1080, // SOCKS 代理端口,在浏览器中需配置代理并指向这个端口 \u0026#34;listen\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;protocol\u0026#34;: \u0026#34;socks\u0026#34;, \u0026#34;domainOverride\u0026#34;: [ \u0026#34;tls\u0026#34;, \u0026#34;http\u0026#34; ], \u0026#34;settings\u0026#34;: { \u0026#34;auth\u0026#34;: \u0026#34;noauth\u0026#34;, \u0026#34;udp\u0026#34;: true, \u0026#34;ip\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;clients\u0026#34;: null }, \u0026#34;streamSettings\u0026#34;: null }, \u0026#34;outbound\u0026#34;: { \u0026#34;tag\u0026#34;: \u0026#34;agentout\u0026#34;, \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;vnext\u0026#34;: [ { \u0026#34;address\u0026#34;: \u0026#34;server\u0026#34;, // 服务器地址,请修改为你自己的服务器 ip 或域名 \u0026#34;port\u0026#34;: 10086, // 服务器端口 \u0026#34;users\u0026#34;: [ { \u0026#34;id\u0026#34;: \u0026#34;b831381d-6324-4d53-ad4f-8cda48b30811\u0026#34;, //客户端和服务器统一的ID号 \u0026#34;alterId\u0026#34;: 0, \u0026#34;email\u0026#34;: \u0026#34;t@t.tt\u0026#34;, \u0026#34;security\u0026#34;: \u0026#34;aes-128-gcm\u0026#34; } ] } ], \u0026#34;servers\u0026#34;: null }, \u0026#34;streamSettings\u0026#34;: { \u0026#34;network\u0026#34;: \u0026#34;tcp\u0026#34;, \u0026#34;security\u0026#34;: \u0026#34;\u0026#34;, \u0026#34;tlsSettings\u0026#34;: null, \u0026#34;tcpSettings\u0026#34;: null, \u0026#34;kcpSettings\u0026#34;: null, \u0026#34;wsSettings\u0026#34;: null, \u0026#34;httpSettings\u0026#34;: null }, \u0026#34;mux\u0026#34;: { \u0026#34;enabled\u0026#34;: true } }, \u0026#34;inboundDetour\u0026#34;: null, \u0026#34;outboundDetour\u0026#34;: [ { \u0026#34;protocol\u0026#34;: \u0026#34;freedom\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;response\u0026#34;: null }, \u0026#34;tag\u0026#34;: \u0026#34;direct\u0026#34; }, { \u0026#34;protocol\u0026#34;: \u0026#34;blackhole\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;response\u0026#34;: { \u0026#34;type\u0026#34;: \u0026#34;http\u0026#34; } }, \u0026#34;tag\u0026#34;: \u0026#34;blockout\u0026#34; } ], \u0026#34;dns\u0026#34;: { \u0026#34;servers\u0026#34;: [ \u0026#34;8.8.8.8\u0026#34;, \u0026#34;8.8.4.4\u0026#34;, \u0026#34;localhost\u0026#34; ] }, \u0026#34;routing\u0026#34;: { \u0026#34;strategy\u0026#34;: \u0026#34;rules\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;domainStrategy\u0026#34;: \u0026#34;IPIfNonMatch\u0026#34;, \u0026#34;rules\u0026#34;: [ { \u0026#34;type\u0026#34;: \u0026#34;field\u0026#34;, \u0026#34;port\u0026#34;: null, \u0026#34;outboundTag\u0026#34;: \u0026#34;direct\u0026#34;, \u0026#34;ip\u0026#34;: [ \u0026#34;0.0.0.0/8\u0026#34;, \u0026#34;10.0.0.0/8\u0026#34;, \u0026#34;100.64.0.0/10\u0026#34;, \u0026#34;127.0.0.0/8\u0026#34;, \u0026#34;169.254.0.0/16\u0026#34;, \u0026#34;172.16.0.0/12\u0026#34;, \u0026#34;192.0.0.0/24\u0026#34;, \u0026#34;192.0.2.0/24\u0026#34;, \u0026#34;192.168.0.0/16\u0026#34;, \u0026#34;198.18.0.0/15\u0026#34;, \u0026#34;198.51.100.0/24\u0026#34;, \u0026#34;203.0.113.0/24\u0026#34;, \u0026#34;::1/128\u0026#34;, \u0026#34;fc00::/7\u0026#34;, \u0026#34;fe80::/10\u0026#34; ], \u0026#34;domain\u0026#34;: null } ] } } } 1.2. 浏览器或其他客户端 代理设置了:127.0.0.1, 端口: 1080\n 2. Windows 玩家 2.1. 客户端模式 官方 Github 分流: https://www.v2ray.com/download/\n选择 V2RayN 或者 V2RayW 均可下载,前者的star数量更高些。\n注意, Core 包也要下载,和 V2RayN/V2RayW 放一个文件夹里\nV2RayN 的配置 类似这样:\n被涂抹的地方就是我填写的服务端的信息.\n就这样就好了.\n2.2. 命令模式 先到这里 https://www.v2ray.com/download/ 下载 Core 包\n 解压, 配置好 config.json 双击打开 v2ray.exe 这样就好了.应该会有个命令行窗口弹出.\n 3. Linux 玩家 3.1. 客户端模式 Snapcraft: https://snapcraft.io/v2ray-core\nLinux利用上面的这个地方就可以完成客户端的下载和安装了,当然你也可以选择通过命令行安装 snap 命令,然后再用 snap 的命令去安装.\n这个办法我没试过,因为墙,所以不保证一定能行.\n3.2 命令行操作 先到这里 https://www.v2ray.com/download/ 下载 Core 包\n 解压, 配置好 config.json 进入解压目录,运行: $ ./v2ray 别试图用命令行执行 go.sh , 因为 GitHub 也是被墙了的.\n 4. 浏览器插件安装 我用的是 chrome 浏览器,如果要翻墙就要设代理,最好是安装好那个 SwitchyOmega 插件,可是我的浏览器翻不了墙才需要装这个插件的,这就是没有鸡怎么生蛋的问题了,所以必须有办法安装上这个插件,一种办法是上网找别人提供的下载位置,还不能是Github的位置,这个有点难,还一个办法就是我要说的办法了.\n通过命令让浏览器挂代理:\n打开 cmd ,然后运行:\ngoogle-chrome-stable --proxy-server=\u0026#34;socks5://127.0.0.1:1080\u0026#34; 这里的1080是端口,一般都是这个,根据你自己的代理客户端设置决定.\n如果你用的不是 chrome 那就该下名字就好了.\n这样打开的浏览器是过代理的,然后你再去下载插件安装插件即可.\n至于配置,网上太多了,去搜吧.\n 5. 终端或其他应用翻墙 5.1 命令翻墙方法 别小看命令翻墙的方式,你可以通过命令行来启动程序从而达到被调用的程序实现翻墙哦!\n命令行终端要翻墙我们一般是用 proxychains-ng 来翻墙,项目主页地址:https://github.com/rofl0r/proxychains-ng\n本文日期时间的下载地址:http://ftp.barfooze.de/pub/sabotage/tarballs/proxychains-ng-4.13.tar.xz\n$ sha512sum proxychains-ng-4.13.tar.xz 686ad90d01f21afa161e35a6fc142a9c9e87c419113c0e54ae4c0ba748be917f34ab17b30a876b825bd4b3f32f15b0793ba8c79a5fafc3b106b3762572349757 proxychains-ng-4.13.tar.xz 关于安装和使用请看苹果系统下的操作,其实基本都是类似的,我也是看压缩包里的README来学习使用的.\nhttp://huifeng.me/2015/08/23/ProxyChains-NG-4-OSX-Setting/\n5.2 代理工具翻墙 推荐 SocksCap 目前还没被墙,可以下载. 实在下载不了了,可以联系我,我必须存一份存货啊.\n","permalink":"https://huifeng.me/posts/the-right-way-make-linux-desktop-use-v2ray-service/","tags":["linux"," v2ray"," ubuntu"," Debian"," proxychains"," proxy"," 代理"," sockscap"],"title":"Linux桌面版 \u0026 Windows 如何使用 V2ray 服务?"},{"categories":["Linux"],"contents":" 参考文档: https://www.linuxidc.com/Linux/2018-05/152390.htm\n本文只讲重点!\n # 1. 安装Pip 我们将使用apt包管理器为 Python 2 pip 和 Python 3 pip3 安装 pip.\n任何时候,要安装先 Update:\nsudo apt update PIP For Python 2.x: sudo apt install python-pip 验证下? pip --version\n PIP For Python 3.x: sudo apt install python3-pip # 2. 安装开发工具 For Python 2.x:\nsudo apt install build-essential python-dev python-setuptools For Python 3.x:\nsudo apt install build-essential python3-dev python3-setuptools # 3. Pip用法 安装卸载名为 foobar 的包: pip install foobar pip uninstall foobar 从PyPI搜索软件包: pip search \u0026#34;search_query\u0026#34; 列出已安装的软件包: pip list 要列出过期的软件包: $pip list --outdated ","permalink":"https://huifeng.me/posts/install-pip-2-ubuntu-18/","tags":["linux"," pip"," python"," ubuntu"],"title":"Install pip to Ubuntu 18.04"},{"categories":["Linux"],"contents":"Ubuntu 18 的宿主机,核心 Update 了,然后要求重启,然后, VMware 起不来了, 报错:\nlinux VM kernel headers 4.15.0-37-generic were not found So, Google and Sogou, and look:\nhttps://blog.csdn.net/ritterliu/article/details/7554183\nhttp://www.vi-toolkit.com/wiki/index.php/Build_host_vmware_kernel_modules\n长话短说,我运行了下面一行,然后就好了! ↓\nsudo apt-get install linux-headers-$(uname -r) Good luck good day!\n","permalink":"https://huifeng.me/posts/fix-vmware-kernel-headers-for-versions-not-found/","tags":["VMware"," kernel"," ubuntu"],"title":"Fix VMware kernel headers for versions not found"},{"categories":["Linux"],"contents":"本文 Debian 9 安装历程,安装包选的是最小版,界面在安装时选择的是 Xfce,选择它是因为它最快!\n本文主要记录联网,VM工具,更换国内源,输入法的安装,让debian的桌面翻墙我新开一页写吧.\n# 1. 系统安装 这个没什么好说的,我都是按照推荐和默认走的,一路安装完毕。\n# 2. 初始配置 2.1. 拨号连接 右键右上角的网络连接标志,选择 Edit Connections =\u0026gt; ADD =\u0026gt; DSL : 填写用户名密码即可,服务为空。\n2.2. sudo 和 vim 2.2.1. 安装 vim 和 sudo $ su # apt-get install sudo # apt-get install vim 2.2.2. 配置 sudo 添加 sudo 命令到用户账号,不需要修改 /etc/sudoers 文件,而是在同一个目录下的 /etc/sudoers.d 目录下添加一个文件,以用户foobar为例:\n# touch /etc/sudoers.d/foobar # vim /etc/sudoers.d/foobar 其内容如下(按 i 键进入 vim 的插入模式):\n\u0026#34;foobar\u0026#34; ALL=(ALL) ALL 按 Esc 退出输入模式,切换到命令模式,然后输入 :wq 保存退出.\n2.3. 安装 VMTools 在VMware的 VM 菜单里可以找到 VMTools 的安装按钮,点下,系统里面就会出现了光盘,把里面的那个压缩包拷贝到别的地方解压,然后命令行进入到该解压的目录下,然后运行命令:\n$ sudo ./vmware-install.pl 然后就开始安装了,第一步会默认是 No 的选项,手动输入 Yes, 后面的一路回车选择默认即可.\n2.4. 更换软件更新源 参考网站: https://opsx.alibaba.com/mirror\ndebian 9.x (stretch)\n编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)\ndeb http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb http://mirrors.aliyun.com/debian-security stretch/updates main deb-src http://mirrors.aliyun.com/debian-security stretch/updates main deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib 2.5. 安装输入法 安装 sogou 输入法,去 sogou 网站去下 Linux 版本的,然后命令行到下载的 deb 文件的目录下面运行:\n$ sudo dpkg -i \u0026lt;你下载的sogou输入法.deb\u0026gt; 然后报错了,缺乏依赖包: zip, fcitx-libs, 等等\u0026hellip;\n安装他们:\n$ sudo apt-get install zip $ sudo apt --fix-broken install 安装完毕重启,输入法就可以用了.\n","permalink":"https://huifeng.me/posts/setup-debian9-init/","tags":["linux"," debian"," tips"],"title":"Setup-Debian9-Init"},{"categories":["Editor"],"contents":"{% centerquote 王小波 %} 人的一切痛苦,本质上都是对自己无能的愤怒。 {% endcenterquote %}\nQuick Fix 1: Remove Strikethrough Extension Sublime Text \u0026gt; Preferences \u0026gt; Package Settings \u0026gt; OmniMarkupPreviewer \u0026gt; Settings - User\npaste the following to remove the strikeout package.\n{ \u0026#34;renderer_options-MarkdownRenderer\u0026#34;: { \u0026#34;extensions\u0026#34;: [\u0026#34;tables\u0026#34;, \u0026#34;fenced_code\u0026#34;, \u0026#34;codehilite\u0026#34;] } } Quick Fix 2: Fix the Strikethrough Extension (if you need it) Find the python-markdown sublime package.\nOn the Mac:\nsubl \u0026#34;/Users/\u0026lt;username\u0026gt;/Library/Application Support/Sublime Text 3/Packages/OmniMarkupPreviewer/OmniMarkupLib/Renderers/libs/mdx_strikeout.py\u0026#34; Replace the makeExtension() method with the following:\ndef makeExtension(*args, **kwargs): return StrikeoutExtension(*args, **kwargs) Save, quit and reload Sublime Text.\n","permalink":"https://huifeng.me/posts/fix-omnimarkdownpreview-cannot-preview/","tags":["sublime"],"title":"Fix OmniMarkdownPreview Cannot Preview"},{"categories":["翻墙"],"contents":"1. 前言 如果要老老实实的,踏踏实实的学习,推荐参考官方网站:https://www.v2ray.com 如果要快速完成,没想要学习了解,推荐:https://v2ray66.com 2. 服务器安装 参考:\n V2Ray 官方文档:https://www.v2ray.com/chapter_00/install.html V2Ray 配置指南(简易直白):https://toutyrater.github.io/prep/install.html 实不相瞒,一键的更好用: https://v2ray666.com/post/13/ 2.1 通过脚本安装 虽然有一键,我的第一次安装不是用一键安装的,是跟着官方文档做的,具体如下:\n2.1.1 方法一:命令行直接运行脚本\nbash \u0026lt;(curl -L -s https://install.direct/go.sh) 2.1.2 方法二:下载脚本,再运行:\nwget https://install.direct/go.sh sudo bash go.sh 2.1.3 方法三(没有翻墙的同志):\n下载 Core 包, 从这里下载: https://www.v2ray.com/chapter_00/install.html\n按道理,你买的VPS肯定是可以访问各类地方的,但是如果不是的话,那么就需要下载 Core 包了,下载下来后,运行里面的 V2ray ,然后会生成一个 config.json 的文件,根据帮助修改其配置即可.\n2.1.4 成功安装的样子:\nInstalling V2Ray v3.46 on x86_64 Downloading V2Ray. % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 608 0 608 0 0 1483 0 --:--:-- --:--:-- --:--:-- 1482 100 10.4M 100 10.4M 0 0 5200k 0 0:00:02 0:00:02 --:--:-- 13.2M Extracting V2Ray package to /tmp/v2ray. Archive: /tmp/v2ray/v2ray.zip creating: /tmp/v2ray/v2ray-v3.46-linux-64/ inflating: /tmp/v2ray/v2ray-v3.46-linux-64/geoip.dat inflating: /tmp/v2ray/v2ray-v3.46-linux-64/geosite.dat inflating: /tmp/v2ray/v2ray-v3.46-linux-64/readme.md creating: /tmp/v2ray/v2ray-v3.46-linux-64/systemd/ inflating: /tmp/v2ray/v2ray-v3.46-linux-64/systemd/v2ray.service creating: /tmp/v2ray/v2ray-v3.46-linux-64/systemv/ inflating: /tmp/v2ray/v2ray-v3.46-linux-64/systemv/v2ray inflating: /tmp/v2ray/v2ray-v3.46-linux-64/v2ctl extracting: /tmp/v2ray/v2ray-v3.46-linux-64/v2ctl.sig inflating: /tmp/v2ray/v2ray-v3.46-linux-64/v2ray extracting: /tmp/v2ray/v2ray-v3.46-linux-64/v2ray.sig inflating: /tmp/v2ray/v2ray-v3.46-linux-64/vpoint_socks_vmess.json inflating: /tmp/v2ray/v2ray-v3.46-linux-64/vpoint_vmess_freedom.json PORT:13863 UUID:8ca787e0-571a-4ff4-bef9-f007057e1e0f Created symlink from /etc/systemd/system/multi-user.target.wants/v2ray.service to /etc/systemd/system/v2ray.service. V2Ray v3.46 is installed. 2.2 管理服务 启动 V2Ray:\n$ sudo systemctl start v2ray 停止 V2Ray:\n$ sudo systemctl stop v2ray 重启 V2Ray:\n$ sudo systemctl restart v2ray Tips: 在首次安装完成之后,V2Ray 不会自动启动,需要手动运行上述启动命令。而在已经运行 V2Ray 的 VPS 上再次执行安装脚本,安装脚本会自动停止 V2Ray 进程,升级 V2Ray 程序,然后自动运行 V2Ray。在升级过程中,配置文件不会被修改。\n 更新 V2Ray 的方法是:再次执行安装脚本!再次执行安装脚本!再次执行安装脚本!\n 对于安装脚本,还有更多用法,在此不多说了,可以执行 bash go.sh -h 看帮助。\n 2.3 服务器配置 这里只是 demo ,端口啥的凭个人爱好。\n修改配置文件:\nsudo vim /etc/v2ray/config.json 如下:\n{ \u0026#34;inbound\u0026#34;: { \u0026#34;port\u0026#34;: 10086, // 服务器监听端口,必须和上面的一样 \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;clients\u0026#34;: [{ \u0026#34;id\u0026#34;: \u0026#34;b831381d-6324-4d53-ad4f-8cda48b30811\u0026#34; }] } }, \u0026#34;outbound\u0026#34;: { \u0026#34;protocol\u0026#34;: \u0026#34;freedom\u0026#34;, \u0026#34;settings\u0026#34;: {} } } 3. 客户端安装配置 下载地址:https://www.v2ray.com/download/\n选择 V2RayN 或者 V2RayW 均可下载,前者的star数量更高些。\n3.1 客户机配置 如果你下载的是 v2ray-windows , config.json 的配置类似下面:\n{ \u0026#34;inbound\u0026#34;: { \u0026#34;port\u0026#34;: 1080, // SOCKS 代理端口,在浏览器中需配置代理并指向这个端口 \u0026#34;listen\u0026#34;: \u0026#34;127.0.0.1\u0026#34;, \u0026#34;protocol\u0026#34;: \u0026#34;socks\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;udp\u0026#34;: true } }, \u0026#34;outbound\u0026#34;: { \u0026#34;protocol\u0026#34;: \u0026#34;vmess\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;vnext\u0026#34;: [{ \u0026#34;address\u0026#34;: \u0026#34;server\u0026#34;, // 服务器地址,请修改为你自己的服务器 ip 或域名 \u0026#34;port\u0026#34;: 10086, // 服务器端口 \u0026#34;users\u0026#34;: [{ \u0026#34;id\u0026#34;: \u0026#34;b831381d-6324-4d53-ad4f-8cda48b30811\u0026#34; }] }] } }, \u0026#34;outboundDetour\u0026#34;: [{ \u0026#34;protocol\u0026#34;: \u0026#34;freedom\u0026#34;, \u0026#34;tag\u0026#34;: \u0026#34;direct\u0026#34;, \u0026#34;settings\u0026#34;: {} }], \u0026#34;routing\u0026#34;: { \u0026#34;strategy\u0026#34;: \u0026#34;rules\u0026#34;, \u0026#34;settings\u0026#34;: { \u0026#34;domainStrategy\u0026#34;: \u0026#34;IPOnDemand\u0026#34;, \u0026#34;rules\u0026#34;: [{ \u0026#34;type\u0026#34;: \u0026#34;field\u0026#34;, \u0026#34;ip\u0026#34;: [ \u0026#34;0.0.0.0/8\u0026#34;, \u0026#34;10.0.0.0/8\u0026#34;, \u0026#34;100.64.0.0/10\u0026#34;, \u0026#34;127.0.0.0/8\u0026#34;, \u0026#34;169.254.0.0/16\u0026#34;, \u0026#34;172.16.0.0/12\u0026#34;, \u0026#34;192.0.0.0/24\u0026#34;, \u0026#34;192.0.2.0/24\u0026#34;, \u0026#34;192.168.0.0/16\u0026#34;, \u0026#34;198.18.0.0/15\u0026#34;, \u0026#34;198.51.100.0/24\u0026#34;, \u0026#34;203.0.113.0/24\u0026#34;, \u0026#34;::1/128\u0026#34;, \u0026#34;fc00::/7\u0026#34;, \u0026#34;fe80::/10\u0026#34; ], \u0026#34;outboundTag\u0026#34;: \u0026#34;direct\u0026#34; }] } } } 客户端启动后,后续也简单,就是浏览器的代理设置了:127.0.0.1, 端口: 1080\n以上。\n","permalink":"https://huifeng.me/posts/get-through-gfw-by-v2ray/","tags":["V2ray"," 翻墙"," shadowsocks"],"title":"通过 V2ray 实现科学上网"},{"categories":["Linux"],"contents":"参考: https://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/\n缓存,owncloud推荐使用的是 APCu 和 Redis,we with PHP 7 needed to build the PHP module as well, because PECL install didn’t work on PHP 7 yet. And as usual – as we didn’t find any good straight forward guide, here is one that works, enjoy!\n原文说的已经很清楚了,细心点应该不会出错,我这里只记录我遇到的坑和How to through it.\ntip1: __ 6. IF THE TEST WAS FINE, PROCEED WITH INSTALLATION__\n这步的命令是在redis的根目录下运行的\n可能你会遇到提示信息: Hint: It's a good idea to run 'make test' ;)\n$ sudo make install $ cd utils \u0026amp;\u0026amp; sudo ./install_server.sh tip2: git 的克隆和下载动作无法在虚拟机内完成,有墙,所以在本地完成后,然后去虚拟机,通过目录隐射来传递文件,把clone下来的文件放到指定的位置.\ntip3: 无法安装 php7.0-dev If you are coming from the old obsolete repository then remove it\n$ sudo apt-get install python-software-properties $ sudo apt-get install ppa-purge $ sudo ppa-purge ppa:ondrej/php-7.0 Add the new repository and update\n$ sudo add-apt-repository ppa:ondrej/php $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get autoremove 再安装一遍:\n$ sudo apt-get install php7.0-dev tip4: 由于我安装的是php7,所以 /etc/php/7.0 才是php所在目录,那么\n$ touch /etc/php/mods-available/redis.ini 执行不会成功,应当是:\n$ sudo touch /etc/php/7.0/mods-available/redis.ini 同样,\n$ echo 'extension=redis.so' \u0026gt; /etc/php/mods-available/redis.ini 也不会成功了,我这里即使目录设置正确的情况下也是不行,所以就 vim 编辑 然后把 extension=redis.so 写到里面了.\ntip5: $ cd .. \u0026amp;\u0026amp; rm -rf phpredis 这句删除的目录是 /etc/phpredis.\n","permalink":"https://huifeng.me/posts/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/","tags":["linux"," php"," php7"," redis"," ubuntu"," owncloud"," install"],"title":"Install Redis Cache on Ubuntu Server with PHP 7 and ownCloud"},{"categories":["Linux"],"contents":"本日志主要记录我配置OwnCloud环境的过程,注意,针对OwnCloud,至于某些模块开启和关闭问题,可以根据具体情况自行调整.另外我操作的系统是Ubuntu14.04LTS. 这里推荐一个很不错的文档位置:https://www.linode.com/docs/\n感悟:\n 遇坑过坑,佛挡杀佛. 看文档很重要,当然,能去官方的GitHub看看更好. 最大坑解决过程: OwnCloud文档 -\u0026gt; MySQL文档 -\u0026gt; MariaDB文档 -\u0026gt; Google -\u0026gt; MySQL/MariaDB文档 -\u0026gt; Github/owncloud/core -\u0026gt; issue -\u0026gt;search for my ailling key-\u0026gt; get it!! 一. 更换源 参照:https://wiki.ubuntu.org.cn/源列表 我曾经用的(网易):http://mirrors.163.com/.help/ubuntu.html\n$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak $ wget http://mirrors.163.com/.help/sources.list.trusty $ sudo cp sources.list.trusty /etc/apt/sources.list # 刷新列表 $ sudo apt-get update # 升级系统,可选! $ sudo apt-get upgrade 我现在用的(香港中文大学):\ndeb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty main restricted universe multiverse deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-security main restricted universe multiverse deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-updates main restricted universe multiverse deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-backports main restricted universe multiverse deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-proposed main restricted universe multiverse deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty main restricted universe multiverse deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-security main restricted universe multiverse deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-updates main restricted universe multiverse deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-backports main restricted universe multiverse deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty-proposed main restricted universe 二. 初始化操作 其他操作系统可以参考:https://www.linode.com/docs/getting-started\n1. 设置Hostname 你可以之间编辑:\n$ sudo nano /etc/hostname When you’re finished editing, press Control-X, then Y to save the changes and Enter to confirm.\n或者:\n$ echo \u0026quot;hostname\u0026quot; \u0026gt; /etc/hostname $ hostname -F /etc/hostname 2. 设置时区 这个还是很有必要的,否则你看不懂服务器日志的实际时间.\n$ sudo dpkg-reconfigure tzdata 三. Apache安装和基本配置 参考: http://tecadmin.net/install-php-7-0-apache-2-4-mysql-5-6-on-ubuntu/ https://segmentfault.com/a/1190000004687322 http://www.rolandolucio.com/howto/2016/02/05/php7-mysql5.7-apache2-ubuntu-lamp.html https://launchpad.net/~ondrej/\n安装 Apache 2.4 (1)通过apt安装Apache $ sudo apt-get install apache2 Error: AH00558: apache2: Could not reliably determine the server\u0026rsquo;s fully qualified domain name, using 127.0.1.1. Set the \u0026lsquo;ServerName\u0026rsquo; directive globally to suppress this message\n Solution: If you insert a\nServerName localhost in either httpd.conf or apache2.conf in /etc/apache2 and restart apache the notice will disappear.\n(2)关闭 KeepAlive 编辑apache主配置文件/etc/apache2/apache2.conf ,修改 KeepAlive 设置 KeepAlive Off\n(3)启用 prefork 模块 Apache默认的 multi-processing 模块( MPM ) 是一个 event 模块, 但是 php 默认是使用 prefork 模块,禁用 event 模块,启用 prefork 模块:\n$ sudo a2dismod mpm_event $ sudo a2enmod mpm_prefork (4)重启 apache2 服务 $ sudo service apache2 restart 四. Install PHP 7 考虑到蛋疼的中华大城域网的原因,很可能安装会遇到某些模块找不到的情况,就需要选择的编译源码安装(方法一),如果一切环境良好,可以选择便捷的方法二.\n编译源码安装(方法一): 请参考我的的博客: http://huifeng.me/2016/05/18/LEMP-step-to-step/#3-__u5B89_u88C5PHP_7-0-6\n快速源安装(方法二): First install python-software-properties package on your system which provides add-apt-repository command then use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install it.\nsudo apt-cache search php7.0 搜索看是否有 php7.0,如果没有就添加源,然后更新,然后安装:\n$ sudo apt-get install python-software-properties $ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:ondrej/php $ sudo apt-get update $ sudo apt-get install -y php7.0 或者:\n$ sudo nano /etc/apt/sources.list 添加:\ndeb http://ppa.launchpad.net/ondrej/php/ubuntu trusty main deb-src http://ppa.launchpad.net/ondrej/php/ubuntu trusty main 然后:\n$ sudo apt-get update $ sudo apt-get install -y php7.0 1. 查看安装情况: 查看版本:\n$ php -v 查看安装的模块:\n$ php -m | grep -i \u0026lt;module_name\u0026gt; 查看可以安装的模块: $ sudo apt-cache search php7-* 2. 安装模块 $ sudo apt-get install libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json php7.0-zip php7.0-xml php7.0-gd php7.0-mcrypt php7.0-mbstring php7.0-imagick Tips: Ubuntu Error-\u0026gt; locale: Cannot set LC_CTYPE to default locale: No such file or directory Wiki:http://wiki.ubuntu.org.cn/%E4%BF%AE%E6%94%B9locale Solution:\n locale 显示当前语言环境 sudo nano /etc/default/locale 来修改语言配置 安装需要的语言环境,我这里设置的是 zh_CN.UTF-8,所以:sudo locale-gen zh_CN.UTF-8 Over! OwnCloud 必须需要的模块 PHP module ctype (if\u0026gt;4.2.0 enabled by default) PHP module dom (enabled by default) PHP module GD PHP module iconv (enabled by default) PHP module JSON PHP module libxml (Linux package libxml2 must be \u0026gt;=2.7.0) PHP module mb multibyte PHP module posix (enabled by default) PHP module SimpleXML PHP module XMLWriter (if\u0026gt;5.1.2 enabled by default) PHP module zip PHP module zlib 之前的命令已经全部满足了这些模块的安装需求.\nOwnCloud 推荐安装的模块 PHP module curl (highly recommended, some functionality, e.g. HTTP user authentication, depends on this) PHP module fileinfo (highly recommended, enhances file analysis performance) sudo apt-get install php7.0-common PHP module bz2 (recommended, required for extraction of apps) sudo apt-get install php7.0-bz2 PHP module intl (increases language translation performance and fixes sorting of non-ASCII characters) sudo apt-get install php7.0-intl PHP module mcrypt (increases file encryption performance) sudo apt-get install php7.0-mcrypt PHP module openssl (required for accessing HTTPS resources) sudo apt-get install openssl ,更多操作待续\u0026hellip; OwnCloud 提到的额外的一些模块 个别app或者会用到以防不时之需,就安装上吧:\nRequired for specific apps:\n PHP module ldap (for LDAP integration) sudo apt-get install php7.0-ldap PHP module smbclient (SMB/CIFS integration, see SMB/CIFS) sudo apt-get install php7.0-smbclient PHP module ftp (for FTP storage / external user authentication) be installed by php7.0-common PHP module imap (for external user authentication) sudo apt-get install php7.0-imap Recommended for specific apps (optional):\n PHP module exif (for image rotation in pictures app) sudo apt-get install php7.0-exif PHP module gmp (for SFTP storage) sudo apt-get install php7.0-gmp 3. phpinfo 写测试页测试下 /var/www/html/phpinfo.php :\n\u0026lt;?php phpinfo(); 浏览: http://YourServerIp/phpinfo.php ,应该没问题,如果出现php文件没有被解析,重新运行安装模块命令吧: sudo apt-get install libapache2-mod-php7.0\n4. PHP日志设定 Create the /var/log/php/ directory for the PHP error log:\n$ sudo mkdir -p /var/log/php Change the owner of the /var/log/php/ directory to www-data, which the PHP user runs as:\n$ sudo chown www-data /var/log/php 五. 安装MariaDB10 参考: https://mariadb.org/learn/ https://mariadb.com/kb/en/mariadb/getting-installing-and-upgrading-mariadb/\n从\n https://launchpad.net 搜索 MariaDB 10.1.14 找到了 https://lists.launchpad.net/maria-discuss/msg03586.html 然后找到了 APT and YUM Repository Configuration Generator: https://downloads.mariadb.org/mariadb/repositories/ So (My base on Ubuntu 14.04LTS): https://downloads.mariadb.org/mariadb/repositories/#mirror=nethub\u0026amp;distro=Ubuntu\u0026amp;distro_release=trusty--ubuntu_trusty\u0026amp;version=10.1 Than(香港的这个靠谱些):\n$ sudo apt-get install software-properties-common $ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db $ sudo add-apt-repository 'deb [arch=amd64,i386] http://mariadb.nethub.com.hk/repo/10.1/ubuntu trusty main' 然后官方建议添加个新的 sourse.list 文件到源目录下,方便以后更新更快捷,我的文件如下:\n /etc/apt/sources.list.d/MariaDB.list ↓\n# MariaDB 10.1 repository list - created 2016-05-23 02:34 UTC # http://mariadb.org/mariadb/repositories/ deb [arch=amd64,i386] http://mariadb.nethub.com.hk/repo/10.1/ubuntu trusty main deb-src http://mariadb.nethub.com.hk/repo/10.1/ubuntu trusty main 然后,Install MariaDB 10.1.14 with blow once your add the key and the repository successful:\n$ sudo apt-get update $ sudo apt-get install mariadb-server 这里解决下 update 时问题:\n W: GPG 错误:http://ppa.launchpad.net trusty InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY 4F4EA0AAE5267A6C 从 hkp 服务器 wwwkeys.pgp.net下载并导入缺失的公钥(采用root权限)\n $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C 六. 配置Apache 文档进行到这一步了: https://doc.owncloud.org/server/9.0/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-14-04-lts-server\n接下来将进行 Apache 和 PHP 的配置, OwnCloud 命令行的安装等等,按照 OwnCloud 文档一步一步来吧.\n整个过程虽然比较慢,但是我想这样下来收货绝对不少,至少提高了过坑能力.\n1. Get Owncloud Now download the archive of the latest ownCloud version:\nGo to the ownCloud Download Page.\nMy command for download,unpacking and copy unpacks to its final destination:\n$ wget https://download.owncloud.org/community/owncloud-9.0.2.tar.bz2 $ tar jxvf owncloud-9.0.2.tar.bz2 $ sudo cp -r owncloud /var/www/ 2. Apache Web Server Configuration (1) Create a /etc/apache2/sites-available/owncloud.conf file with these lines in it,replacing the Directory and other filepaths with your own filepaths:\nAlias /owncloud \u0026quot;/var/www/owncloud/\u0026quot; \u0026lt;Directory /var/www/owncloud/\u0026gt; Options +FollowSymlinks AllowOverride All \u0026lt;IfModule mod_dav.c\u0026gt; Dav off \u0026lt;/IfModule\u0026gt; SetEnv HOME /var/www/owncloud SetEnv HTTP_HOME /var/www/owncloud \u0026lt;/Directory\u0026gt; (2) Then create a symlink to /etc/apache2/sites-enabled to enable your new website, replacing owncloud with your config file name:\n$ sudo ln -s /etc/apache2/sites-available/owncloud.conf /etc/apache2/sites-enabled/owncloud.conf Or:\n$ sudo a2ensite owncloud.conf Than:\n$ sudo service apache2 restart Additional Apache Configurations For ownCloud to work correctly, we need the module mod_rewrite. Enable it by running: sudo a2enmod rewrite Additional recommended modules are mod_headers, mod_env, mod_dir and mod_mime: $ sudo a2enmod headers $ sudo a2enmod env $ sudo a2enmod dir $ sudo a2enmod mime 你必须为 Owncloud 禁止任何服务器配置认证,add the following line in the \u0026lt;Directory section: Satisfy Any Enable Vhost (1) Disable the default Apache virtual host:\n$ sudo a2dissite *default (2) Create log folders\n$ mkdir -p /var/www/owncloud/log/ (3) change config file /etc/apache2/sites-available/owncloud.conf to blow:\n\u0026lt;VirtualHost *:80\u0026gt; # Admin email, Server Name (domain name), and any aliases ServerAdmin wedojava@gmail.com ServerName yun.app # ServerAlias owncloud.app # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /var/www/owncloud # Log file locations LogLevel warn ErrorLog /var/www/owncloud/log/error.log CustomLog /var/www/owncloud/log/access.log combined \u0026lt;/VirtualHost\u0026gt; 至此,我已经可以通过 http://yun.app 访问到owncloud站点了,可以安装了.\n 七. 配置MySQL/MariaDB OwnCloud 通过 TRANSACTION_READ_COMMITTED 来交换隔离,以避免在高调用率的情况下丢失数据(比如,你有很多客户,客户用客户端同时同步数据,频繁操作).解决这个问题,需要禁用或者正确的配置 MySQL/MariaDB 的 binary logging 配置.\n默认安装好的数据库在通过浏览器访问并安装的时候会遇到错误信息:\n An unhandled exception has been thrown: exception ‘PDOException’ with message \u0026lsquo;SQLSTATE[HY000]: General error: 1665 Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.\u0026rsquo;\n There are two solutions. One is to disable binary logging. Binary logging records all changes to your database, and how long each change took. The purpose of binary logging is to enable replication and to support backup operations.\nThe other is to change the BINLOG_FORMAT = STATEMENT in your database configuration file, or possibly in your database startup script, to BINLOG_FORMAT = MIXED. See Overview of the Binary Log and The Binary Log for detailed information.\n下面开始修改 BINGLOG: 我安装的是 10.1.14-MariaDB-1~trusty, 主配置文件在:/etc/mysql/my.cnf\n 版本号怎么查? mysql -u root -p 登录,然后输入 show variables like \u0026quot;version\u0026quot;; 即可显示版本号了.\n 1. 解决 BINLOG_FORMAT 问题. 真心查阅里很多地方,从MySQL和OwnCloud官方文档到GitHub: http://dev.mysql.com/doc/refman/5.7/en/binary-log-setting.html 这里MySQL确实说了怎么设置,但是重启服务器又没了!!!Owncloud也是指向里类似的解决问题的办法. 可能很多解决问题的都是大神吧,他们说的并不是很清楚,只是说添加一行binlog_format = MIXED到my.cnf,但是添加错误真的不会起作用的!!最终找到一个好人,他说中了我的痛点,怎么处理? https://github.com/owncloud/core/issues/16008 看@saamo的回答总算明白是哪里的问题了.\nIt was already said somewhere above but make sure to place the option under the [mysqld] header in /etc/mysql/my.cnf unless it won\u0026rsquo;t work.\n[mysqld] binlog_format = MIXED 然后重启服务器,问题解决!\n然后我在安装的时候遇到的上面的出错信息,下面分布解决,你可以跳过第一步,之间进入第二步.\n2. phpMyAdmin 先安装个phpMyAdmin吧,可以参考: https://launchpad.net/~nijel/+archive/ubuntu/phpmyadmin https://docs.phpmyadmin.net/en/latest/setup.html 我是用的 Composer 装的,推荐此法!! 当然直接下载也是可以用的,需要注意的是截止目前,4.6对中文的支持不是很好,所以会报错: Ignoring unsupported language code.\n 2016/5/22更新:github上面大神已找到问题原因,官方回复会在4.6.2版本予以修复,大家拭目以待! https://github.com/phpmyadmin/phpmyadmin/issues/12256 暂时可以这么解决:\n在登录页修改语言为英文,或者修改配置文件 libraries/config.default.php 的这一行:\n$cfg['Lang'] = 'en'; 3. Configuring a MySQL or MariaDB Database If you decide to use a MySQL or MariaDB database, ensure the following:\n That you have installed and enabled the pdo_mysql extension in PHP That the mysql.default_socket points to the correct socket (if the database runs on the same server as ownCloud). Now you need to create a database user and the database itself by using the MySQL command line interface. The database tables will be created by ownCloud when you login for the first time.\n(1) 生成密码 这里新开一个终端,用命令随机生成一个用户密码:openssl rand -base64 12,我测试生成的是6Vh44YmKoOcR2NWo 经常我们会忘记了数据库的用户名,所以,我推荐一个数据库就用和数据库名一样的用户名,密码随机生成.\n(2) 创建用户和数据库 To start the MySQL command line mode use:\n$ mysql -uroot -p Then a mysql\u0026gt; or MariaDB [root]\u0026gt; prompt will appear. Now enter the following lines and confirm them with the enter key:\nMariaDB [root]\u0026gt; CREATE USER 'owncloud'@'localhost' IDENTIFIED BY '刚才随机生成的密码'; MariaDB [root]\u0026gt; CREATE DATABASE IF NOT EXISTS owncloud; MariaDB [root]\u0026gt; GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED BY '刚才随机生成的密码'; You can quit the prompt by entering:\nquit 注意,到这一步,已经可以完全安装好OwnCloud了,虽然下面是可选项,但是最好还是设置号ssl和pretty url. ↓\n Pretty URLs Pretty URLs are created automatically when .htaccess is writable by the HTTP user, mod_env and mod_rewrite are installed, and 'overwrite.cli.url' in your config.php is set to any non-null value.\nEnabling SSL 官方强烈建议启用ssl.\nApache installed under Ubuntu comes already set-up with a simple self-signed certificate. All you have to do is to enable the ssl module and the default site. Open a terminal and run:\n$ sudo a2enmod ssl $ sudo a2ensite default-ssl $ sudo service apache2 reload ","permalink":"https://huifeng.me/posts/lamp-stepbystep/","tags":["linux"," php"," mysql"," mariadb"," apache2"," apache"],"title":"LAMP环境搭建(Ubuntu14.04 For OwnCloud)"},{"categories":["Linux"],"contents":" 更多文档请浏览官方文档和Wiki,这个很重要,其实文档里已经说的很清楚了,会遇到的Bug往往在回复里也有。\n ## 1. 更换国内更新源\n Ubuntu 14.04 更新源: https://m.oschina.net/blog/224661\n 2. 安装Nginx 想要安装最新版本,或添加模块,请参考这里:http://nginx.org/en/linux_packages.html\n 下载 nginx_signing.key: wget http://nginx.org/keys/nginx_signing.key\n 添加下面代码到 /etc/apt/sources.list 的末尾:\ndeb http://nginx.org/packages/ubuntu/ trusty nginx deb-src http://nginx.org/packages/ubuntu/ trusty nginx\n 最后:\nsudo apt-get update sudo apt-get install nginx 安装成功后,应该可以在命令行这样:\n sudo nginx -s stop — fast shutdown sudo nginx -s quit — graceful shutdown sudo nginx -s reload — reloading the configuration file sudo nginx -s reopen — reopening the log files 3. 安装PHP 7.0.6 可以参考:http://php.net/manual/zh/install.unix.nginx.php\n 先下载需要的版本的 php 包,然后解压等等:\ntar zxf php-7.0.6.tar.gz cd php-7.0.6 ./configure --enable-fpm --with-mysql make make test sudo make install 在运行 ./configure 的过程中我遇到了若干错误信息:\n __Error:__configure: error: xml2-config not found. Please check your libxml2 installation. 我开始安装了下 libxml2 ,发现问题还是没解决,在 stackoverflow 找到了答案:链接\n __Solution:__安装 libxml2 和 libxml2-dev 即可:sudo apt-get install libxml2 libxml2-dev __Error:__configure: WARNING: unrecognized options: --with-mysql\n Solution1: --with-pdo-mysql instead of --with-mysql Solution2: --with-mysqli instead of --with-mysql make install log:\nWrote PEAR system config file at: /usr/local/etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_path /home/vagrant/php-7.0.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin ln -s -f phar.phar /usr/local/bin/phar Installing PDO headers: /usr/local/include/php/ext/pdo/ 运行:\nsudo /home/vagrant/php-7.0.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin sudo ln -s -f phar.phar /usr/local/bin/phar 创建配置文件,并将其复制到正确的位置:\ncp php.ini-development /usr/local/php/php.ini cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf cp sapi/fpm/php-fpm /usr/local/bin 需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击。\n将 /usr/local/php/php.ini 文件中的配置项 cgi.fix_pathinfo 设置为 0 。\n在启动服务之前,需要修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。\nvim /usr/local/etc/php-fpm.conf 修改:\n; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. user = www-data group = www-data __需要注意的是:__我在这个文件里没找到 user的设置,莫非官方文档还没有针对PHP7?,我在 /usr/local/etc/php-fpm.d/www.conf.default 里找到了 user 的选项,默认是 nobody,你可以参照这里:http://php.net/manual/zh/install.fpm.install.php : 编译 PHP 时需要 --enable-fpm 配置选项来激活 FPM 支持。\n 以下为 FPM 编译的具体配置参数(全部为可选参数):\n --with-fpm-user - 设置 FPM 运行的用户身份(默认 - nobody) --with-fpm-group - 设置 FPM 运行时的用户组(默认 - nobody) --with-fpm-systemd - 启用 systemd 集成 (默认 - no) --with-fpm-acl - 使用POSIX 访问控制列表 (默认 - no) 5.6.5版本起有效 PHP核心配置列表\n 其实可以把之前的配置命令改为\n ./configure --enable-fpm --with-mysqli --with-fpm-user=www-data --with-fpm-group=www-data 来运行就不用在修改配置文件那么麻烦了。\n 然后启动 php-fpm 服务:\n/usr/local/bin/php-fpm 这里会遇到坑:\n$ sudo /usr/local/bin/php-fpm [12-May-2016 04:39:05] ERROR: Unable to globalize '/usr/local/NONE/etc/php-fpm.d/*.conf' (ret=2) from /usr/local/etc/php-fpm.conf at line 125. [12-May-2016 04:39:05] ERROR: failed to load configuration file '/usr/local/etc/php-fpm.conf' [12-May-2016 04:39:05] ERROR: FPM initialization failed 修改 /usr/local/etc/php-fpm.conf 最后一行:\n/NONE/etc/php-fpm.d/*.conf 为 etc/php-fpm.d/*.conf\n然后拷贝默认文件为 *.conf 文件:\ncp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf 并修改里面的 user 和 group:\nuser = www-data group = www-data 现在应该好了,启动 php-fpm 服务:\n/usr/local/bin/php-fpm 参考文献: http://php.net/manual/zh/install.unix.nginx.php http://nginx.org/en/docs/beginners_guide.html http://nginx.org/en/linux_packages.html https://github.com/owncloud/documentation/wiki/NGINX-Configuration\n推荐工具 ee(如果你不能翻墙就算了,去用oneinstack吧,也是很好的工具):https://github.com/EasyEngine/easyengine\n4. 配置 Nginx 使其支持 PHP 应用: 我的本地测试域名用 yum.app ,代码放在虚拟机的 /var/www/owncloud 。成功搞定应该是可以通过浏览器访问 http://yum.app 直接访问到我们的OwnCloud 的。\nsudo vim /etc/nginx/conf.d/default.conf 修改默认的 location 块,使其支持 .php 文件:\nlocation / { root html; index index.php index.html index.htm; } 下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:\nlocation ~* \\.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; } 写下测试文件:\nsudo touch /usr/share/nginx/html/index.php sudo vim /usr/share/nginx/html/index.php index.php:\n\u0026lt;?php phpinfo(); 然后访问 http://yum.app ,报错:File Not Found. 这里可以初步判断也许是php解析有问题,在相同位置建一个html文件,访问,发现正常。确诊是php解析问题。\nFile Not Found 解决和分析 打开刚才的配置文件:\nsudo vim /etc/nginx/conf.d/default.conf 将原有配置修改为:\nlocation ~ \\.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name; include fastcgi_params; } 没错,是这一行:\nfastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name; 我们把 $document_root 修改为 /usr/share/nginx/html/,然后重启nginx,会发现问题解决了。\n但是这样并不算很科学,我认为放弃对 $document_root 的使用不科学,所以,这样,其实,如果我们把 root html; 写到解析 / 或 php 里并不科学,更好的做法是把这些基本不变的参数写到 /etc/nginx/conf.d/default.conf 顶上去:\nserver { listen 80; server_name localhost; root /var/www; index index.html index.htm index.php; ...... 然后,修改 php 的解析为:\nlocation ~ \\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } 重启nginx,一些都好了,至此,File Not Found 问题分析解决完毕。\n5. Nginx的\u0026quot;虚拟目录\u0026rdquo; 参考:https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/ 按照官方的说法,Nginx是没有虚拟目录的概念的,它有的是 Server Blocks。\n 其实我没必要做这一部分,毕竟我没打算让服务器上运行多个网站,它只运行 owncloud, 但是既然都走到这步了,那就实现了吧。\n 打开 /etc/nginx/nginx.conf 配置文件可以看到这样一段:\nhttp { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] \u0026quot;$request\u0026quot; ' '$status $body_bytes_sent \u0026quot;$http_referer\u0026quot; ' '\u0026quot;$http_user_agent\u0026quot; \u0026quot;$http_x_forwarded_for\u0026quot;'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } 而这一行 include /etc/nginx/conf.d/*.conf; 就是插入了所有 conf.d 目录下的配置文件,这个做法好——解耦很重要。\n根据官方给的样例:\nserver { # Replace this port with the right one for your requirements listen 80 default_server; #could also be 1.2.3.4:80 # Multiple hostnames separated by spaces. Replace these as well. server_name star.yourdomain.com *.yourdomain.com; # Alternately: _ root /PATH/TO/WEBROOT; error_page 404 errors/404.html; access_log logs/star.yourdomain.com.access.log; index index.php index.html index.htm; # static file 404's aren't logged and expires header is set to maximum age location ~* \\.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location ~ \\.php$ { include fastcgi_params; fastcgi_intercept_errors on; # By all means use a different server for the fcgi processes if you need to fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE; } location ~ /\\.ht { deny all; } } 我们把这个样例稍作修改,放到 conf.d 目录下即可,例如下面的 /etc/nginx/conf.d/demo.conf:\nserver { # Replace this port with the right one for your requirements listen 80 default_server; #could also be 1.2.3.4:80 # Multiple hostnames separated by spaces. Replace these as well. server_name star.demo.com *.demo.com; # Alternately: _ root /var/www/demo; error_page 404 errors/404.html; # access_log logs/star.yourdomain.com.access.log; index index.php index.html index.htm; # static file 404's aren't logged and expires header is set to maximum age location ~* \\.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location ~ \\.php$ { include fastcgi_params; fastcgi_intercept_errors on; # By all means use a different server for the fcgi processes if you need to fastcgi_pass 127.0.0.1:9000; } location ~ /\\.ht { deny all; } } 然后重启Nginx即可. Over!\n","permalink":"https://huifeng.me/posts/lemp-step-to-step/","tags":["lnmp"," lemp"," nginx"," php"," php-fpm"],"title":"LEMP/LNMP 环境搭建(Nginx1.10 + PHP7)"},{"categories":["Linux"],"contents":"$ pushd $openssh_source_dir \u0026gt; /dev/null 命令 说明 command \u0026gt; file 将输出重定向到 file。 command \u0026lt; file 将输入重定向到 file。 command \u0026raquo; file 将输出以追加的方式重定向到 file。 n \u0026gt; file 将文件描述符为 n 的文件重定向到 file。 n \u0026raquo; file 将文件描述符为 n 的文件以追加的方式重定向到 file。 n \u0026gt;\u0026amp; m 将输出文件 m 和 n 合并。 n \u0026lt;\u0026amp; m 将输入文件 m 和 n 合并。 \u0026laquo; tag 将开始标记 tag 和结束标记 tag 之间的内容作为输入。 \u0026gt; /dev/null 如果希望执行某个命令,但又不希望在屏幕上显示输出结果,那么可以将输出重定向到 /dev/null, /dev/null 是一个特殊的文件,写入到它的内容都会被丢弃;如果尝试从该文件读取内容,那么什么也读不到。但是 /dev/null 文件非常有用,将命令的输出重定向到它,会起到\u0026quot;禁止输出\u0026quot;的效果。\n如果希望屏蔽 stdout 和 stderr,可以这样写:\n$ command \u0026gt; /dev/null 2\u0026gt;\u0026amp;1 pushd = PUSH Directory:\nkali@kali:~$ pushd ~/test ~/test ~ kali@kali:~/test$ pushd ~/Documents/ ~/Documents ~/test ~ kali@kali:~/Documents$ pushd ~/test ~/Documents ~ kali@kali:~/test$ pushd ~/Documents ~/test ~ kali@kali:~/Documents$ pushd ~/test ~/Documents ~ kali@kali:~/test$ pushd ~/Documents ~/test ~ kali@kali:~/Documents$ pushd ~/test ~/Documents ~ kali@kali:~/test$ pushd ~/Documents ~/test ~ kali@kali:~/Documents$ popd ~/test ~ kali@kali:~/test$ popd ~ kali@kali:~$ pushd bash: pushd: no other directory kali@kali:~$ popd bash: popd: directory stack empty kali@kali:~$ patch -p1 \u0026lt; ../$your_patch https://www.runoob.com/linux/linux-comm-patch.html\nLinux patch命令用于修补文件。\npatch指令让用户利用设置修补文件的方式,修改,更新原始文件。倘若一次仅修改一个文件,可直接在指令列中下达指令依序执行。如果配合修补文件的方式则能一次修补大批文件,这也是Linux系统核心的升级方法之一。\n[-p \u0026lt;剥离层级\u0026gt;] 设置欲剥离几层路径名称。\npushd $openssh_source_dir \u0026gt; /dev/null # 进入到目录 $openssh_source_dir patch -p1 \u0026lt; ../$mitm_patch # 用 $mitm_patch 给 $openssh_source_dir 打补丁 Linux 里判断是否存在用户 ssh-mitm 如果跟了 --force 则删除用户:\n# Check if the ssh-mitm user exists. id ssh-mitm \u0026gt; /dev/null 2\u0026gt; /dev/null if [[ $? == 0 ]]; then # The user exists. If this script was run with the \u0026#34;--force\u0026#34; argument, # then we will delete the user. if [[ $1 == \u0026#39;--force\u0026#39; ]]; then userdel -f -r ssh-mitm 2\u0026gt; /dev/null # There could be saved sessions from an old version of SSH MITM that # we shouldn\u0026#39;t destroy automatically. else echo \u0026#34;It appears that the ssh-mitm user already exists. Make backups of any saved sessions in /home/ssh-mitm/, then re-run this script with the \\\u0026#34;--force\\\u0026#34; argument (this will cause the user account to be deleted and re-created).\u0026#34; exit -1 fi fi 下载 OpenSSH 并验证是否正品:\n# Downloads OpenSSH and verifies its sources. function get_openssh { local openssh_sig=\u0026#39;openssh-7.5p1.tar.gz.asc\u0026#39; local release_key_fingerprint_expected=\u0026#39;59C2 118E D206 D927 E667 EBE3 D3E5 F56B 6D92 0D30\u0026#39; local openssh_checksum_expected=\u0026#39;9846e3c5fab9f0547400b4d2c017992f914222b3fd1f8eee6c7dc6bc5e59f9f0\u0026#39; echo -e \u0026#34;\\nGetting OpenSSH release key...\\n\u0026#34; wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/RELEASE_KEY.asc echo -e \u0026#34;\\nGetting OpenSSH sources...\\n\u0026#34; wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/$openssh_sources echo -e \u0026#34;\\nGetting OpenSSH signature...\\n\u0026#34; wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/$openssh_sig echo -e \u0026#34;\\nImporting OpenSSH release key...\\n\u0026#34; gpg --import RELEASE_KEY.asc local release_key_fingerprint_actual=`gpg --fingerprint 6D920D30` if [[ $release_key_fingerprint_actual != *\u0026#34;$release_key_fingerprint_expected\u0026#34;* ]]; then echo -e \u0026#34;\\nError: OpenSSH release key fingerprint does not match expected value!\\n\\tExpected: $release_key_fingerprint_expected\\n\\tActual: $release_key_fingerprint_actual\\n\\nTerminating.\u0026#34; exit -1 fi echo -e \u0026#34;\\n\\nOpenSSH release key matches expected value.\\n\u0026#34; local gpg_verify=`gpg --verify $openssh_sig $openssh_sources 2\u0026gt;\u0026amp;1` if [[ $gpg_verify != *\u0026#34;Good signature from \\\u0026#34;Damien Miller \u0026lt;djm@mindrot.org\u0026gt;\\\u0026#34;\u0026#34;* ]]; then echo -e \u0026#34;\\n\\nError: OpenSSH signature invalid!\\n$gpg_verify\\n\\nTerminating.\u0026#34; rm -f $openssh_sources exit -1 fi # Check GPG\u0026#39;s return value. 0 denotes a valid signature, and 1 is returned # on invalid signatures. if [[ $? != 0 ]]; then echo -e \u0026#34;\\n\\nError: OpenSSH signature invalid! Verification returned code: $?\\n\\nTerminating.\u0026#34; rm -f $openssh_sources exit -1 fi echo -e \u0026#34;Signature on OpenSSH sources verified.\\n\u0026#34; local openssh_checksum_actual=`sha256sum $openssh_sources` if [[ $openssh_checksum_actual != \u0026#34;$openssh_checksum_expected\u0026#34;* ]]; then echo -e \u0026#34;Error: OpenSSH checksum is invalid! Terminating.\u0026#34; exit -1 fi return 1 } ","permalink":"https://huifeng.me/posts/shell-study/","tags":["shell"," linux"],"title":"Shell Study"},{"categories":["Linux"],"contents":"sudo Command is unable in centos system?\n我遇到了这样的问题,在 CentOS 7 系统下,执行 sudo 提示 Sorry, try again. ,密码是正确的密码,当前用户和 root 的密码都试过,都是这样 visudo 也都配置正确,怎么办?\n我参考了这里:https://www.centos.org/forums/viewtopic.php?t=40708\n这里我设置成 sudo 适用空密码:\n 创建用户 user: useradd user 立即过期 user: chage -d 0 user 设置 user: usermod -p \u0026quot;\u0026quot; user 如果你确实想设置 user 的密码,可以这样: sudo passwd user , Then type your password what you want. ","permalink":"https://huifeng.me/posts/sudo-unable-in-centos/","tags":["sudo"," linux"," unable"," centos"],"title":"sudo命令输入密码还是不能用?"},{"categories":["Linux"],"contents":"本人遇到一个很尴尬的问题,忘记了 vps 的 root 的密码。怎么办?查阅官方提示,找到如下方法:\nhttps://www.vultr.com/docs/boot-into-single-user-mode-reset-root-password\nCentOS 7 的操作过程 重启服务器,(Ctrl + Alt + Del) 重启后有个选项,按任意键停止,否则自动选择进入,一直按方向键吧,我是这么做的 boot 停下来了, 此时根据提示的按键进入编辑,我的系统是 CentOS-7,所以是按 e 进入编辑 找到以 linux /boot/ 开始的行,在其末尾添加: init=\u0026quot;/bin/bash\u0026quot;。(On CentOS 7, the line may start with linux16). 按 Ctrl + X 或 F10 输入:mount -rw -o remount /,然后输入 passwd 即可开始重置 root 的密码了。 其实,其他系统也是类似的,具体可以参考上面给的网址。\n","permalink":"https://huifeng.me/posts/how-to-reset-root-password/","tags":["linux"," password"," passwd"," 重置"," root"],"title":"Linux系统下,如何重置root密码?"},{"categories":["Cloud"],"contents":"本来是用的 Homestead box 虚拟机环境,但是遇到些问题,看到官方例子是用 Apache,并且官方推荐是用Apache 的 mod_php 来解析PHP。这里记录下整个过程。So many chores beat me?No chores can beat me.\n 由于是打算用作运维的环境搭建,所以一切跟着官方文档做吧。 起始文档: https://doc.owncloud.org/server/9.0/admin_manual/installation/source_installation.html\n 关于WebServer的选择,官方如是说:\nWeb server¶\nTaking Apache and Nginx as the contenders, Apache with mod_php is currently the best option, as Nginx does not support all features necessary for enterprise deployments. Mod_php is recommended instead of PHP_FPM, because in scale-out deployments separate PHP pools are simply not necessary.\n我是把 Nginx + php7 的环境都搭建差不多的时候看到的,我简直。。。\n当然Nginx + php7的配置我也放博客了:http://huifeng.me/2016/05/18/LEMP-step-to-step/ 差数据库没安装,当然,那个很简单了,这里无需赘述。\n一. 操作系统 添加 puphpet/ubuntu box:\nvagrant box add puphpet/ubuntu1404-x64 创建项目文件夹并初始化:\nmkdir owncloud \u0026amp;\u0026amp; cd owncloud \u0026amp;\u0026amp; vagrant init puphpet/ubuntu1404-x64 编辑配置文件为(原 Vagrantfile 文件里,#表示注释):\n# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure(2) do |config| config.vm.box = \u0026quot;puphpet/ubuntu1404-x64\u0026quot; config.vm.network \u0026quot;private_network\u0026quot;, ip: \u0026quot;192.168.33.10\u0026quot; config.vm.provider \u0026quot;virtualbox\u0026quot; do |vb| vb.memory = \u0026quot;1024\u0026quot; vb.name = \u0026quot;puphpet-ubuntu-14.04-owncloud\u0026quot; end end 启动虚拟机:vagrant up\n进入虚拟机:vagrant ssh\n 二. 安装和配置(基于LAMP) 这里用 LAMP 是因为官方推荐,我个人更喜欢 Nginx+php-fpm ,如果强迫自己用 LEMP/LNMP 可以参考:http://huifeng.me/2016/05/18/LEMP-step-to-step/\n1. 使用OwnCloud提供脚本来安装 这个好用,实现速度快,但求能用,不求更精准配置的可以用这个步骤:\n 根据这篇文档来安装。 访问 http://YourLampHost/owncloud 来完成安装。 2. 自己手动搭建环境,通过源码包安装 (1) 搭建 LAMP 环境 LAMP环境的搭建请参考这里:http://huifeng.me/2016/05/19/LAMP-StepByStep/\n (2) OwnCloud 下载安装 Now download the archive of the latest ownCloud version: https://owncloud.org/install Go to **Download ownCloud Server \u0026gt; Download \u0026gt; Archive file for server owners ** and download either the tar.bz2 or .zip archive.\n下载源码:\nwget https://download.owncloud.org/community/owncloud-9.0.1.tar.bz2 下载 MD5 :\nwget https://download.owncloud.org/community/owncloud-9.0.1.tar.bz2.md5 校验:\nmd5sum -c owncloud-9.0.1.tar.bz2.md5 \u0026lt; owncloud-9.0.1.tar.bz2 没问题则返回: owncloud-9.0.1.tar.bz2: OK.\n解压:\ntar xjf owncloud-9.0.1.tar.bz2 拷贝 owncloud 到 apache 的网站目录下\ncp -r owncloud /path/to/webserver/document-root 安装有两条路:\n Installation Wizard Installing ownCloud From the Command Line 命令行安装也是蛮方便,在 /var/www/owncloud 目录下运行下面的代码即可(注意修改为你的用户名密码数据库等个性信息).\nsudo -u www-data php occ maintenance:install --database \u0026quot;mysql\u0026quot; --database-name \u0026quot;owncloud\u0026quot; --database-user \u0026quot;owncloud\u0026quot; --database-pass \u0026quot;6Vh44YmKoOcR2NWo\u0026quot; --admin-user \u0026quot;admin\u0026quot; --admin-pass \u0026quot;admin123\u0026quot; 源码安装看这里: https://doc.owncloud.org/server/9.0/admin_manual/installation/source_installation.html\n这里,我修改hosts文件添加了一个域名 yun.app 隐射到本地的虚拟机.虚拟机里添加了vhost对应这个域名,具体设置参照 http://huifeng.me/2016/05/19/LAMP-StepByStep/\n做完了上面的步骤,可以通过浏览器浏览了,我的: http://yun.app .这里遇到一个报错,意思是域名不被信任,可以修改 owncloud/config/config.php 来添加信任,我的配置文件:\n\u0026lt;?php $CONFIG = array ( 'instanceid' =\u0026gt; 'ocnvlfoeu6cz', 'passwordsalt' =\u0026gt; 'hWm51195qEAe8qpdb4q5gXYQa4C/0h', 'secret' =\u0026gt; '23VzMrQWzz/kIkJaCr861C9jv5UFyZBUH7uSQnnh/Tw2M9oX', 'trusted_domains' =\u0026gt; array ( 0 =\u0026gt; 'localhost', 1 =\u0026gt; 'yun.app', ), 'datadirectory' =\u0026gt; '/var/www/owncloud/data', 'overwrite.cli.url' =\u0026gt; 'http://yun.app', 'dbtype' =\u0026gt; 'mysql', 'version' =\u0026gt; '9.0.2.2', 'dbname' =\u0026gt; 'owncloud', 'dbhost' =\u0026gt; 'localhost', 'dbtableprefix' =\u0026gt; 'oc_', 'dbuser' =\u0026gt; 'owncloud', 'dbpassword' =\u0026gt; '6Vh44YmKoOcR2NWo', 'logtimezone' =\u0026gt; 'UTC', 'installed' =\u0026gt; true, ); 至此,网站可以正常浏览和访问了,上传下载都没问题.\n但是在管理页面我们会看到这样的提示:\n 你的数据目录和你的文件可能从互联网被访问到。.htaccess 文件不工作。我们强烈建议你配置你的网页服务器,使数据目录不再可访问,或者将数据目录移动到网页服务器根文档目录之外。 您正在通过 HTTP 访问该站点,我们强烈建议您按照安全提示配置服务器强制使用 HTTPS。 内存缓存未配置。如果可用,请配置 memcache 来增强性能。更多信息请查看我们的文档 。 下面解决他们!\n 三. 推荐的设定(可选) 1. Operating system (非必须!先看完说明再设置) **When having an open_basedir configured within your php.ini file, make sure to include /dev/urandom. 如果你的配置文件里的这项是注释掉的就忽略这一步!!\n Give PHP read access to /dev/urandom :\n$ sudo vim /etc/php/7.0/apache2/php.ini Change line begin with ;open_basedir to:\nopen_basedir = /dev/urandom Then:\n$ sudo service apache2 restart 2. Use HTTPS 可能会用到的参考文档:\n https://doc.owncloud.org/server/9.0/admin_manual/installation/source_installation.html#enabling-ssl\n https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/oc_server_tuning.html#ssl-encryption-app\n https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/harden_server.html#use-https\n https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/occ_command.html#security-import-ssl-certificates\n https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04\n https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html\n 1. Redirect all unencrypted traffic to HTTPS 为了不影响原有的配置信息,我们先备份原有的配置文件,然后新建一个:\n$ sudo mv /etc/apache2/sites-available/owncloud.conf /etc/apache2/sites-available/owncloud.conf.bak $ sudo touch /etc/apache2/sites-available/owncloud-ssl.conf 这里新建的这个配置文件的内容可以参考该目录下系统自带的一个默认配置文件: default-ssl.conf.\n然后编辑新添加的配置文件:\n$ sudo vim /etc/apache2/sites-available/owncloud-ssl.conf 添加所有指向该域名的都转为 https :\n\u0026lt;VirtualHost *:80\u0026gt; ServerName cloud.owncloud.com Redirect permanent / https://cloud.owncloud.com/ \u0026lt;/VirtualHost\u0026gt; 这里的 cloud.owncloud.com 是你自己设定的.根据你的域名或本地hosts隐射决定.\n2. Enable HTTP Strict Transport Security 再添加一段 443 端口的设置到这个文件里:\n\u0026lt;VirtualHost *:443\u0026gt; ServerName cloud.owncloud.com \u0026lt;IfModule mod_headers.c\u0026gt; Header always set Strict-Transport-Security \u0026quot;max-age=15768000; includeSubDomains; preload\u0026quot; \u0026lt;/IfModule\u0026gt; \u0026lt;/VirtualHost\u0026gt; If you have subdomains not accessible via HTTPS, remove includeSubdomains; .\nOwncloud 官方文档就指导到这里了.然后发现 apache2 服务根本起不来,虽然我知道日志在 /var/log/apache2/error_log, 但是我还是决定参考默认的 default-ssl.conf 文件配置一下,当然结果很理想,一些细节功能以及原因,原理,更多配置等,我还没着急研究,但是我这个配置成功启动了,只是https访问的时候会有不认可的网站红色标记.这个后面在解决.更多详细内容我想可以在这里得到答案: https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html\n我最终的配置文件如下:\n\u0026lt;VirtualHost *:80\u0026gt; ServerAdmin wedojava@gmail.com ServerName yun.app Redirect permanent / https://yun.app/ \u0026lt;/VirtualHost\u0026gt; \u0026lt;IfModule mod_ssl.c\u0026gt; \u0026lt;VirtualHost *:443\u0026gt; ServerAdmin wedojava@gmail.com ServerName yun.app DirectoryIndex index.html index.php DocumentRoot /var/www/owncloud SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key \u0026lt;FilesMatch \u0026quot;\\.(cgi|shtml|phtml|php)$\u0026quot;\u0026gt; SSLOptions +StdEnvVars \u0026lt;/FilesMatch\u0026gt; \u0026lt;Directory /usr/lib/cgi-bin\u0026gt; SSLOptions +StdEnvVars \u0026lt;/Directory\u0026gt; BrowserMatch \u0026quot;MSIE [2-6]\u0026quot; \\ nokeepalive ssl-unclean-shutdown \\ downgrade-1.0 force-response-1.0 # MSIE 7 and newer should be able to use keepalive BrowserMatch \u0026quot;MSIE [17-9]\u0026quot; ssl-unclean-shutdown \u0026lt;IfModule mod_headers.c\u0026gt; Header always set Strict-Transport-Security \u0026quot;max-age=15768000; includeSubDomains; preload\u0026quot; \u0026lt;/IfModule\u0026gt; \u0026lt;/VirtualHost\u0026gt; \u0026lt;/IfModule\u0026gt; 3. Create SSL Certificate on Apache for Ubuntu 14 Step One — Activate the SSL Module 这一步应该在之前就已经做过了,如果没做过就执行一遍,然后会有若干的 true 的返回. SSL support actually comes standard in the Ubuntu 14.04 Apache package. We simply need to enable it to take advantage of SSL on our system.\nEnable the module by typing:\n$ sudo a2enmod ssl After you have enabled SSL, you\u0026rsquo;ll have to restart the web server for the change to be recognized:\n$ sudo service apache2 restart With that, our web server is now able to handle SSL if we configure it to do so.\nStep Two — Create a Self-Signed SSL Certificate Let\u0026rsquo;s start off by creating a subdirectory within Apache\u0026rsquo;s configuration hierarchy to place the certificate files that we will be making:\n$ sudo mkdir /etc/apache2/ssl Now that we have a location to place our key and certificate, we can create them both in one step by typing:\n$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt Let\u0026rsquo;s go over exactly what this means.\n openssl: This is the basic command line tool provided by OpenSSL to create and manage certificates, keys, signing requests, etc. req: This specifies a subcommand for X.509 certificate signing request (CSR) management. X.509 is a public key infrastructure standard that SSL adheres to for its key and certificate managment. Since we are wanting to create a new X.509 certificate, this is what we want. -x509: This option specifies that we want to make a self-signed certificate file instead of generating a certificate request. -nodes: This option tells OpenSSL that we do not wish to secure our key file with a passphrase. Having a password protected key file would get in the way of Apache starting automatically as we would have to enter the password every time the service restarts. -days 365: This specifies that the certificate we are creating will be valid for one year. -newkey rsa:2048: This option will create the certificate request and a new private key at the same time. This is necessary since we didn\u0026rsquo;t create a private key in advance. The rsa:2048 tells OpenSSL to generate an RSA key that is 2048 bits long. -keyout: This parameter names the output file for the private key file that is being created. -out: This option names the output file for the certificate that we are generating. When you hit \u0026ldquo;ENTER\u0026rdquo;, you will be asked a number of questions.\nThe questions portion looks something like this:\nCountry Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:New York Locality Name (eg, city) []:New York City Organization Name (eg, company) [Internet Widgits Pty Ltd]:Your Company Organizational Unit Name (eg, section) []:Department of Kittens Common Name (e.g. server FQDN or YOUR name) []:your_domain.com Email Address []:your_email@domain.com The key and certificate will be created and placed in your /etc/apache2/ssl directory.\nStep Three — Configure Apache to Use SSL 之前我们已经配置好了 -ssl 的配置文件,但证书指向的不是我们指定的,而是默认的,既然我们已经生成了证书,应用它,并重启服务器.\n$ sudo vim /etc/apache2/sites-available/owncloud-ssl.conf 修改:\nSSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key 为:\nSSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key 重启看看效果: sudo service apache2 restart\n一些不好解决但也不要紧的问题(对我而言) 点击浏览器的https的按钮可以看到我们刚才填写的证书信息.但是浏览器地址栏的 https 是红色表示不可信,怎么办呢?从服务器上把证书考到本地,然后运行安装为可信,可以参考这个帖子: http://superuser.com/questions/632059/how-to-add-a-self-signed-certificate-as-an-exception-in-chrome# ↓ Export the certificate from Chrome, and then import the certificate into your trusted root certification authority store. Unfortunately Microsoft made this difficult to do.\nGo to Start | and run the command certmgr.msc.\nExpand the tree to get to Trusted Root Certification Authorities | Certificates. Go to All Tasks, choose Import and import the certificate in question.\nTo export the certificate from Chrome:\nClick on the Certificate icon in the address bar. Click on Certificate Information | Details and then Copy to File.\n下面这一步我不明白它具体的作用和意义,但我还是做了一下,该命令的执行需要在 owncloud 的目录下运行 /var/www/owncloud :\n$ sudo -u www-data php occ security:certificates:import /etc/apache2/ssl/apache.crt 官方是这么说的:\n Use these commands to manage server-wide SSL certificates. These are useful when you create federation shares with other ownCloud servers that use self-signed certificates\n 更多occ命令在: https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/occ_command.html\n3. Setting Strong Directory Permissions https://doc.owncloud.org/server/9.0/admin_manual/installation/installation_wizard.html#strong-perms-label ↓ Your HTTP user must own the config/, data/ and apps/ directories so that you can configure ownCloud, create, modify and delete your data files, and install apps via the ownCloud Web interface.\nYou can find your HTTP user in your HTTP server configuration files.\n The HTTP user and group in Debian/Ubuntu is www-data. The HTTP user and group in Fedora/CentOS is apache. The HTTP user and group in Arch Linux is http. The HTTP user in openSUSE is wwwrun, and the HTTP group is www. The easy way to set the correct permissions is to copy and run this script. Replace the ocpath variable with the path to your ownCloud directory, and replace the htuser and htgroup variables with your HTTP user and group:\n#!/bin/bash ocpath='/var/www/owncloud' htuser='www-data' htgroup='www-data' rootuser='root' printf \u0026quot;Creating possible missing Directories\\n\u0026quot; mkdir -p $ocpath/data mkdir -p $ocpath/assets mkdir -p $ocpath/updater printf \u0026quot;chmod Files and Directories\\n\u0026quot; find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640 find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750 printf \u0026quot;chown Directories\\n\u0026quot; chown -R ${rootuser}:${htgroup} ${ocpath}/ chown -R ${htuser}:${htgroup} ${ocpath}/apps/ chown -R ${htuser}:${htgroup} ${ocpath}/assets/ chown -R ${htuser}:${htgroup} ${ocpath}/config/ chown -R ${htuser}:${htgroup} ${ocpath}/data/ chown -R ${htuser}:${htgroup} ${ocpath}/themes/ chown -R ${htuser}:${htgroup} ${ocpath}/updater/ chmod +x ${ocpath}/occ printf \u0026quot;chmod/chown .htaccess\\n\u0026quot; if [ -f ${ocpath}/.htaccess ] then chmod 0644 ${ocpath}/.htaccess chown ${rootuser}:${htgroup} ${ocpath}/.htaccess fi if [ -f ${ocpath}/data/.htaccess ] then chmod 0644 ${ocpath}/data/.htaccess chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess fi If you have customized your ownCloud installation and your filepaths are different than the standard installation, then modify this script accordingly.\nThis lists the recommended modes and ownership for your ownCloud directories and files:\nAll files should be read-write for the file owner, read-only for the group owner, and zero for the world All directories should be executable (because directories always need the executable bit set), read-write for the directory owner, and read-only for the group owner\n The apps/ directory should be owned by [HTTP user]:[HTTP group] The config/ directory should be owned by [HTTP user]:[HTTP group] The themes/ directory should be owned by [HTTP user]:[HTTP group] The assets/ directory should be owned by [HTTP user]:[HTTP group] The data/ directory should be owned by [HTTP user]:[HTTP group] The [ocpath]/.htaccess file should be owned by root:[HTTP group] The data/.htaccess file should be owned by root:[HTTP group] Both .htaccess files are read-write file owner, read-only group and world 需要注意的是,这个脚本的运行的确令owncloud更安全,但是同时页阻碍了版本的升级,如果运行了该脚本,要升级的时候请移步这里: Setting Permissions for Updating\n4. 缓存 Memory cache configuration for the ownCloud server is no longer automatic in ownCloud 8.1 and up, but must be installed and configured. https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/caching_configuration.html ↓\nRecommended caches are APCu and Redis. 因为我们用的是 PHP7, Redis好像更好用一些,关于Redis的安装,过程比较长,我新开页面了.\n参考:\nhttps://www.techandme.se/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/ http://thereluctantdeveloper.com/2015/12/quick-and-dirty-php-70-set-up-on-ubuntu-1404-with-apcu\n这里我用的是redis来处理缓存,一切正常. 因为本文篇幅也太长了,所以,新开一页,其他内容以后有时间再抽象出来: http://huifeng.me/2016/06/08/install-redis-cache-on-ubuntu-server-with-php-7-and-owncloud/\n至此,主要内容都完了,就差数据存放目录了,应有附加新磁盘的动作,后续在写.\n5. 改变数据目录 你的数据目录和你的文件可能从互联网被访问到。.htaccess 文件不工作。我们强烈建议你配置你的网页服务器,使数据目录不再可访问,或者将数据目录移动到网页服务器根文档目录之外。\n 注意,它说的是数据目录会被访问到,让你移动网页目录的外面,那么就这么整吧.当然,还有个问题也要注意到:.htaccess 文件不工作。 这应该是 Apache 的设置缺少: AllowOverride All 查阅官方文档的 Apache Web Server Configuration 可以发现这里的主要配置是:\n\u0026lt;Directory /var/www/owncloud/\u0026gt; Options +FollowSymlinks AllowOverride All \u0026lt;IfModule mod_dav.c\u0026gt; Dav off \u0026lt;/IfModule\u0026gt; SetEnv HOME /var/www/owncloud SetEnv HTTP_HOME /var/www/owncloud \u0026lt;/Directory\u0026gt; 我们把这段拷贝到 我们自己添加好的那个 owncloud-ssl.conf 文件里去,最终: /etc/apache2/sites-available/owncloud-ssl.conf :\n\u0026lt;VirtualHost *:80\u0026gt; ServerAdmin wedojava@gmail.com ServerName yun.app Redirect permanent / https://yun.app/ \u0026lt;/VirtualHost\u0026gt; \u0026lt;IfModule mod_ssl.c\u0026gt; \u0026lt;VirtualHost *:443\u0026gt; ServerAdmin wedojava@gmail.com ServerName yun.app DirectoryIndex index.html index.php DocumentRoot /var/www/owncloud SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key \u0026lt;FilesMatch \u0026quot;\\.(cgi|shtml|phtml|php)$\u0026quot;\u0026gt; SSLOptions +StdEnvVars \u0026lt;/FilesMatch\u0026gt; \u0026lt;Directory /var/www/owncloud/\u0026gt; Options +FollowSymlinks AllowOverride All \u0026lt;IfModule mod_dav.c\u0026gt; Dav off \u0026lt;/IfModule\u0026gt; SetEnv HOME /var/www/owncloud SetEnv HTTP_HOME /var/www/owncloud \u0026lt;/Directory\u0026gt; \u0026lt;Directory /usr/lib/cgi-bin\u0026gt; SSLOptions +StdEnvVars \u0026lt;/Directory\u0026gt; BrowserMatch \u0026quot;MSIE [2-6]\u0026quot; \\ nokeepalive ssl-unclean-shutdown \\ downgrade-1.0 force-response-1.0 # MSIE 7 and newer should be able to use keepalive BrowserMatch \u0026quot;MSIE [17-9]\u0026quot; ssl-unclean-shutdown \u0026lt;IfModule mod_headers.c\u0026gt; Header always set Strict-Transport-Security \u0026quot;max-age=15768000; includeSubDomains; preload\u0026quot; \u0026lt;/IfModule\u0026gt; \u0026lt;/VirtualHost\u0026gt; \u0026lt;/IfModule\u0026gt; 后续我会把数据放的单独的虚拟硬盘上,所以移动数据目录位置后面到那步了我再继续写.\n","permalink":"https://huifeng.me/posts/owncloud-install/","tags":["linux"," owncloud"," install"," cloud"," apache"," php7"," mysql"," mariadb"],"title":"Owncloud 安装实录(Apache2.4+PHP7+MariaDB10)"},{"categories":["Linux"],"contents":" Thanks for: http://www.111cn.net/sys/Ubuntu/73675.htm 用 vagrant 本地虚拟了一个 Ubuntu,想把数据放到单独的磁盘里,查阅资料,下面把日志记录下来。\n 虚拟机里的新加磁盘类型是 VMDK ,动态分配大小,大小20G。\n运行:\nvagrant up vagrant ssh 进入虚拟机!\n一、查询现有硬盘情况 运行: sudo fdisk -l\n运行 ll -h /dev/sd* 测试linux系统是否能找到挂载的未分区硬盘:\n得到:\nbrw-rw---- 1 root disk 8, 0 4月 19 05:15 /dev/sda brw-rw---- 1 root disk 8, 1 4月 19 05:15 /dev/sda1 brw-rw---- 1 root disk 8, 16 4月 19 05:15 /dev/sdb Linux 硬盘识别:\n 2.6 kernel以后,linux会将识别到的硬件设备,在/dev/下建立相应的设备文件. 如: sda 表示第1块SCSI硬盘,第二块是sdb,以此类推 hda 表示第1块IDE硬盘(即连接在第1个IDE接口的Master口上) scd0 表示第1个USB光驱. 当添加了新硬盘后,在/dev目录下会有相应的设备文件产生.cciss的硬盘是个例外,它的 设备文件在/dev/cciss/目录下.\n 二、挂载硬盘 1. 创建未被挂载的磁盘分区 fdisk /dev/sdb 此时会进入到 Command 的状态,大概是这么操作的:\n 输入 m 查看帮助 输入 p 查看 /dev/sdb 分区的状态 输入 n 创建sdb这块硬盘的分区 选 p primary =\u0026gt;输入 p Partition number =\u0026gt;分一个区所以输入 1 其他的默认即可 输入 w 保存并退出 Command 状态。 下面全是命令行下的操作过程:\n# 查看帮助信息 Command (m for help): m Command action a toggle a bootable flag 将分区设置为启动区 b edit bsd disklabel 编辑bsd的disklabel c toggle the dos compatibility flag 设置该分区为dos分区 d delete a partition 删除分区 l list known partition types 列出已知的分区类型 m print this menu 打印帮助列表 n add a new partition 创建新分区 o create a new empty DOS partition table p print the partition table查看分区信息 q quit without saving changes 退出不保存 s create a new empty Sun disklabel t change a partition's system id改变分区类型 u change display/entry units v verify the partition table w write table to disk and exit 保存退出 x extra functionality (experts only) # 查看sdb这块硬盘的分区 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xf74052cc Device Boot Start End Blocks Id System # 创建sdb这块硬盘的分区 Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 #查看创建sdb硬盘的分区 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xf74052cc Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 83 Linux #保存退出,分区创建结束 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. fdisk的操作告一段落,现在可以再用 sudo fdisk -l 查看硬盘信息就可以看到sdb1新分区了:\nvagrant@vagrant-ubuntu-trusty-64:~$ sudo fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes 4 heads, 32 sectors/track, 655360 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000020ea Device Boot Start End Blocks Id System /dev/sda1 * 2048 83886079 41942016 83 Linux Disk /dev/sdb: 21.5 GB, 21474836480 bytes 213 heads, 34 sectors/track, 5791 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xf74052cc Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 83 Linux 2. 格式化未被挂载的磁盘 sudo mkfs.ext3 /dev/sdb1 下面是具体过程:\nvagrant@vagrant-ubuntu-trusty-64:~$ sudo mkfs.ext3 /dev/sdb1 mke2fs 1.42.9 (4-Feb-2014) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5242624 blocks 262131 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 160 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done 3. 创建目录并挂载 sudo mkdir /data1 sudo mount /dev/sdb1 /data1 三、开机自动挂载 因为mount挂载在重启服务器后会失效,所以需要将分区信息写到/etc/fstab文件中让它永久挂载:\ne2label /dev/hda6 先查看需要挂载硬盘分区的labl /home e2label /dev/hda6 home1 因为系统中已经有个/home的label了,所以这里要重新把/dev/hda6的label设置为home1 vi /etc/fstab 在尾部加上\n/dev/sdb1 /home ext3 defaults 0 0 表示把新的硬盘分区挂载到 /home 这个目录 在修改 /etc/fstab 文件后,运行 mount -a 命令验证一下配置是否正确,否则错误配置 fstab 文件导致系统无法正常启动。如果系统无法正常启动,则输入root密码进入修复模式,关键的一步是重新 mount /(mount -n -o remount,rw /) 。如果没有此步操作,则文件系统处于只读状态,导致不能修改配置文件并保存,修复存在的问题。\n重启系统\n四、其他可能会用到的命令 sudo vi /etc/fstab sudo umount /data1 #卸载磁盘到/data1的映射 sudo dd if=/dev/zero of=/dev/sdb 填零/dev/sdb cat /proc/mounts 查看映射信息 ","permalink":"https://huifeng.me/posts/new-disk-mount-to-ubuntu/","tags":["linux"," ubuntu"," disk"," 挂载"," 硬盘"],"title":"为 Ubuntu 加载新硬盘"},{"categories":["Docker"],"contents":" 参考:\n Docker —— 从入门到实践 Docker官方-Linux For Windows 10(failed) Reference:\nRun Linux containers on Windows\nPreparation hyper-v installed docker installed (2.2.0 install cannot be success. recommend 2.1.0) Install(Method 1) while, I update docker.exe everything goes well.\n Download docker.exe from Docker Master Binaries Replace C:\\Program Files\\Docker\\Docker\\resources\\bin\\docker.exe you download from link above, and you can download any image from container manager: Kitematic Install(method 2 failed) Install docker desktop and download container manager: Kitematic\n download: Canonical Partner Images of Ubuntu for Linux containers on Microsoft Hyper-V and unzip it.\n mkdir C:\\\\lcow used as scratch space for Docker while preparing the containers.\n mkdir C:\\\\Program Files\\\\Linux Containers where the Ubuntu container image will live.\n TIPS: never change the path: C:\\\\Program Files\\\\Linux Containers, it must be there.\n Save script below to .\\set_perms.ps1:\n param( [string] $Root ) # Give the virtual machines group full control $acl = Get-Acl -Path $Root $vmGroupRule = new-object System.Security.AccessControl.FileSystemAccessRule(\u0026#34;NT VIRTUAL MACHINE\\Virtual Machines\u0026#34;, \u0026#34;FullControl\u0026#34;,\u0026#34;ContainerInherit,ObjectInherit\u0026#34;, \u0026#34;None\u0026#34;, \u0026#34;Allow\u0026#34;) $acl.SetAccessRule($vmGroupRule) Set-Acl -AclObject $acl -Path $Root You will need to give this folder extra permissions to allow Docker to use the images from it. Run the following Powershell script in an administrator Powershell window:\n TIP You may need to run Set-ExecutionPolicy -Scope process unrestricted to be allowed to run unsigned Powershell scripts.\n .\\set_perms.ps1 \u0026#34;C:\\\\Program Files\\\\Linux Containers\u0026#34; Now, copy the Ubuntu container image .vhdx file that was decompressed at the previous step to uvm.vhdx under C:\\Program Files\\Linux Containers.\n For Ubuntu 系统要求 use command blow:\nuname -a or\ncat /proc/version to get the kenrel version that is must biger than 3.10.\nNotice: Your Ubuntu version must biger than 12.04.\nFirst to update or have these packages which is blow:\n linux-image-generic-lts-trusty (必备) linux-headers-generic-lts-trusty (必备) xserver-xorg-lts-trusty (带图形界面时必备) libgl1-mesa-glx-lts-trusty(带图形界面时必备) To use aufs storage,you\u0026rsquo;d better get the package:linux-image-extra\nsudo apt-get install -y linux-image-extra-$(uname -r) 添加镜像源 首先需要安装 apt-transport-https 包支持 https 协议的源。\nsudo apt-get install -y apt-transport-https 添加源的 gpg 密钥。\nsudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D 获取当前操作系统的代号。\nlsb_release -c // echo info! Codename: wily 12.04 (LTS) 代号为 precise,14.04 (LTS) 代号为 trusty,15.04 代号为 vivid,15.10 代号为 wily。\n接下来就可以添加 Docker 的官方 apt 软件源了。通过下面命令创建 /etc/apt/sources.list.d/docker.list 文件,并写入源的地址内容。非 wily 版本的系统注意修改为自己对应的代号。\nsudo cat \u0026lt;\u0026lt;EOF \u0026gt; /etc/apt/sources.list.d/docker.list deb https://apt.dockerproject.org/repo ubuntu-wily main EOF 如果执行报权限不足,请直接 su 用 root 用户执行。\n添加成功后,更新 apt 软件包缓存。\nsudo apt-get update ","permalink":"https://huifeng.me/posts/docker-install-log/","tags":["docker"," log"," ubuntu"],"title":"Docker-Install-Log"},{"categories":["Laravel"],"contents":"常常会用到 artisan 的一些命令,往往要去查文档,翻弄半天,不方便,这里归纳在这里\n一、控制器 5.1 --plain用于创建一个空的控制器而不是标准的 RESTful 风格控制器。 5.2 --plain无效,默认即是空的控制器,要自带生成各类方法框架需要添加参数:--resource php artisan make:controller BlogController --resource 则生成的方法和5.1前,没有添加任何参数生成的控制器一样。\n二、模型和数据库迁移 1、创建模型的同时创建表的迁移 php artisan make:model --migration Post 或:\nphp artisan make:model --m Post 上述命令会做两件事情:\n 在 app 目录下创建模型类 App\\Post; 创建用于创建 posts 表的迁移,该迁移文件位于 database/migrations 目录下。 生成的迁移文件的关键位置是:\nSchema::create(\u0026#39;posts\u0026#39;, function (Blueprint $table) { 注意,是Schema::create。\n2、创建表的迁移 php artisan make:migration create_users_table --create=users --create=users:该迁移是否要创建一个新的数据表users\n3、修改表字段的迁移 在 Laravel 5.1 中如果需要修改数据表的列,则需要安装 Doctrine 依赖包,我们使用 Composer 安装该依赖包:\ncomposer require \u0026quot;doctrine/dbal\u0026quot; 接下来使用 Artisan 命令创建新的迁移文件:\nphp artisan make:migration --table=posts restructure_posts_table restructure是关键字,--table=posts指定了要操作的表\n生成文件的关键位置为:\nSchema::table(\u0026#39;posts\u0026#39;, function (Blueprint $table) { // ...... $table-\u0026gt;renameColumn(\u0026#39;content\u0026#39;, \u0026#39;content_raw\u0026#39;); // ...... change():修改已存在的列为新的类型,或者修改列的属性。 $table-\u0026gt;string('name', 50)-\u0026gt;change();即就是修改 name 列的尺寸为50。 $table-\u0026gt;string('name', 50)-\u0026gt;nullable()-\u0026gt;change();即就是修改 name 列为可空。\n列修改器列表:\n 修改器 描述 -\u0026gt;first() 将该列置为表中第一个列 (仅适用于MySQL) -\u0026gt;after('column') 将该列置于另一个列之后 (仅适用于MySQL) -\u0026gt;nullable() 允许该列的值为NULL -\u0026gt;default($value) 指定列的默认值 -\u0026gt;unsigned() 设置 integer 列为 UNSIGNED 更多信息可参考 laravel学院的文档\n4、添加新字段到已存在的表 php artisan make:migration alter_posts_deleted_at --table=posts alter是关键字,--table=posts指定要操作的表\n生成文件的关键位置为:\nSchema::table(\u0026#39;posts\u0026#39;, function (Blueprint $table) { 5、创建迁移文件:关系表 php artisan make:migration create_user_accounts_table --create=user_accounts 创建表:user_accounts\n关键行:\nSchema::create(\u0026#39;user_accounts\u0026#39;, function (Blueprint $table) { 6、运行迁移 php artisan migrate 可以接的参数: --force:在生产环境中强制运行迁移\n","permalink":"https://huifeng.me/posts/laravel-artisan-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/","tags":["laravel"," artisan"],"title":"laravel-artisan-model-常用命令"},{"categories":["Laravel"],"contents":"关于 laravel 的很多理解还是比较缺乏,最近看 laravel 学院的基础教程,这里把我的个人理解放这里,方便日后温故。\n原理概括 第一步定义服务类。也就是我们具体的逻辑方法等,定义这个类又应该有契约约束,所以定义接口并让服务类继承实现,所以第一步是包括服务类和接口的定义。 第二步定义服务提供者。服务有了,需要专人负责实时所提供的服务,实例化对象和绑定在这里完成。 第三步注册服务。公司装修好了,设备也都能运转了,可要是向所有人提供服务就需要获得政府的认可和注册,告诉政府公司地址,以便管控。 第四步开店营业。所有事务都以准备完毕,可以开张营业了,店面负责展示和向公司提交订单等业务逻辑(路由、控制器和视图)。 案例实现 1、定义服务类 按照正常思维逻辑,我们需要实现某功能或服务,现在,我们创建服务类,考虑到创建服务类应该先创建其接口来约束该类,所以我们要先创建这个约束其行为的接口app\\TestContracts\\TestContract.php:\n\u0026lt;?php namespace App\\Contracts; interface TestContract { public function callMe($controller); } 然后我们来定义针对这个接口的实现,具体的服务逻辑app\\Services\\TestService.php:\n\u0026lt;?php namespace App\\Services; use App\\Contracts\\TestContract; class TestService implements TestContract { public function callMe($controller) { dd(\u0026#39;Call Me From TestServiceProvider In \u0026#39;.$controller); } } 2、创建服务提供者 第一步是为了制造机器,机器制造好了,需要用好机器,服务提供者就是用机器的人,绑定和实例化应该是在这里完成。 定义一个服务提供者TestServiceProvider,运行下面的命令:\nphp artisan make:provider TestServiceProvider 成执行会在app/Providers目录下生成一个TestServiceProvider.php文件,我们修改其内容如下:\n\u0026lt;?php namespace App\\Providers; use Illuminate\\Support\\ServiceProvider; use App\\Services\\TestService; class TestServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { // } /** * Register the application services. * * @return void * @author LaravelAcademy.org */ public function register() { //使用singleton绑定单例 $this-\u0026gt;app-\u0026gt;singleton(\u0026#39;test\u0026#39;,function(){ return new TestService(); }); //使用bind绑定实例到接口以便依赖注入 $this-\u0026gt;app-\u0026gt;bind(\u0026#39;App\\Contracts\\TestContract\u0026#39;,function(){ return new TestService(); }); } } register() 方法里的这两种绑定方式是由区别的,可以参考服务容器文档了解更多。\n3、注册服务提供者 服务提供者多了,系统难免难于管理,为了更有条理的管理好各类服务提供者,应该有政府出面来负责各类服务的注册,注册的意思就是说,只有在政府注册了的公司才可以合法经营。 laravel 所有的注册都是在config/app.php里。我们在provider数组里追加我们新增加的服务:\n// 更多 \u0026#39;providers\u0026#39; =\u0026gt; [ //其他服务提供者 App\\Providers\\TestServiceProvider::class, ], // 更多 4、测试服务提供者 这里包括创建测试用控制器和视图,添加测试用路由等。\n创建控制器 创建TestController控制器,运行:\nphp artisan make:controller TestController 控制器内容为:\n\u0026lt;?php namespace App\\Http\\Controllers; use Illuminate\\Http\\Request; use App\\Http\\Requests; use App\\Http\\Controllers\\Controller; use App; use App\\Contracts\\TestContract; class TestController extends Controller { //依赖注入 public function __construct(TestContract $test){ $this-\u0026gt;test = $test; } /** * Display a listing of the resource. * * @return Response * @author LaravelAcademy.org */ public function index() { // $test = App::make(\u0026#39;test\u0026#39;); // $test-\u0026gt;callMe(\u0026#39;TestController\u0026#39;); $this-\u0026gt;test-\u0026gt;callMe(\u0026#39;TestController\u0026#39;); } ...//其他控制器动作 } 配置路由 在routes.php中添加一条路由:\nRoute::resource(\u0026#39;test\u0026#39;,\u0026#39;TestController\u0026#39;); 此时,我们可以测试下:http://youwebsite/test,应该会输出这样一行内容:\n \u0026ldquo;Call Me From TestServiceProvider In TestController\u0026rdquo;\n 此外,Laravel服务提供者还支持延迟加载,具体可参考服务提供者文档。\n","permalink":"https://huifeng.me/posts/laravel-%E6%9C%8D%E5%8A%A1%E6%8F%90%E4%BE%9B%E8%80%85-%E6%88%91%E6%98%AF%E8%BF%99%E4%B9%88%E7%90%86%E8%A7%A3%E7%9A%84/","tags":["laravel"," 服务提供者"],"title":"laravel-服务提供者-我是这么理解的"},{"categories":["翻墙"],"contents":" 参考文档:https://quericy.me/blog/512 一键脚本:http://quericy.me/blog/699 目前用的一键脚本:https://blog.ls20.com/ipsec-l2tp-vpn-auto-setup-for-ubuntu-12-04-on-amazon-ec2/ 一键脚本说明:https://github.com/hwdsl2/setup-ipsec-vpn\n 因为我的 vps 是 CentOS 系统,所以 Ubuntu 没测试,本日志主要记录我在 CentOS 上的各种操作。\n编辑安装 Strongswan 安装必备库 Ubuntu: apt-get update apt-get install libpam0g-dev libssl-dev make gcc CentOS: yum update yum install pam-devel openssl-devel make gcc 下载和解压 Strongswan wget http://download.strongswan.org/strongswan.tar.gz tar xzf strongswan.tar.gz cd strongswan-* 编译Strongswan Xen、KVM使用以下参数 ./configure --enable-eap-identity --enable-eap-md5 \\ --enable-eap-mschapv2 --enable-eap-tls --enable-eap-ttls --enable-eap-peap \\ --enable-eap-tnc --enable-eap-dynamic --enable-eap-radius --enable-xauth-eap \\ --enable-xauth-pam --enable-dhcp --enable-openssl --enable-addrblock --enable-unity \\ --enable-certexpire --enable-radattr --enable-tools --enable-openssl --disable-gmp OpenVZ需额外增加一个 enable-kernel-libipsec ./configure --enable-eap-identity --enable-eap-md5 \\ --enable-eap-mschapv2 --enable-eap-tls --enable-eap-ttls --enable-eap-peap \\ --enable-eap-tnc --enable-eap-dynamic --enable-eap-radius --enable-xauth-eap \\ --enable-xauth-pam --enable-dhcp --enable-openssl --enable-addrblock --enable-unity \\ --enable-certexpire --enable-radattr --enable-tools --enable-openssl --disable-gmp --enable-kernel-libipsec 编译安装 make; make install 编译完成后如果没有报错,且使用ipsec version指令能出现版本信息,则表示安装成功.\n配置证书 生成CA证书的私钥: ipsec pki --gen --outform pem \u0026gt; ca.pem 使用私钥,签名CA证书: ipsec pki --self --in ca.pem --dn \u0026#34;C=com, O=myvpn, CN=VPN CA\u0026#34; --ca --outform pem \u0026gt;ca.cert.pem 生成服务器证书所需的私钥: ipsec pki --gen --outform pem \u0026gt; server.pem 用CA证书签发服务器证书: 请先确认你的服务器的IP地址或域名,以后客户端连接时只能使用证书中的地址连接(多服务器使用相同根证书CA的,请先做好服务器的域名解析), 然后将下面命令中的123.123.123.123替换为自己服务器的IP地址或域名,一共需要替换两处:\n ipsec pki --pub --in server.pem | ipsec pki --issue --cacert ca.cert.pem \\ --cakey ca.pem --dn \u0026#34;C=com, O=myvpn, CN=123.123.123.123\u0026#34; \\ --san=\u0026#34;123.123.123.123\u0026#34; --flag serverAuth --flag ikeIntermediate \\ --outform pem \u0026gt; server.cert.pem 注意以上命令中的”C=”和”O=”的值要与第2步CA中的C,O的值保持一致. 5. 生成客户端证书所需的私钥:\nipsec pki --gen --outform pem \u0026gt; client.pem 用CA签名客户端证书(C,O的值要与上面第2步CA的值一致,CN的值随意): ipsec pki --pub --in client.pem | ipsec pki --issue --cacert ca.cert.pem --cakey ca.pem --dn \u0026#34;C=com, O=myvpn, CN=VPN Client\u0026#34; --outform pem \u0026gt; client.cert.pem 生成pkcs12证书: openssl pkcs12 -export -inkey client.pem -in client.cert.pem -name \u0026#34;client\u0026#34; -certfile ca.cert.pem -caname \u0026#34;VPN CA\u0026#34; -out client.cert.p12 注意以上命令中的”-caname”后面的引号里的值必须要与第2步CA中的”CN=”的值保持一致. 8. 安装证书:\ncp -r ca.cert.pem /usr/local/etc/ipsec.d/cacerts/ cp -r server.cert.pem /usr/local/etc/ipsec.d/certs/ cp -r server.pem /usr/local/etc/ipsec.d/private/ cp -r client.cert.pem /usr/local/etc/ipsec.d/certs/ cp -r client.pem /usr/local/etc/ipsec.d/private/ 配置 Strongswan 编辑/usr/local/etc/ipsec.conf文件: vim /usr/local/etc/ipsec.conf 修改为以下内容:\nconfig setup uniqueids=never conn iOS_cert keyexchange=ikev1 # strongswan version \u0026gt;= 5.0.2, compatible with iOS 6.0,6.0.1 fragmentation=yes left=%defaultroute leftauth=pubkey leftsubnet=0.0.0.0/0 leftcert=server.cert.pem right=%any rightauth=pubkey rightauth2=xauth rightsourceip=10.31.2.0/24 rightcert=client.cert.pem auto=add conn android_xauth_psk keyexchange=ikev1 left=%defaultroute leftauth=psk leftsubnet=0.0.0.0/0 right=%any rightauth=psk rightauth2=xauth rightsourceip=10.31.2.0/24 auto=add conn networkmanager-strongswan keyexchange=ikev2 left=%defaultroute leftauth=pubkey leftsubnet=0.0.0.0/0 leftcert=server.cert.pem right=%any rightauth=pubkey rightsourceip=10.31.2.0/24 rightcert=client.cert.pem auto=add conn windows7 keyexchange=ikev2 ike=aes256-sha1-modp1024! rekey=no left=%defaultroute leftauth=pubkey leftsubnet=0.0.0.0/0 leftcert=server.cert.pem right=%any rightauth=eap-mschapv2 rightsourceip=10.31.2.0/24 rightsendcert=never eap_identity=%any auto=add 使用vim编辑/usr/local/etc/strongswan.conf文件: charon { load_modular = yes duplicheck.enable = no compress = yes plugins { include strongswan.d/charon/*.conf } dns1 = 8.8.8.8 dns2 = 8.8.4.4 nbns1 = 8.8.8.8 nbns2 = 8.8.4.4 } include strongswan.d/*.conf 使用vim编辑/usr/local/etc/ipsec.secrets文件: : RSA server.pem : PSK \u0026#34;myPSKkey\u0026#34; : XAUTH \u0026#34;myXAUTHPass\u0026#34; [用户名] %any : EAP \u0026#34;[密码]\u0026#34; 将上面的myPSKkey单词更改为你需要的PSK认证方式的密钥; 将上面的myXAUTHPass单词更改为你需要的XAUTH认证方式的密码,该认证方式的用户名是随意的; 将上面的[用户名]改为自己想要的登录名,[密码]改为自己想要的密码([]符号去掉),可以添加多行,得到多个用户,这即是使用IKEv2的用户名+密码认证方式的登录凭据.\n配置防火墙 编辑/etc/sysctl.conf,将net.ipv4.ip_forward=1一行前面的#号去掉(否则Ikev2 vpn连接上后将无法访问外网),保存后执行sysctl -p(如果执行后有报错的,重新打开sysctl.conf将报错的部分#注释掉保存,直到执行sysctl -p不再报错为止)。此外,如果需要对TCP连接及速度进行进一步优化,可以参见原作者的另一篇文章《各平台vps快速搭建shadowsocks及优化总结》中的TCP部分(注意不要把现有vpn配置的ip_forward给覆盖了). 配置iptables: OpenVZ执行: iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -s 10.31.0.0/24 -j ACCEPT iptables -A FORWARD -s 10.31.1.0/24 -j ACCEPT iptables -A FORWARD -s 10.31.2.0/24 -j ACCEPT iptables -A INPUT -i venet0 -p esp -j ACCEPT iptables -A INPUT -i venet0 -p udp --dport 500 -j ACCEPT iptables -A INPUT -i venet0 -p tcp --dport 500 -j ACCEPT iptables -A INPUT -i venet0 -p udp --dport 4500 -j ACCEPT iptables -A INPUT -i venet0 -p udp --dport 1701 -j ACCEPT iptables -A INPUT -i venet0 -p tcp --dport 1723 -j ACCEPT iptables -A FORWARD -j REJECT iptables -t nat -A POSTROUTING -s 10.31.0.0/24 -o venet0 -j MASQUERADE iptables -t nat -A POSTROUTING -s 10.31.1.0/24 -o venet0 -j MASQUERADE iptables -t nat -A POSTROUTING -s 10.31.2.0/24 -o venet0 -j MASQUERADE Xen、KVM则执行: iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -s 10.31.0.0/24 -j ACCEPT iptables -A FORWARD -s 10.31.1.0/24 -j ACCEPT iptables -A FORWARD -s 10.31.2.0/24 -j ACCEPT iptables -A INPUT -i eth0 -p esp -j ACCEPT iptables -A INPUT -i eth0 -p udp --dport 500 -j ACCEPT iptables -A INPUT -i eth0 -p tcp --dport 500 -j ACCEPT iptables -A INPUT -i eth0 -p udp --dport 4500 -j ACCEPT iptables -A INPUT -i eth0 -p udp --dport 1701 -j ACCEPT iptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT iptables -A FORWARD -j REJECT iptables -t nat -A POSTROUTING -s 10.31.0.0/24 -o eth0 -j MASQUERADE iptables -t nat -A POSTROUTING -s 10.31.1.0/24 -o eth0 -j MASQUERADE iptables -t nat -A POSTROUTING -s 10.31.2.0/24 -o eth0 -j MASQUERADE 开机自动载入iptables: - Ubuntu: iptables-save \u0026gt; /etc/iptables.rules cat \u0026gt; /etc/network/if-up.d/iptables\u0026lt;\u0026lt;EOF #!/bin/sh iptables-restore \u0026lt; /etc/iptables.rules EOF chmod +x /etc/network/if-up.d/iptables - CentOS: service iptables save 至此,IPSec/IKEv2 VPN便搭建好了!现在启用服务就可以使用了:ipsec start\n哎。。。服务启动成功了的,但是连接不上它啊。。。 回头再整。\n","permalink":"https://huifeng.me/posts/%E5%9C%A8ubuntu%E5%92%8Ccentos%E9%87%8C%E7%94%A8ipsec-ikev2%E6%90%AD%E5%BB%BAvpn%E6%9C%8D%E5%8A%A1%E5%99%A8/","tags":["Ubuntu"," CentOS"," IPSec"," VPN"," 翻墙"],"title":"在Ubuntu和CentOS里用IPSec/IKEV2搭建VPN服务器"},{"categories":["NodeJS"],"contents":"今天试着在 CentOS-7.1虚拟机上安装 nodejs 的环境,安装这个环境当然是为了能运行 Ghost 博客程序了,为什么要在虚拟机上安装?那是因为我打算搞到我自己的局域网服务器环境里去。下面开始!\n安装 Nginx Nginx 主要用于反向代理,后面说明。\n先安装下必备的 vim 和 wget:\nyum install -y vim wget 添加Nginx的仓储地址。输入:\nvim /etc/yum.repos.d/nginx.repo 接着按键盘上的 “i” 便于用vim编辑内容,把下面的内容粘贴进去。\n[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 编辑完成,按下 Esc,输入 :wq! 回车退出。 现在,用 yum 自动下载安装。\n如果你是 CentOS 7 以上版本:\nsudo yum install nginx -y sudo systemctl start nginx sudo systemctl enable nginx 如果你是 CentOS 7 以下版本:\nsudo yum install nginx -y sudo service nginx start sudo chkconfig nginx on 最后一行是设置为开机启动。\n安装 Nodejs 环境 一台崭新的虚拟机,什么都没装很干净,安全方面的内容在我其他博客上有说明,这里假设安全设置都已经完毕,编译环境还需要一些安装,至少让./configure,make,sudo make install命令能正确执行。\n编译环境 注意,如果你用的 nvm 来安装,那么可以直接跳过这一步,但是还是推荐你完成这一步,这在你未来编译安装任何其他软件也是有帮助的。\n 基础环境 运行:\nyum update -y \u0026amp;\u0026amp; yum install -y ncurses-devel make gcc bc 如果 sodu 不行就干脆登录 root 账号安装好了。\n运行:\nyum groupinstall 'Development Tools' The Development Tools package includes the core development tools like automake, gcc, perl, python, flex, make, gdb, bison, and many more. Update: For Fedora 20 (at least), you\u0026rsquo;ll additionally need to install gcc-c++.\n安装 nodejs 方法一:源码编译或通过包管理安装 包管理安装优点在于傻瓜些,可以参考这篇文档(需翻墙),以 centos 为例,需要运行这个:\ncurl --silent --location https://rpm.nodesource.com/setup | bash - 再运行:\nyum -y install nodejs 缺点在于目前只能安装 v0.10 的版本,如果你要安装指定版本,请去官方下载相应的 tar.gz 源码包,然后编译安装,编译方法:\ntar zxvf ***nodejs****.tar.gz 解压,然后进入解压的目录,运行:./configure=\u0026gt;make=\u0026gt;sudo make install,遇到权限问题试试 root 用户安装。\n方法二:通过 nvm 安装指定版本 这里先推荐下 Github 上的一份不错的教程:https://github.com/alsotang/node-lessons\n先安装 nvm: $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash nvm 的全称是 Node Version Manager,之所以需要这个工具,是因为 Node.js 的各种特性都没有稳定下来,所以我们经常由于老项目或尝新的原因,需要切换各种版本。 安装完成后,你的 shell 里面应该就有个 nvm 命令了,调用它试试:\n$ nvm 当看到有输出时,则 nvm 安装成功。注意,安装完请重新启动终端,否则命令无效。\n安装 Node.js 使用 nvm 的命令安装 Node.js 最新稳定版,现在是 v0.12.7(目前最新)\n$ nvm install 0.12 关于这部分的更多内容请参考: https://github.com/alsotang/node-lessons/tree/master/lesson0\n安装 Ghost 博客系统 准备工作 安装 nodejs 后,通过 nvm 命令发现 iojs 版本是空,所以安装下 Ghost 推荐的版本:\nnvm install io.js v1.2 确保在用的 nodejs 是0.12版本:nvm ls,如果不是就运行nvm use v0.12。\n安装 Ghost 去官方网站下载最新的包:\ncurl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip 解压到 ghost 目录下:\nunzip -d ghost ghost-0.7.1.zip 到 ghost 目录下,运行:\nnpm install --production 如果你没有 VPN 也许会遇到因为网络不给力而导致的安装问题,那么可以去 ghost 中国去下载 full 包\n以生产模式运行 Ghost 要部署,我们不能让其运行在开发模式。需要让其运行在生产模式,且当其运行进程退出时自动重启。因此我们可以使用强大的进程守护程序“pm2”达到此目的。(也可以使用Forever)\n进入到刚才的Ghost安装目录,执行下面的命令安装PM2:\nsudo npm install pm2 -g 我们要设置环境变量为“production”生产模式!“index.js”是程序启动的入口。最后给这个pm2的进程命名为\u0026quot;ghost\u0026rdquo; 于是,执行下面的命令:\nNODE_ENV=production pm2 start index.js --name \u0026quot;ghost\u0026quot; 让PM2知道在开机后自动运行我们的网站:\npm2 startup centos pm2 save 提示: pm2 kill ghost (清除所有ghost进程)\npm2 \u0026lt;start|stop|restart\u0026gt; ghost (启动|停止|重启ghost进程) pm2 startup \u0026lt;centos|ubuntu|amazon\u0026gt; (让pm2能够在这3个系统上自动启动) 至此,pm2 已经可以守护 Ghost 博客永远在线。\n配置 Nginx 的反向代理 新建一个 Nginx 代理配置文件,并将代理指向到本地的Ghost端口:\nsudo vim /etc/nginx/conf.d/ghost.conf 先按下 i 键,再将如下内容拷贝到到新文件中。注意将 My-Domain-Name.com 改成你要设置的网址。在编辑完成后,按下 Esc,输入 :wq! 回车退出。\nserver { listen 80; server_name My-Ghost-Blog.com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:2368; } } 重新启动 Nginx 服务器,让设置生效。(这里针对 CentOS 7 使用 sudo /bin/systemctl restart nginx.service)\nsudo service nginx restart PS: 关键的工作都已做完了! 你的博客程序能够跟随操作系统自动运行了。\n但是别忘了修改服务器时区哦。错误的系统时间会导致博客程序显示错误的文章发布日期。\nsudo yum install -y ntp sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime Enjoy!\n","permalink":"https://huifeng.me/posts/mynodejsandghostinstalloncentos7-1-md/","tags":["nodejs"," ghost"," blog"," install"],"title":"My Nodejs And Ghost Install On CentOS7.1"},{"categories":["Tickets"],"contents":"此乃神器也,然,深度使用尚需学习,文分两段:全站下载和常用参数说明\n整站下载(全站下载) wget -r -p -np -k http://xxx.com/abc/ -r, \u0026ndash;recursive(递归) specify recursive download.(指定递归下载) -k, \u0026ndash;convert-links(转换链接) make links in downloaded HTML point to local files.(将下载的HTML页面中的链接转换为相对链接即本地链接) -p, \u0026ndash;page-requisites(页面必需元素) get all images, etc. needed to display HTML page.(下载所有的图片等页面显示所需的内容) -np, \u0026ndash;no-parent(不追溯至父级) don\u0026rsquo;t ascend to the parent directory. 另外断点续传用-nc参数 日志 用-o参数\n熟练掌握wget命令,可以帮助你方便的使用linux。\nwget中文详细使用说明 1)支持断点下传功能(2)同时支持FTP和HTTP下载方式(3)支持代理服务器(4)设置方便简单;5)程序小,完全免费;\n命令格式:\n wget [参数列表] [目标软件、网页的网址]\n1、启动类参数\n 这一类参数主要提供软件的一些基本信息;\n -V,\u0026ndash;version 显示软件版本号然后退出; -h,\u0026ndash;help显示软件帮助信息; -e,\u0026ndash;execute=COMMAND 执行一个 “.wgetrc”命令\n 以上每一个功能有长短两个参数,长短功能一样,都可以使用。需要注意的是,这里的-e参数是执行一个.wgettrc的命令,.wgettrc命令其实是一个参数列表,直接将软件需要的参数写在一起就可以了。\n 2、文件处理参数\n 这类参数定义软件log文件的输出方式等;\n -o,\u0026ndash;output-file=FILE 将软件输出信息保存到文件; -a,\u0026ndash;append-output=FILE将软件输出信息追加到文件; -d,\u0026ndash;debug显示输出信息; -q,\u0026ndash;quiet 不显示输出信息; -i,\u0026ndash;input-file=FILE 从文件中取得URL;\n 以上参数对于攻击者比较有用,我们来看看具体使用;\n例1:下载192.168.1.168首页并且显示下载信息 wget -d http://192.168.1.168\n例2:下载192.168.1.168首页并且不显示任何信息 wget -q http://192.168.1.168\n例3:下载filelist.txt中所包含的链接的所有文件 wget -i filelist.txt\nwget -np -m -l5 http://jpstone.bokee.com //不下载本站所链接的其它站点内容,5级目录结构 3、下载参数\n 下载参数定义下载重复次数、保存文件名等;\n -t,\u0026ndash;tries=NUMBER 是否下载次数(0表示无穷次) -O \u0026ndash;output-document=FILE下载文件保存为别的文件名 -nc, \u0026ndash;no-clobber 不要覆盖已经存在的文件 -N,\u0026ndash;timestamping只下载比本地新的文件 -T,\u0026ndash;timeout=SECONDS 设置超时时间 -Y,\u0026ndash;proxy=on/off 关闭代理\n例:下载192.168.1.168的首页并将下载过程中的的输入信息保存到test.htm文件中 wget -o test.htm http://192.168.1.168\n4、目录参数\n 目录参数主要设置下载文件保存目录与原来文件(服务器文件)的目录对应关系;\n -nd \u0026ndash;no-directories 不建立目录 -x,\u0026ndash;force-directories 强制建立目录 可能现在我们对这里的目录还不是很了解,我们来看一个举例\n例:下载192.168.1.168的首页,并且保持网站结构 wget -x http://192.168.1.168\n 5、HTTP参数\n HTTP参数设置一些与HTTP下载有关的属性;\n \u0026ndash;http-user=USER设置HTTP用户 \u0026ndash;http-passwd=PASS设置HTTP密码 \u0026ndash;proxy-user=USER设置代理用户 \u0026ndash;proxy-passwd=PASS设置代理密码\n 以上参数主要设置HTTP和代理的用户、密码;\n6、递归参数设置\n 在下载一个网站或者网站的一个目录的时候,我们需要知道的下载的层次,这些参数就可以设置; -r,\u0026ndash;recursive 下载整个网站、目录(小心使用) -l,\u0026ndash;level=NUMBER 下载层次\n例:下载整个网站 wget -r http://192.168.1.168\n7、递归允许与拒绝选项参数\n 下载一个网站的时候,为了尽量快,有些文件可以选择下载,比如图片和声音,在这里可以设置;\n -A,\u0026ndash;accept=LIST 可以接受的文件类型 -R,\u0026ndash;reject=LIST拒绝接受的文件类型 -D,\u0026ndash;domains=LIST可以接受的域名 \u0026ndash;exclude-domains=LIST拒绝的域名 -L,\u0026ndash;relative 下载关联链接 \u0026ndash;follow-ftp 只下载FTP链接 -H,\u0026ndash;span-hosts 可以下载外面的主机 -I,\u0026ndash;include-directories=LIST允许的目录 -X,\u0026ndash;exclude-directories=LIST 拒绝的目录\n如何设定wget所使用的代理服务器 wget可以使用用户设置文件\u0026rdquo;.wgetrc\u0026quot;来读取很多设置,我们这里主要利用这个文件来是 设置代理服务器。使用者用什么用户登录,那么什么用户主目录下的\u0026rdquo;.wgetrc\u0026quot;文件就起 作用。例如,\u0026ldquo;root\u0026quot;用户如果想使用\u0026rdquo;.wgetrc\u0026quot;来设置代理服务器,\u0026quot;/root/.wgetrc\u0026quot;就起 作用,下面给出一个\u0026rdquo;.wgetrc\u0026quot;文件的内容,读者可以参照这个例子来编写自己的\u0026quot;wgetrc\u0026quot;文件: http-proxy = 111.111.111.111:8080 ftp-proxy = 111.111.111.111:8080 这两行的含义是,代理服务器IP地址为:111.111.111.111,端口号为:80。第一行指定 HTTP协议所使用的代理服务器,第二行指定FTP协议所使用的代理服务器。\nWGet使用指南 wget是一个从网络上自动下载文件的自由工具。它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理.\n所谓的自动下载是指,wget可以在用户退出系统的之后在后台执行。这意味这你可以登录系统,启动一个wget下载任务,然后退出系统,wget将在后台执行直到任务完成,相对于其它大部分浏览器在下载大量数据时需要用户一直的参与,这省去了极大的麻烦。\nwget可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录结构。这又常被称作”递归下载”。在递归下载的时候,wget遵循Robot Exclusion标准(/robots.txt). wget可以在下载的同时,将链接转换成指向本地文件,以方便离线浏览。\nwget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性.如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完 毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。\nwget的常见用法 wget的使用格式\nUsage: wget [OPTION]\u0026hellip; [URL]\u0026hellip;用wget做站点镜像: wget -r -p -np -k http://dsec.pku.edu.cn/~us...\n或者 wget -m http://www.tldp.org/LDP/ab...在不稳定的网络上下载一个部分下载的文件,以及在空闲时段下载 wget -t 0 -w 31 -c http://dsec.pku.edu.cn/BBC... -o down.log \u0026amp;\n或者从filelist读入要下载的文件列表 wget -t 0 -w 31 -c -B ftp://dsec.pku.edu.cn/linu... -i filelist.txt -o down.log \u0026amp;上面的代码还可以用来在网络比较空闲的时段进行下载。我的用法是:在mozilla中将不方便当时下载的URL链接拷贝到内存中然后粘贴到文件filelist.txt中,在晚上要出去系统前执行上面代码的第二条。\n使用代理下载 wget -Y on -p -k https://sourceforge.net/pr...代理可以在环境变量或wgetrc文件中设定\n在环境变量中设定代理 export PROXY=http://211.90.168.94:8080/\n在~/.wgetrc中设定代理 http_proxy = http://proxy.yoyodyne.com:\u0026hellip; ftp_proxy = http://proxy.yoyodyne.com:\u0026hellip;各种选项分类列表 启动 -V, \u0026ndash;version 显示wget的版本后退出 -h, \u0026ndash;help 打印语法帮助 -b, \u0026ndash;background 启动后转入后台执行 -e, \u0026ndash;execute=COMMAND 执行.wgetrc'格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc记录和输入文件 -o, --output-file=FILE 把记录写到FILE文件中 -a, --append-output=FILE 把记录追加到FILE文件中 -d, --debug 打印调试输出 -q, --quiet 安静模式(没有输出) -v, --verbose 冗长模式(这是缺省设置) -nv, --non-verbose 关掉冗长模式,但不是安静模式 -i, --input-file=FILE 下载在FILE文件中出现的URLs -F, --force-html 把输入文件当作HTML格式文件对待 -B, --base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀 --sslcertfile=FILE 可选客户端证书 --sslcertkey=KEYFILE 可选客户端证书的KEYFILE --egd-file=FILE 指定EGD socket的文件名下载 --bind-address=ADDRESS 指定本地使用地址(主机名或IP,当本地有多个IP或名字时使用) -t, --tries=NUMBER 设定最大尝试链接次数(0 表示无限制). -O --output-document=FILE 把文档写到FILE文件中 -nc, --no-clobber 不要覆盖存在的文件或使用.#前缀 -c, --continue 接着下载没下载完的文件 --progress=TYPE 设定进程条标记 -N, --timestamping 不要重新下载文件除非比本地文件新 -S, --server-response 打印服务器的回应 --spider 不下载任何东西 -T, --timeout=SECONDS 设定响应超时的秒数 -w, --wait=SECONDS 两次尝试之间间隔SECONDS秒 --waitretry=SECONDS 在重新链接之间等待1...SECONDS秒 --random-wait 在下载之间等待0...2*WAIT秒 -Y, --proxy=on/off 打开或关闭代理 -Q, --quota=NUMBER 设置下载的容量限制 --limit-rate=RATE 限定下载输率目录 -nd --no-directories 不创建目录 -x, --force-directories 强制创建目录 -nH, --no-host-directories 不创建主机目录 -P, --directory-prefix=PREFIX 将文件保存到目录 PREFIX/... --cut-dirs=NUMBER 忽略 NUMBER层远程目录HTTP 选项 --http-user=USER 设定HTTP用户名为 USER. --http-passwd=PASS 设定http密码为 PASS. -C, --cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许). -E, --html-extension 将所有text/html文档以.html扩展名保存 --ignore-length 忽略 Content-Length\u0026rsquo;头域 \u0026ndash;header=STRING 在headers中插入字符串 STRING \u0026ndash;proxy-user=USER 设定代理的用户名为 USER \u0026ndash;proxy-passwd=PASS 设定代理的密码为 PASS \u0026ndash;referer=URL 在HTTP请求中包含 Referer: URL'头 -s, --save-headers 保存HTTP头到文件 -U, --user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION. --no-http-keep-alive 关闭 HTTP活动链接 (永远链接). --cookies=off 不使用 cookies. --load-cookies=FILE 在开始会话前从文件 FILE中加载cookie --save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中FTP 选项 -nr, --dont-remove-listing 不移走 .listing\u0026rsquo;文件 -g, \u0026ndash;glob=on/off 打开或关闭文件名的 globbing机制 \u0026ndash;passive-ftp 使用被动传输模式 (缺省值). \u0026ndash;active-ftp 使用主动传输模式 \u0026ndash;retr-symlinks 在递归的时候,将链接指向文件(而不是目录)递归下载 -r, \u0026ndash;recursive 递归下载--慎用! -l, \u0026ndash;level=NUMBER 最大递归深度 (inf 或 0 代表无穷). \u0026ndash;delete-after 在现在完毕后局部删除文件 -k, \u0026ndash;convert-links 转换非相对链接为相对链接 -K, \u0026ndash;backup-converted 在转换文件X之前,将之备份为 X.orig -m, \u0026ndash;mirror 等价于 -r -N -l inf -nr. -p, \u0026ndash;page-requisites 下载显示HTML文件的所有图片递归下载中的包含和不包含(accept/reject) -A, \u0026ndash;accept=LIST 分号分隔的被接受扩展名的列表 -R, \u0026ndash;reject=LIST 分号分隔的不被接受的扩展名的列表 -D, \u0026ndash;domains=LIST 分号分隔的被接受域的列表 \u0026ndash;exclude-domains=LIST 分号分隔的不被接受的域的列表 \u0026ndash;follow-ftp 跟踪HTML文档中的FTP链接 \u0026ndash;follow-tags=LIST 分号分隔的被跟踪的HTML标签的列表 -G, \u0026ndash;ignore-tags=LIST 分号分隔的被忽略的HTML标签的列表 -H, \u0026ndash;span-hosts 当递归时转到外部主机 -L, \u0026ndash;relative 仅仅跟踪相对链接 -I, \u0026ndash;include-directories=LIST 允许目录的列表 -X, \u0026ndash;exclude-directories=LIST 不被包含目录的列表 -np, \u0026ndash;no-parent 不要追溯到父目录\nWget使用技巧 wget的使用形式是: wget [参数列表] URL 首先来介绍一下wget的主要参数: · -b:让wget在后台运行,记录文件写在当前目录下\u0026quot;wget-log\u0026quot;文件中; · -t [nuber of times]:尝试次数,当wget无法与服务器建立连接时,尝试连接多少次 。比如\u0026rdquo;-t 120\u0026quot;表示尝试120次。当这一项为\u0026quot;0\u0026quot;的时候,指定尝试无穷多次直到连接成功为止,这个 设置非常有用,当对方服务器突然关机或者网络突然中断的时候,可以在恢复正常后继续 下载没有传完的文件; · -c:断点续传,这也是个非常有用的设置,特别当下载比较大的文件的时候,如果中 途意外中断,那么连接恢复的时候会从上次没传完的地方接着传,而不是又从头开始,使 用这一项需要远程服务器也支持断点续传,一般来讲,基于UNIX/Linux的Web/FTP服务器 都支持断点续传; · -T [number of seconds]:超时时间,指定多长时间远程服务器没有响应就中断连接 ,开始下一次尝试。比如\u0026rdquo;-T 120\u0026quot;表示如果120秒以后远程服务器没有发过来数据,就重新尝试连接。如果网络速度比 较快,这个时间可以设置的短些,相反,可以设置的长一些,一般最多不超过900,通常 也不少于60,一般设置在120左右比较合适; · -w [number of seconds]:在两次尝试之间等待多少秒,比如\u0026rdquo;-w 100\u0026quot;表示两次尝试 之间等待100秒; · -Y on/off:通过/不通过代理服务器进行连接; · -Q [byetes]:限制下载文件的总大小最多不能超过多少,比如\u0026rdquo;-Q2k\u0026quot;表示不能超过2K 字节,\u0026quot;-Q3m\u0026quot;表示最多不能超过3M字节,如果数字后面什么都不加,就表示是以字节为单 位,比如\u0026rdquo;-Q200\u0026quot;表示最多不能超过200字节; · -nd:不下载目录结构,把从服务器所有指定目录下载的文件都堆到当前目录里; · -x:与\u0026rdquo;-nd\u0026quot;设置刚好相反,创建完整的目录结构,例如\u0026quot;wget -nd http://www.gnu.org\u0026quot;将创建在当前目录下创建\u0026quot;www.gnu.org\u0026quot;子目录,然后按照服务器 实际的目录结构一级一级建下去,直到所有的文件都传完为止; · -nH:不创建以目标主机域名为目录名的目录,将目标主机的目录结构直接下到当前目 录下; · \u0026ndash;http-user=username · \u0026ndash;http-passwd=password:如果Web服务器需要指定用户名和口令,用这两项来设定; · \u0026ndash;proxy-user=username · \u0026ndash;proxy-passwd=password:如果代理服务器需要输入用户名和口令,使用这两个选项 ; · -r:在本机建立服务器端目录结构; · -l [depth]:下载远程服务器目录结构的深度,例如\u0026rdquo;-l 5\u0026quot;下载目录深度小于或者等 于5以内的目录结构或者文件; · -m:做站点镜像时的选项,如果你想做一个站点的镜像,使用这个选项,它将自动设 定其他合适的选项以便于站点镜像; · -np:只下载目标站点指定目录及其子目录的内容。这也是一个非常有用的选项,我们 假设某个人的个人主页里面有一个指向这个站点其他人个人主页的连接,而我们只想下载 这个人的个人主页,如果不设置这个选项,甚至\u0026ndash;有可能把整个站点给抓下来,这显然是 我们通常不希望的; ü 如何设定wget所使用的代理服务器 wget可以使用用户设置文件\u0026rdquo;.wgetrc\u0026quot;来读取很多设置,我们这里主要利用这个文件来是 设置代理服务器。使用者用什么用户登录,那么什么用户主目录下的\u0026rdquo;.wgetrc\u0026quot;文件就起 作用。例如,\u0026ldquo;root\u0026quot;用户如果想使用\u0026rdquo;.wgetrc\u0026quot;来设置代理服务器,\u0026quot;/root/.wgert\u0026quot;就起 作用,下面给出一个\u0026rdquo;.wge trc\u0026quot;文件的内容,读者可以参照这个例子来编写自己的\u0026quot;wgetrc\u0026quot;文件: http-proxy = 111.111.111.111:8080 ftp-proxy = 111.111.111.111:8080 这两行的含义是,代理服务器IP地址为:111.111.111.111,端口号为:80。第一行指定 HTTP协议所使用的代理服务器,第二行指定FTP协议所使用的代理服务器。\nwget 使用实例: wget是一个命令行工具,用于批量下载文件,支持HTTP和FTP。究竟比其他的工具好在哪里?看看内容吧 :)\nwget基本上所有的Linux版本都自己带了,但是有多少人在用呢?呵呵,如果你没有用过,不妨试试。Windows下面的用户可以使用GNUwin32的项目,wget,基本功能完全一致。好吧,我们来以几个简单的例子看看wget的威力。\n如果我们想下载ftp里面某个目录里面的所有文件,我们也可以不用ftp这个笨蛋,呵呵,可以享受cute ftp等图形化工具的拖一个目录的轻松了。如\nwget -r ftp://10.8.8.8/movie/\n呵呵,等吧!下完了,发觉有些不对劲,怎么出来个10.8.8.8的目录,进去看看,又是一个movie,哦,wget将目录结构和网站标题都给记录下来了,不要??没有问题!比如说还是这个例子\nwget -r -nd ftp://10.8.8.8/movie/\n结果什么目录都没有了,faint!怎么会这样?呵呵,你如果想要这样就让它这样吧,否则使用\nwget -r -nH ftp://10.8.8.8/movie/\n恩?movie也不要?OK,那就这样\nwget -r -nH \u0026ndash;cut-dirs=1 ftp://10.8.8.8/movie/\n这有什么用啊?cuteftp比他好用多了,而且,你这断了线能连吗?呵呵,不好意思,可以连\nwget -c -r -nH \u0026ndash;cut-dirs=1 ftp://10.8.8.8/movie/\n但是cuteftp能做下面的事情吗?比如,现在很多网站使用Apache建站,并不提供ftp服务,但是Apache有一个indexing功能,可以提供一个类似于ftp的界面,好多文件我想下啊,怎么办?由于是HTTP协议,CuteFTP无能为力了,倒是flash get等有什么get all这种功能,不知道他们对于目录处理怎么样。但是wget一点问题都没有,不信?我们拿CTAN为例(例子并不恰当,CTAN有FTP服务),我们下载这里面所有的宏包,呵呵\nwget -r -k http://www.txia.com/blog\n-k表示将连接转换为本地连接。但是现在同样有上面的问题啊,那就把你需要的加上吧,另外也许你根本不需要向下走那么多层,比如,我们就要到第二层,那么\nwget -r -l2 -k http://www.txia.com/blog\n现在新的问题是,由于网页有一个排序功能,很讨厌,因为下载的时候把网页重复了好多次,那么我们可使用-A和-R开关控制下载类型,并且可以使用通配符,呵呵,现在随心所欲了吧\nwget -r -R \u0026lsquo;.htm?*\u0026rsquo; -k http://www.txia.com/blog\n这次没有那种网页了吧?-R的意义在于拒绝下载匹配类型的文件,-A表示仅仅接受的文件类型,如-A \u0026lsquo;*.gif\u0026rsquo;将仅下载gif图片,如果有多个允许或者不允许,可以使用,分开。\n那么,我们现在在使用代理服务器,怎么办呢?呵呵,很高兴你选择了wget,你可以使用它的配置文件,环境变量来利用代理。这里推荐使用环境变量,如在 bash里面我们可以把天天用的proxy加到.bash_profile里面,这是Linux标准写法(很多软件都用的,什么apt-get,yum等等)\nexport http_proxy=http://10.20.30.40:8080\n然后,proxy就默认打开了,如果需要暂时关闭,可以使用\nwget \u0026ndash;proxy=off -r -k http://www.txia.com/blog\n当然,写一个.wgetrc文件也可以,该文件可以从/usr/local/etc里面找到,里面有很详细的注释,我就不多说了。\n下载网页的时候比较麻烦的事情是,有的网页被同时指向了很多遍,那么为了避免多次下载,我们使用\nwget -nc -r -k http://www.txia.com/blog\n可以避免这件事情。为了不被有的连接指向非http://www.txia.com/blog内层目录,我们还应该加上\nwget -nc -np -r -k http://www.txia.com/blog\n避免下载非该目录里面的文件,这也避免了到不同的host上面去。当然,如果你希望有这个功能,在多个host之间跳来跳去的下载,可以使用\nwget -nc -np -H -r -k http://www.txia.com/blog\n使得可以在多个host之间span,同时-I和-X可以使得我们仅仅跟踪某些目录或者不跟踪某些目录。如果某些HTML里面你需要的东西不是由这种东西作出来的,你就得使用\u0026ndash;follow-tags和\u0026ndash;ignore-tags了。\n嘿,我有个文件里面都是连接,怎么办?要是不是html你只需要\nwget -i your.file\n如果是,那也不繁\nwget -F -i your.file\nwget 使用指南 wget是一个从网络上自动下载文件的自由工具。它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理.\n所谓的自动下载是指,wget可以在用户退出系统的之后在后台执行。这意味这你可以登录系统,启动一个wget下载任务,然后退出系统,wget将在后台执行直到任务完成,相对于其它大部分浏览器在下载大量数据时需要用户一直的参与,这省去了极大的麻烦。\nwget可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录结构。这又常被称作\u0026quot;递归下载\u0026rdquo;。在递归下载的时候,wget遵循Robot Exclusion标准(/robots.txt). wget可以在下载的同时,将链接转换成指向本地文件,以方便离线浏览。\nwget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性.如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。\nwget的常见用法 wget的使用格式\nUsage: wget [OPTION]\u0026hellip; [URL]\u0026hellip;\n用wget做站点镜像: wget -r -p -np -k http://dsec.pku.edu.cn/~us... -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参数,因为如果你要下载的网站也有别的网站的链接,wget也会把别的网站的东西下载下来,所以要加上 -np这个参数,表示不下载别的站点的链接. -k表示将下载的网页里的链接修改为本地链接.-p获得所有显示网页所需的元素,比如图片什么的.\n或者 wget -m http://www.tldp.org/LDP/ab...\n在不稳定的网络上下载一个部分下载的文件,以及在空闲时段下载 wget -t 0 -w 31 -c http://dsec.pku.edu.cn/BBC... -o down.log \u0026amp;\n或者从filelist读入要下载的文件列表 wget -t 0 -w 31 -c -B ftp://dsec.pku.edu.cn/linu... -i filelist.txt -o down.log \u0026amp;\n上面的代码还可以用来在网络比较空闲的时段进行下载。我的用法是:在mozilla中将不方便当时下载的URL链接拷贝到内存中然后粘贴到文件filelist.txt中,在晚上要出去系统前执行上面代码的第二条。\n使用代理下载 wget -Y on -p -k https://sourceforge.net/pr...\n代理可以在环境变量或wgetrc文件中设定\n在环境变量中设定代理 export PROXY=http://211.90.168.94:8080/\n在~/.wgetrc中设定代理 http_proxy = http://proxy.yoyodyne.com:\u0026hellip; ftp_proxy = http://proxy.yoyodyne.com:\u0026hellip;\nwget各种选项分类列表 启动 -V, \u0026ndash;version 显示wget的版本后退出 -h, \u0026ndash;help 打印语法帮助 -b, \u0026ndash;background 启动后转入后台执行 -e, \u0026ndash;execute=COMMAND 执行`.wgetrc\u0026rsquo;格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc\n记录和输入文件 -o, \u0026ndash;output-file=FILE 把记录写到FILE文件中 -a, \u0026ndash;append-output=FILE 把记录追加到FILE文件中 -d, \u0026ndash;debug 打印调试输出 -q, \u0026ndash;quiet 安静模式(没有输出) -v, \u0026ndash;verbose 冗长模式(这是缺省设置) -nv, \u0026ndash;non-verbose 关掉冗长模式,但不是安静模式 -i, \u0026ndash;input-file=FILE 下载在FILE文件中出现的URLs -F, \u0026ndash;force-html 把输入文件当作HTML格式文件对待 -B, \u0026ndash;base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀 \u0026ndash;sslcertfile=FILE 可选客户端证书 \u0026ndash;sslcertkey=KEYFILE 可选客户端证书的KEYFILE \u0026ndash;egd-file=FILE 指定EGD socket的文件名\n下载 \u0026ndash;bind-address=ADDRESS 指定本地使用地址(主机名或IP,当本地有多个IP或名字时使用) -t, \u0026ndash;tries=NUMBER 设定最大尝试链接次数(0 表示无限制). -O \u0026ndash;output-document=FILE 把文档写到FILE文件中 -nc, \u0026ndash;no-clobber 不要覆盖存在的文件或使用.#前缀 -c, \u0026ndash;continue 接着下载没下载完的文件 \u0026ndash;progress=TYPE 设定进程条标记 -N, \u0026ndash;timestamping 不要重新下载文件除非比本地文件新 -S, \u0026ndash;server-response 打印服务器的回应 \u0026ndash;spider 不下载任何东西 -T, \u0026ndash;timeout=SECONDS 设定响应超时的秒数 -w, \u0026ndash;wait=SECONDS 两次尝试之间间隔SECONDS秒 \u0026ndash;waitretry=SECONDS 在重新链接之间等待1\u0026hellip;SECONDS秒 \u0026ndash;random-wait 在下载之间等待0\u0026hellip;2*WAIT秒 -Y, \u0026ndash;proxy=on/off 打开或关闭代理 -Q, \u0026ndash;quota=NUMBER 设置下载的容量限制 \u0026ndash;limit-rate=RATE 限定下载输率\n目录 -nd \u0026ndash;no-directories 不创建目录 -x, \u0026ndash;force-directories 强制创建目录 -nH, \u0026ndash;no-host-directories 不创建主机目录 -P, \u0026ndash;directory-prefix=PREFIX 将文件保存到目录 PREFIX/\u0026hellip; \u0026ndash;cut-dirs=NUMBER 忽略 NUMBER层远程目录\nHTTP 选项 \u0026ndash;http-user=USER 设定HTTP用户名为 USER. \u0026ndash;http-passwd=PASS 设定http密码为 PASS. -C, \u0026ndash;cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许). -E, \u0026ndash;html-extension 将所有text/html文档以.html扩展名保存 \u0026ndash;ignore-length 忽略 Content-Length'头域 --header=STRING 在headers中插入字符串 STRING --proxy-user=USER 设定代理的用户名为 USER --proxy-passwd=PASS 设定代理的密码为 PASS --referer=URL 在HTTP请求中包含 Referer: URL\u0026rsquo;头 -s, \u0026ndash;save-headers 保存HTTP头到文件 -U, \u0026ndash;user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION. \u0026ndash;no-http-keep-alive 关闭 HTTP活动链接 (永远链接). \u0026ndash;cookies=off 不使用 cookies. \u0026ndash;load-cookies=FILE 在开始会话前从文件 FILE中加载cookie \u0026ndash;save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中\nFTP 选项 -nr, \u0026ndash;dont-remove-listing 不移走 `.listing\u0026rsquo;文件 -g, \u0026ndash;glob=on/off 打开或关闭文件名的 globbing机制 \u0026ndash;passive-ftp 使用被动传输模式 (缺省值). \u0026ndash;active-ftp 使用主动传输模式 \u0026ndash;retr-symlinks 在递归的时候,将链接指向文件(而不是目录)\n递归下载 -r, \u0026ndash;recursive 递归下载--慎用! -l, \u0026ndash;level=NUMBER 最大递归深度 (inf 或 0 代表无穷). \u0026ndash;delete-after 在现在完毕后局部删除文件 -k, \u0026ndash;convert-links 转换非相对链接为相对链接 -K, \u0026ndash;backup-converted 在转换文件X之前,将之备份为 X.orig -m, \u0026ndash;mirror 等价于 -r -N -l inf -nr. -p, \u0026ndash;page-requisites 下载显示HTML文件的所有图片\n递归下载中的包含和不包含(accept/reject) -A, \u0026ndash;accept=LIST 分号分隔的被接受扩展名的列表 -R, \u0026ndash;reject=LIST 分号分隔的不被接受的扩展名的列表 -D, \u0026ndash;domains=LIST 分号分隔的被接受域的列表 \u0026ndash;exclude-domains=LIST 分号分隔的不被接受的域的列表 \u0026ndash;follow-ftp 跟踪HTML文档中的FTP链接 \u0026ndash;follow-tags=LIST 分号分隔的被跟踪的HTML标签的列表 -G, \u0026ndash;ignore-tags=LIST 分号分隔的被忽略的HTML标签的列表 -H, \u0026ndash;span-hosts 当递归时转到外部主机 -L, \u0026ndash;relative 仅仅跟踪相对链接 -I, \u0026ndash;include-directories=LIST 允许目录的列表 -X, \u0026ndash;exclude-directories=LIST 不被包含目录的列表 -np, \u0026ndash;no-parent 不要追溯到父目录\n问题 在递归下载的时候,遇到目录中有中文的时候,wget创建的本地目录名会用URL编码规则处理。如\u0026quot;天网防火墙\u0026quot;会被存为\u0026rdquo;%CC%EC%CD%F8%B7%C0%BB%F0%C7%BD\u0026rdquo;,这造成阅读上的极大不方便。\n","permalink":"https://huifeng.me/posts/utilities-wget/","tags":["wget"," 参数"," 文档"],"title":"神器wget的使用方法"},{"categories":["Laravel"],"contents":"这里记录下我使用 vagrant 来做开发环境的各种经验,本文主要讲通过 homestead 命令行来控制虚拟机。 之前我用 vagrant 搭建了自己的方便移动的开发和生产环境,用过 CentOS-6.5 CentOS-7.0 CentOS-7.1,最终我回到了官方提供的开发环境:laravel/homestead,为什么要绕一圈,为什么绕了一圈又回来了呢?\n故事背景 曾经用绿色的 amp 环境包来部署各类应用,然后各种慢和不稳定,慢是必然的,稳定性的影响主要来自于宿主计算机,当时部署给别人一个自己做好的站点,不到一个月,打不开了,查明原因是因为毒,没错,是因为毒,毒把网站搞坏了,把 mysql 的服务也搞坏了,虽然最终是搞定了,但是这个过程让我意识到一个问题,再有类似的事情,我要给他们配个虚拟机!也就是那个时候,我接触了 laravel,学习的过程中又遇到了 vagrant,顿时觉得这真是神器,当时本来试图用官方提供的 homestead 环境的,但是遇到了一些问题,第一,该环境配好后要配置环境变量,我确实按照文档配置了,但是不起作用,当时也懒得考虑为什么,我总是对 Ubuntu 有成见。第二,当我用它操作了半天,发现怎么修改和配置,它都只能针对homestead这个数据库操作,我创建新的数据库用来连不上,不明白是什么原因,反正我是放弃了。 事隔半年,我又燃起了要搞定homestead的愿望,原因是每次自己搞个 lnmp 环境出来总还是会遇到一些其他的问题,问题解决了又有新问题,我感觉自己把时间大量的花费在了环境上,我不想这样,我想把更多的时间放在 laravel 上,我得把环境配置上的时间节省下来,干脆就用官方的环境吧!因此,我重新阅览官方文档,重新的意思包括把5.1版本的文档翻译了一下,翻译过后确实对很多细节更了解了,也意识到当时可能遇到但是没解决的问题。啰嗦了太多了,下面上干货:\n准备工作 你的电脑应该已经具备如下环境:Composer, git, php(可选)\n你的电脑最好是能够畅游互联网,可以访问 github.com。\n安装 新版 vagrant 用这个命令:\nvagrant box add laravel/homestead 老版 vagrant 用这个:\nvagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead 本土局域网用户也许会在安装中遇到下载失败的问题,请科学上网,或用下载工具下载吧,我是用 wget 下载下来安装的,写此文时,homestead 版本还是 0.2.7,本来想上传到百度云的,但是 Urumqi 的百度网盘有问题。\n分支1:vagrant 命令行管理虚拟机 如果你本地没有 PHP 环境,可以选择这个分支。 克隆 Homestead 代码库,你可以在用户根目录(~)下运行下面的命令,这样会在~/Homestead目录下克隆:\ngit clone https://github.com/laravel/homestead.git Homestead 初始化,可以实现在~/.homestead目录下创建配置文件Homestead.yaml:\nbash init.sh 此时,你已经可以在~/Homestead 目录下,用vagrant up命令来启动虚拟机了,虚拟机的目录等配置后面说。\n分支2:homestead 命令行管理虚拟机 如果你本地有 PHP 环境,建议选择这个分支。 为了实现 http://laracasts.com 里那样的操作,我们需要安装 homestead 的命令行。\ncomposer global require \u0026quot;laravel/homestead=~2.0\u0026quot; 完后,你的~/.composer/vendor/bin目录下应该是具备了homestead文件,该文件具有执行权限。\n添加环境变量(可能成为你的绊脚石) 下面修改环境变量,将~/.composer/vendor/bin写入 PATH 环境变量里。\n注意: 如果你的命令行安装了zsh和oh-my-zsh,修改环境变量时有些小的变化。\n我遇到的就是这个问题,怎么修改,环境变量都不生效,比如我修改的是~/.bash_profile,那么必须source ~/.bash_profile才能生效,而且重启后继续无效,为什么呢?因为 zsh !我的终端是 iTerm2,它很炫酷,但是就是环境变量搞不成。Google 找到了问题所在,安装 zsh 后,~/.bash_profile并没有被执行,所以需要编辑 zsh 的配置文件~/.zshrc,在该文件里加入\nsource ~/.bash_profile 现在我们应该可以用homestead命令了,可以看到 homestead 包含了一些 vagrant 的功能,下面初始化:\nhomestead init 此时应会在~/.homestead/下创建配置文件Homestead.yaml,如果该文件已经存在会问你是否覆盖。如果想编辑配置文件就输入homestead edit。\n使用 不管你是分支1还是分支2,下面的操作都是一样的。 配置~/.homestead/Homestead.yaml:\n目录映射 说明:\nfolders: - map: 本地目录 to: 虚拟机上的目录 我的配置:\nfolders: - map: ~/Sites to: /home/vagrant/Code 虚拟目录 说明:\nsites: - map: 域名,自己的 hosts 文件里已经定义了的。 alias: 别名,也是 hosts 文件里已经定义了的。 to: 虚拟主机里的目录,一般这个目录是通过目录映射映射好了的。 我的配置:\nsites: - map: pma.local to: /home/vagrant/Code/phpMyAdmin - map: test.local to: /home/vagrant/Code/test - map: hfcms.local to: /home/vagrant/Code/hfcms/public - map: flyer.dev to: /home/vagrant/Code/flyer.dev/public 新增或修改虚拟目录配置 方式一:修改完Homestead.yaml后,务必运行下面命令以使配置生效: 有 php 环境,成功配置好了 homestead 环境的。 homestead provision 无 php 环境,未成功配置 homestead 环境的。 vagrant provision 方式二:通过 SSH 直接登录到虚拟机里面,然后运行: serve domain.app /home/vagrant/Code/path/to/public/directory 就会添加一个域名为domain.app, 目录在/home/vagrant/Code/path/to/public/directory的虚拟目录。\n","permalink":"https://huifeng.me/posts/laravel-homestead-note/","tags":["laravel"," homestead"," vagrant"," 开发环境"],"title":"laravel-homestead 开发环境使用"},{"categories":["Editor"],"contents":"这个编辑器的打开速度是我喜欢的,它的自定义性又很强,经历bracket,atom等各种编辑器后,最后由laracastes.com再次将我带入Sublime text3的世界。下面,我主要介绍下中文输入法和laracastes.com里说的各种技巧。当然前提还是:你得学会在中国上互联网,代理或VPN都行。 下面进入正题.\n用正确的姿势输入中文 用惯了windows的朋友一定要适应,在linxu和苹果系统里,我们更多的时候用命令行来打开编辑器更方便,这个是真的,如果能理解这个,拿你就可以接受在Ubuntu系统下中文输入的蹩脚的地方了:只能从命令行用subl来启动的Sublime Text3才能输入中文,具体原因请看原作者解释,我这里提供的方法相比还是比较简单的,两台Ubuntu系统测试通过,没有问题。\n输入法安装 网址:https://github.com/lyfeyaj/sublime-text-imfix\n命令流程:\n## 更新系统 sudo apt-get update \u0026amp;\u0026amp; sudo apt-get upgrade ## 克隆项目到本地 git clone https://github.com/lyfeyaj/sublime-text-imfix.git ## 运行脚本:进入克隆的目录,然后运行作者写好的脚本 cd sublime-text-imfix \u0026amp;\u0026amp; ./sublime-imfix ##试试看是否可以输入中文了 subl 我遇到的问题 刚开始,按照作者的做法做了,然并卵!所以找问题,发现我没有装sogou输入法,我用的是google输入法,所以又装了下sogou输入法,运行如下命令居然安装了48M左右的东西,估计问题出在这里了:\ngcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC 当然,此时我没有测试是否能正常输入中文,接着,我添加ppa:fcitx-team/nightly,到软件源,然后更新了下,再然后,我安装了sogou输入法的deb包,过程中又下载安装了什么包,之后,一切就好了。\n推荐安装的插件 慢慢整理,总共10个课时,ubuntu都行,视频在这里,laracasts.com.\n 先安装插件 PackageResourceViewer,然后安装好下面的皮肤后Ctrl+Shift+p运行PackageResourceViewer:Extract Package命令,选择相应的皮肤。\n皮肤选择: Material Theme for Sublime Text 3 GitHub项目主页 配色风格选择插件:Colorsublime GitHub项目主页 Colorsublime配色选择:facebook 上面的都安装完后:打开 Settings-User,添加配色和皮肤选项设定:\n\u0026#34;theme\u0026#34;: \u0026#34;Material-Theme-DIY.sublime-theme\u0026#34;, \u0026#34;color_scheme\u0026#34;: \u0026#34;Packages/Colorsublime - Themes/Facebook.tmTheme\u0026#34;, 然后设定字体和大小是否显示行号等设置:\n\u0026#34;font_size\u0026#34;: 15, \u0026#34;font_face\u0026#34;: \u0026#34;Fira Code\u0026#34;, \u0026#34;line_numbers\u0026#34;: false, \u0026#34;margin\u0026#34;: 0, \u0026#34;overlay_scroll_bars\u0026#34;\t: \u0026#34;enabled\u0026#34;, \u0026#34;line_padding_top\u0026#34;\t: 3, \u0026#34;line_padding_bottom\u0026#34;\t: 3, \u0026#34;always_show_minimap_viewport\u0026#34; : false, \u0026#34;bold_folder_labels\u0026#34; : true, // Highlight active indent \u0026#34;indent_guide_options\u0026#34; : [ \u0026#34;draw_normal\u0026#34;, \u0026#34;draw_active\u0026#34; ], \u0026#34;font_options\u0026#34; : [ \u0026#34;gray_antialias\u0026#34; ], \u0026#34;use_simple_full_screen\u0026#34;: true, 这里会用到字体:Fira Code\n上面都设置完毕后,我们进入目录:/home/SignedUser/.Sublime Text 3/Packages/Material Theme,复制一份Material-Theme.sublime-theme,重命名为:Material-Theme-DIY.sublime-theme,打开重命名后的文件,修改颜色,将所有的38, 50, 56色值修改为:37, 43, 57。保存文件。\n已安装插件: MarkdownEditing\n 非常棒的markdown编辑辅助插件,快捷键如下:\n OS X Windows/Linux Description ⌘⌥V CtrlWinV 粘贴剪贴板中的内容作为选择的文本内嵌的链接。 ⌘⌥R CtrlWinR 粘贴剪贴板作为参考链接的内容。 ⌘⌥K CtrlWinK 插入一个标准的内嵌链接。 ⌘⇧K ShiftWinK 插入内嵌图像。 ⌘⌥B ⌘⌥I CtrlShiftB CtrlShiftI These are bound to bold and italic. They work both with and without selections. If there is no selection, they will just transform the word under the cursor. These keybindings will unbold/unitalicize selection if it is already bold/italic. ⌘^1\u0026hellip;6 Ctrl1\u0026hellip;6 These will add the corresponding number of hashmarks for headlines. Works on blank lines and selected text in tandem with the above headline tools. If you select an entire existing headline, the current hashmarks will be removed and replaced with the header level you requested. This command respects the mde.match_header_hashes preference setting. ⌘⇧6 CtrlShift6 插入一个脚注,并跳转到它的定义。如果你的光标在一个定义,它会跳回标记。 ⌥⇧F AltShiftF 定位到没有定义的脚注标记并插入其标记的定义。 ⌥⇧G AltShiftG 定位链接引用未经定义和插入其标签在底部的定义。 AdvancedNewFile\n 快速新建和重命名文件!非常好用,⌘+alt+n或 windows+ctrl+n就可以新建文件。\n Sublime-phpfmt\n 格式化代码\n OmniMarkupPreviewer\n 我用的最好用的 markdown 预览,真的很好用,实时预览,浏览器和你编辑的内容是同步的,按:⌘+⌥+O(是 O,不是0)即可在浏览器预览你的 markdown 样式效果。\n PHP Getters and Setter\n 快速生成 get 和 set 魔术方法\n SublimePHPCompanion\n 一键补全或引入命名空间,一键添加属性和构造方法\n Origami\n 快捷分屏\n Colorsublime\n install themes功能,方便直接看到着色效果 可以先在它的网站上找到合适的:http://colorsublime.com\n Better PHP Workflow 这一节安装的插件有: PHP Getters and Setter\nSublimePHPCompanion\n添加 snippet 菜单栏:Tools-\u0026gt;New Snippet\u0026hellip;\n我保存了这样几个:\n 使用:输入pmet(met 是 method 的缩写),然后按 Tab 代码如下:\n\u0026lt;snippet\u0026gt; \u0026lt;content\u0026gt;\u0026lt;![CDATA[ protected function ${1}(${2}) { ${3} } ]]\u0026gt;\u0026lt;/content\u0026gt; \u0026lt;!-- Optional: Set a tabTrigger to define how to trigger the snippet --\u0026gt; \u0026lt;tabTrigger\u0026gt;pmet\u0026lt;/tabTrigger\u0026gt; \u0026lt;!-- Optional: Set a scope to limit where the snippet will trigger --\u0026gt; \u0026lt;scope\u0026gt;source.php\u0026lt;/scope\u0026gt; \u0026lt;/snippet\u0026gt; 使用:输入met,然后按 Tab 代码如下:\n\u0026lt;snippet\u0026gt; \u0026lt;content\u0026gt;\u0026lt;![CDATA[ public function ${1}(${2}) { ${3} } ]]\u0026gt;\u0026lt;/content\u0026gt; \u0026lt;!-- Optional: Set a tabTrigger to define how to trigger the snippet --\u0026gt; \u0026lt;tabTrigger\u0026gt;met\u0026lt;/tabTrigger\u0026gt; \u0026lt;!-- Optional: Set a scope to limit where the snippet will trigger --\u0026gt; \u0026lt;scope\u0026gt;source.php\u0026lt;/scope\u0026gt; \u0026lt;/snippet\u0026gt; 使用:输入_c,然后按 Tab 代码如下:\n\u0026lt;snippet\u0026gt; \u0026lt;content\u0026gt;\u0026lt;![CDATA[ public function __construct(${1}) { ${2} } ]]\u0026gt;\u0026lt;/content\u0026gt; \u0026lt;!-- Optional: Set a tabTrigger to define how to trigger the snippet --\u0026gt; \u0026lt;tabTrigger\u0026gt;_c\u0026lt;/tabTrigger\u0026gt; \u0026lt;!-- Optional: Set a scope to limit where the snippet will trigger --\u0026gt; \u0026lt;scope\u0026gt;source.php\u0026lt;/scope\u0026gt; \u0026lt;/snippet\u0026gt;\t 插件PHP Getters and Setter 这个插件的用法是:command+shift+p,输入php get就能找到相应的功能了,能够实现直接生成指定的或全部的 get 和 set 魔术方法。\n插件SublimePHPCompanion 这个插件很犀利,按一个键即可不全命名空间,或者添加命名空间引用,而定义了insert_php_constructor_property的快键后更牛,可以实现一键创建属性名称,同时构造方法封装.\n针对这个插件,我的Key Bindings-User 配置,F7一键创建属性,F9一键不全命名空间,F10一键引入光标所在关键字的命名空间:\n{ \u0026quot;keys\u0026quot;: [\u0026quot;f9\u0026quot;], \u0026quot;command\u0026quot;: \u0026quot;expand_fqcn\u0026quot; }, { \u0026quot;keys\u0026quot;: [\u0026quot;f10\u0026quot;], \u0026quot;command\u0026quot;: \u0026quot;find_use\u0026quot; }, { \u0026quot;keys\u0026quot;: [\u0026quot;f7\u0026quot;], \u0026quot;command\u0026quot;: \u0026quot;insert_php_constructor_property\u0026quot; }, 默认的一键创建属性创建的都是private的,我想改为默认是protected,打开该插件的默认配置文件可以看到最后一行是\u0026quot;visibility\u0026quot;: \u0026quot;private\u0026quot;,这时,我们复制这一行,在 PHPCompanion 插件的 User 配置文件里添加{}然后将\u0026quot;visibility\u0026quot;: \u0026quot;private\u0026quot;拷贝进去,并修改private为protected。\nOK,至此,操作完毕。\n","permalink":"https://huifeng.me/posts/sublime-text3-mastery/","tags":["sublime"," 编辑器"," 中文输入"," 插件"],"title":"Sublime-text3使用经验"},{"categories":["FrontEnd"],"contents":"这东西很不错,可以让浏览器和我们的文件同步显示,意思是,你一修改完 css 或者 js 或者 Html,立即就能看到浏览器里他们的变化。 You\u0026rsquo;re worth it!\n官方网站:http://www.browsersync.io\n安装 npm install -g browser-sync 国内玩家,如果速度太慢,可以先安装 cnpm, 然后:\ncnpm install -g browser-sync 当然,过程中还会用到 github 所以最好还是有 VPN 或 shadowsocks 配合 proxychains-ng\n安装成功后,运行browser-sync命令可以出现帮助和说明,说明安装成功了,想要在那个项目里使用就先到那个目录下,然后运行:\nnpm init npm install browser-sync --save-dev --save-dev 参数用来将 browser-sync 作为开发依赖放到package.json 里去。\n使用 这里以宁皓网的 github 上的 forest 为用例代码:\ngit clone https://github.com/ninghao/forest 启动服务 # --server 表示要启动一个服务器,后面跟的是要启动的服务所在根目录,不指定会是命令当先位置 # --files 指定要监视的文件,比如监视了 index.html 和 css 文件夹里的 css 文件 browser-sync start --server forest --files \u0026#34;forest/index.html, forest/css/*.css\u0026#34; 成功后,会自动打开浏览器,管理 browser-sync 在 http://localhost:3001\n其他参数 --tunnel:与所有人同步 就是说,你的修改可以公布给网上的人,有地址,让他们都可以看到,地址是随机生成的。\n--proxy:代理 这个功能很有用,我们一般开发的 php 动态的网站有依赖的一些环境,有了这个代理就方便了,比如,我们的测试地址是:http://test.dev那么我们就这么写这个参数:\n--proxy test.dev 然后访问http://localhost:3000即可\n把 browser-sync 作为 Gulp 的任务 安装 gulp :npm install gulp --save-dev\n在forest目录的上级目录下添加一个 gulp 文件gulpfile.js:\nvar gulp = require(\u0026#39;gulp\u0026#39;); var browserSync = require(\u0026#39;browser-sync\u0026#39;).create(); gulp.task(\u0026#39;browser-sync\u0026#39;, function () { browserSync.init({ server:{ baseDir: \u0026#39;./forest\u0026#39; }, files: [\u0026#39;forest/index.html\u0026#39;, \u0026#39;forest/css/*.css\u0026#39;] }); }); 安装 gulp 的命令行工具:npm install -g gulp\n执行任务:gulp browser-sync。\n 如果报错说Cannot find module 'browser-sync',对应的代码行是var browserSync = require('browser-sync').create(); 请再次运行并保证成功:npm install gulp --save-dev然后再执行刚才的任务\n","permalink":"https://huifeng.me/posts/ninghao-browser-sync-01/","tags":["宁皓网"," 浏览器"," 同步"," Browser"," sync"],"title":"跟着宁皓网学 Browser-sync"},{"categories":["FrontEnd"],"contents":"至于 SemanticUI 也做过一些调研,最后还是选择了它,最重要的原因是想跟着宁皓学学看,我想,任何界面框架,学好了都能做很多事情,有人说,semantic 太大,那么,你学好它,只 build 你需要的功能,它应该就满足你的需要了吧,而且,这个也许还不是我们页面的瓶颈。\n基础环境 npm 、nodejs 和 glup 是必备的,安装过程,洋文不好的请访问 http://cnodejs.org\nnpm 默认安装版本不是3的,可以通过命令来升级到3:npm install -g npm@3\n当我们的基本环境 OK 后,还要确定一件事,你可以访问 github, 如果不行,那就想办法,反正必须要上。\n开始 clone 宁皓的库\ngit clone https://github.com/ninghao/semantic-course ninghao-semantic\n 进入目录,初始化\ncd ninghao-semantic\nnpm init\n 一路回车,然后,安装 Semantic-UI:\nnpm install semantic-ui \u0026ndash;save\n 安装完后设置部分一路回车,然后 进入 semantic 目录:\ncd semantic\ngulp build\n Gulp 任务 gulpfile.js 配置文件在semantic/gulpfile.js,具体的命令实际上是在semantic/tasks里。 生成 js 文件:\n//生成在 dist 目录下面\ngulp build-javascript\n 生成 css 文件:\ngulp build-css\n 修改 Google 字体为国内360提供服务的字体,打开semantic/src/theme.less,修改fonts.googleapis.com为fonts.useso.com\n gulp 监视 不会主动结束,会一直监视 semantic 目录,将一切改变自动 build:\ngulp watch\n ","permalink":"https://huifeng.me/posts/ninghao-semantic-study-01/","tags":["宁皓网"," semantic"," UI"," 笔记"," notes"," 前端"],"title":"跟着宁皓网学 SemanticUI 学习笔记(01)"},{"categories":["Linux"],"contents":"今天为一台联想安装ubuntu系统,确实手闲,看Elementary OS非常漂亮,就把一台好好的机子给做了,于是被坑了,但是问题最终通过我强大的搜索能力和完美的解决问题的思路,最终搞定了。下面记录下经验。\n黑屏原因 因为显卡驱动问题,默认情况下,ubuntu没有对个别显卡有较好的支持。\n解决方案 参考页面:\n 安装ubuntu黑屏问题的解决 Ubuntu 14.04 黑屏问题解决 官方:My computer boots to a black screen, what options do I have to fix it? Elementary OS – Black Screen and Blank Desktop error 上面1和2是国人写的,国语,3和4是洋文。\n我这里把4的贴这里,我是按照这个搞定的,想深入了解内幕玄机原理的,可以看2和3.\n我是成功了,当然一般这么做都没问题。祝你成功!~\n Create USB Linux install using YUMI – Multiboot USB Creator - [LINK]\n Boot up via USB\n At Elementary OS menu, select TAB to edit the command line. remove \u0026ldquo;quiet\u0026rdquo; and replace with \u0026ldquo;nomodeset\u0026rdquo;\n Proceed with normal installation\n After installation, boot into Elementary OS and press CTRL+ALT+F1\n Login using the credential created during installation\ncp /etc/default/grub /etc/default/grub.bak\nnano /etc/default/grub\n Add “nomodeset” to GRUBCMDLINELINUX_DEFAULT so it looks like this:\nGRUBDEFAULT=0 GRUBHIDDENTIMEOUT=0 GRUBHIDDENTIMEOUTQUIET=true GRUBTIMEOUT=5 GRUBDISTRIBUTOR=lsb_release -i -s 2\u0026gt; /dev/null || echo Debian GRUBCMDLINELINUXDEFAULT=“quiet splash nomodeset” GRUBCMDLINE_LINUX=”“\n Save by hitting Ctrl-O, then exit nano with Ctrl-X.\nsudo update-grub\n reboot into the Elementary OS\n ","permalink":"https://huifeng.me/posts/ubuntu-black-screen/","tags":["linux"," ubuntu"," black"," screen"," 黑屏"],"title":"Ubuntu安装黑屏问题(ubuntu black screen)"},{"categories":["Git"],"contents":"如何让你的项目可以劈腿呢?可以同时向两个位置push呢?如何实现github和coding上代码同步呢? 其实将代码同时放到GitHub和Coding上在本地看来,就是需要两次push,两次push的名称不同 一次是默认的,比如我的主要库是在GitHub上的origin master, 一次是指定的,比如我的备份库是在Coding上的coding-copy master\n其实对于远端库没什么区别的,都是master主分支上,只是在本地端,需要添加两个远端罢了. 步骤:\n 分别在GitHub和Coding上建立一个项目名称可以相同也可以不同.\n 将本地代码提交到GitHub上刚添加的项目:\n ## 添加GitHub的远程主提交 git remote add origin git@github.com:username/newRepository.git ## 添加其他远程版本库备份提交,这里以Coding为例 git remote add coding-copy git@git.coding.net:username/newRepository.git 此时如果查看版本库git remote show可以看到:\ncoding-copy origin 提交到两个版本库: ## 这会提交到Github版本库:origin master git push -u origin ## 这回提交到coding版本库:coding-copy master git push -u coding-copy 搞定,此时去看看版本库怎么样了?反正我是这么操作的没有问题,一切正常.\n","permalink":"https://huifeng.me/posts/git-push-and-backup-to-coding/","tags":["git"," push"," 同步"," coding"," github"],"title":"Git劈腿实战:让项目脚踩两条船"},{"categories":["Linux"],"contents":"每次,每次要改系统变量都要查,都要搜索,这次我把这个知识点记录下来,主要针对Linux和Mac系统.\n 最简洁,最有效,临时的,最通用的是:PATH=$PATH:/usr/local/bin; export PATH\n 复杂但永久有效的,需要重启:\n 快速配置方法:sudo vim ~/.bash_profile,添加一行. 这里示例添加Composer的bin目录到环境变量,:是分隔符\n export PATH=\u0026#34;$HOME/.composer/vendor/bin:$PATH\u0026#34; 想了解原理细节等继续往下看:\n /etc/profile: 对所有用户生效;\n 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行;并从/etc/profile.d目录的配置文件中搜集shell的设置\n /etc/bashrc: 对所有用户生效;\n 为每一个运行 bash shell 的用户执行此文件.当 bash shell 被打开时,该文件被读取\n ~/.bash_profile: 仅会对当前用户有效;\n 每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次\n ~/.bashrc: 仅会对当前用户有效;\n 该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取 ~/.bashrc中设定的变量(局部)只能继承/etc/profile中的变量,他们是\u0026quot;父子\u0026quot;关系 常用的环境变量: PATH 决定了shell将到哪些目录中寻找命令或程序 HOME 当前用户主目录 HISTSIZE 历史记录数 LOGNAME 当前用户的登录名 HOSTNAME 指主机的名称 SHELL 当前用户Shell类型 LANGUGE 语言相关的环境变量,多语言可以修改此环境变量 MAIL 当前用户的邮件存放目录 PS1 基本提示符,对于root用户是#,对于普通用户是$ ","permalink":"https://huifeng.me/posts/system-path-edit/","tags":["linux"," path"," 环境变量"],"title":"修改系统环境变量"},{"categories":["Mac"],"contents":"Made iTerm2 lovely and amazing 为了让我的Mac的终端更漂亮,我结结实实的经历了一番折腾,之前一直被卡在乱码的事情上了,今天解决了,这里记录下经验. 本文适用于Mac OSX系统,Linux系统也可以,办法都是一样的.\n这是我的样式,你喜欢的话可以继续往下看.\n首先,请确定,你的终端已经安装好了oh-my-zsh,安装它的前提是已经安装了zsh,这些都可以在这些网站得到帮助:\n它的官网是:http://ohmyz.sh , GItHub: https://github.com/robbyrussell/oh-my-zsh/\n安装过程不说了,这里主要将应用皮肤后的图标乱码问题,基础问题,请阅读上面两个地址的内容.\n安装完毕后,你的当前用户目录下应该有这样的文件结构:\n输入ls ~/.oh-my-zsh/命令,得到:\nMIT-LICENSE.txt custom oh-my-zsh.sh themes README.markdown lib plugins tools cache log templates 注意,样式文件都放在themes文件夹里面.\n在这里可以看到样式的预览:https://github.com/robbyrussell/oh-my-zsh/wiki/Themes\n然后很多炫酷的样式都需要powerline的支持,安装完毕后,进入真正让人郁闷的乱码环节:\n其实,这对于搞定的人而言,真的是非常简单的~~ 我当时安装好了各种,官方文档也各种看,结果就有一件事没做,我怎么都没想到问题会出在那里!!\n我们应该知道powerline的字体是放在这里的:https://github.com/powerline/fonts\n我们也知道运行./install.sh可以安装,但是我们是否知道,运行完后,哪些.ttf文件也许是没有完整安装的? 我试着将powerline的github上的内容clone下来,然后将里面的字体安装了一下,会有别于一般的字体,会有for powerline的名称后缀, 这就是突破口,突破乱码的突破口啊,建议选择好喜欢的字体后,手动安装下.ttf字体\n这些都搞定了,你以为你的终端已经好了么?No!你还需要调整你的终端的设置,将字体设置为你刚才安装的有for powerline后缀的字体.\n此时,整个世界清朗了,没有乱码了\n总结 需要完成你能完成的工作,否则你看不懂我在说什么,我选择的风格是:avit, Gitster, robbyrussell, miloshadzic, powerline, 目前用的最多的是avit 手动安装喜欢的,带有for powerline后缀的字体 调整设置你的终端字体 如果需要的换,可以在选择一款合适的配色方案,我的选择|更多选择 资源 我选择的字体:SourceCodePro 如果你被墙了,上述地址你打不开的,一切东西都是妄谈,不如先学会如何翻过局域网看世界 实在想要这个字体,在这里下载:本站下载 我选择的终端配色:philduffy/seti-iterm 实在想用这个配色,在这里下载:本站下载,下载后,在终端设置里导入即可. ","permalink":"https://huifeng.me/posts/made-iterm2-lovely-and-amazing/","tags":["iterm"," powerline"," 乱码"," Mac"],"title":"让终端更美丽动人-解决乱码问题"},{"categories":["翻墙"],"contents":"起因:\n 我中华大地大局域网风云变幻,目前git push git pull git clone等,单反需要访问真互联网的操作总让人痛心!痛彻心扉~~ 怎么办?shadowsocks可以让我访问真互联网,但是每次命令行都会遇到一些问题,开启全局代理依然无法git 到 GitHub.怎么办?之前试过tsocks,现在,我的体验是,它只能支持wget,不能git 为了方便快捷解决这个问题,这里推荐下ProxyChains-NG,下面具体操作.\n 项目主页:https://github.com/rofl0r/proxychains-ng\n官方说明:\n proxychains ng (new generation) - a preloader which hooks calls to sockets in dynamically linked programs and redirects it through one or more socks/http proxies. continuation of the unmaintained proxychains project.\n 参考博文: http://www.dreamxu.com/proxychains-ng/\n安装配置 使用 Homebrew 安装\nbrew install proxychains-ng 编辑配置文件 vim /usr/local/etc/proxychains.conf\n在 [ProxyList] 下面(也就是末尾)加入代理类型,代理地址和端口 例如使用 TOR 代理,注释掉原来的代理并添加\nsocks5 127.0.0.1 1080 注意,这里的端口号根据你自己的决定,比如我用的shadowsocks,本地端口是1080,那这里就是1080\n如果所在的网络很复杂,可能需要在配置文件中启用 dynamic_chain - 按照列表中出现的代理服务器的先后顺序组成一条链,如果有代理服务器失效,则自动将其排除,但至少要有一个是有效的 然后在 [ProxyList] 下添加多个代理\n默认是: strict_chain - 按照后面列表中出现的代理服务器的先后顺序组成一条链,要求所有的代理服务器都是有效的\n使用 在命令的前面加上proxychains4即可\nproxychains4 git push OSX 10.11安装失败? 2015-12-05更新\n 由于 OSX 10.11 的 SIP 特性,会导致 proxychains-ng 安装失败,这里有三种解决方法:\n 如果是使用 brew install proxychains-ng 安装的话,由于没有写入权限,必须暂时关闭 SIP,安装成功之后再打开 SIP。具体方法见 http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/ 如果不使用 brew install 的话,可以 clone 源码自己编译安装,关键是避免安装到 usr 目录(无法写入),手动指定写入目录,如 ./configure --prefix=$HOME/.local --sysconfdir=/etc,etc 有写入权限不必修改,记得添加环境变量即可。 需要安装 xcode7 , 然后执行 xcode-select -s /Applications/Xcode-beta.app/Contents/Developer ,就能用 brew 安装 proxychains 了,可能以后 xcode7 正式版本出来,要记得改回来 初此之外,OSX 自带的 git,curl 等版本过低,无法支持 proxychains-ng,请手动更新版本。 ","permalink":"https://huifeng.me/posts/proxychains-ng-4-osx-setting/","tags":["proxychains"," shadowsocks"," 翻墙"," 代理"," OSX"," Mac"," git"],"title":"Mac OSX 系统下通过 ProxyChains-NG 实现终端(命令行)翻墙"},{"categories":["翻墙"],"contents":"Shadowsocks Python源码(zip包,tar包)解压后,进入目录运行python setup.py\nOS X 为 OS X 10.8+ 设计的 Shadowsocks 图形界面,启动后可自动实现全局翻墙,并根据 GFWList 区分墙内外流量。\n下载 https://sourceforge.net/projects/shadowsocksgui/ 去Coding.net下载\n基本使用 解压后移动到合适目录下,然后启动。 如果弹出系统安全提示,请选「允许」。 Shadowsocks 会自动设置为全局 PAC 代理,Chrome、Safari、Twitter 都可以正常使用了。 如果你开启了其它翻墙工具,请先将它们关闭。如果你使用了 Chrome 扩展程序 SwitchySharp,请把它的模式设置为「使用系统代理设置」。 启动后可以在菜单栏右边找到 Shadowsocks 图标。 高级使用 如果你不想用全局 PAC 代理,想配合 SwitchySharp 等插件使用,可在菜单栏图标里点关闭 Shadowsocks。关闭后代理仍会运行在 127.0.0.1:1080 上,代理类型为 SOCKS v5。之所以不叫关闭 PAC,因为很多人不懂什么是 PAC。写关闭 Shadowsocks 更容易理解。 默认使用公共服务器,可以在菜单栏图标里配置自定义服务器。 切换服务器后,因为 Chrome 保持长连接,可能需要重启浏览器才能生效。也可以重启 ShadowsocksX 来强制 Chrome 重新连接。 可以在菜单里点 编辑 PAC 来修改 PAC 文件,文件保存后会自动通知浏览器重新加载。推荐用 Xcode 等代码编辑器来编辑。如果用系统自带的文本编辑器,引号可能自动半角变全角,需要撤销一下回到半角。 可以在菜单栏图标里打开控制台查看日志,其中 ShadowsocksX: 开头的是 Shadowsocks 的日志。 Linux Fedora 目前支持RHEL 7, Fedora 21, 22, rawhide\n 使用dnf添加shadowsocks的Copr源: sudo dnf copr enable librehat/shadowsocks 使用dnf更新cache并安装: sudo dnf update sudo dnf install shadowsocks-qt5 如果使用传统的yum包管理工具的话,需要从Copr下载相应版本的repo文件放到/etc/yum.repos.d/下,然后通过yum安装:\nsudo yum update sudo yum install shadowsocks-qt5 Ubuntu 通过PPA源安装,仅支持Ubuntu 14.04或更高版本。\nsudo add-apt-repository ppa:hzwhuang/ss-qt5 sudo apt-get update sudo apt-get install shadowsocks-qt5 Debian 可以尝试安装Ubuntu PPA源的deb包,如果不行,请自行编译(dpkg-buildpackage -uc -us -b),在上级目录中将会生成shadowsocks-qt5的deb包,通过sudo dpkg -i来安装。\n注意:你可能需要安装好的依赖关系:\nsudo apt-get install qt5-qmake qtbase5-dev libqrencode-dev libqtshadowsocks-dev libappindicator-dev libzbar-dev libbotan1.10-dev\nArch AUR,由ykelvis维护\nGentoo gentoo-zh,由microcai维护\nwindows 直接下载客户端:\nss-qt5-v2.4.1-win32 ss-qt5-v2.4.1-win64 需安装.Net4.0的CSharp版本\n","permalink":"https://huifeng.me/posts/shadowsocks-bakup/","tags":["shadowsocks"," 翻墙"," GFW"],"title":"shadowsocks使用帮助和下载"},{"categories":["Tickets"],"contents":"记录下平时常用又不止一次忘记的\u0026hellip;\u0026hellip; Git git remote remove origin git remote add origin git@github.com:wedojava/myPythonStudy.git git push -u origin master git pull --allow-unrelated-histories fix: git pull =\u0026gt; fatal: refusing to merge unrelated histories OS Linux 系统的 80 端口被占用了?运行: sudo fuser -k 80/tcp\n 列出进程的详细信息,而不仅仅是进程id: -v 含义是:verbose output,详细的输出信息 列出进程所属的用户:-u 含义是:display user IDs,显示用户id 杀死所有正在访问指定文件的进程: -k 含义: kill processes accessing the named file 列出 fuser 所知的信号: -l windows系统编辑文件:C:\\Windows\\System32\\Drivers\\etc\\hosts\n 生成随机字符串:openssl rand -base64 12 =\u0026gt; mLIZ5/4nlHTqjEM5\n 这个-base64还可以换成其他参数\n Coding PHP显示所有错误 // Show all errors error_reporting(E_ALL); PHP换行:PHP_EOL: echo \u0026#34;do sth\u0026#34;.PHP_EOL; 打包虚拟机先删除网卡数据 要导出或打包虚拟机应该先清理虚拟机,如果不做下面的操作,当虚拟机被导入到其他主 机上时会在网络配置方面遇到很麻烦的问题,具体表现为怎么配置网络设置都无效果,原因 是这个文件里包含了宿主电脑的网卡等硬件信息,比如Mac地址,我曾经遇到过这样的问题, 怎么设置配置文件里的mac和IP等信息都不其作用,后来在问题虚拟机上执行下面的命令删 除了老文件重启机器,问题才得到解决,所以最好是在导出前将该文件删除,具体的命令:\n sudo rm -rf /etc/udev/rules.d/70-persistent-net.rules lorem:Lorem ipsum(乱数假文)\n g++: command not found或g++:命令未找到,怎么办?Install the suite of development tools first. Then go back to compile the software 运行这个命令:yum groupinstall 'Development Tools', The Development Tools package includes the core development tools like automake, gcc, perl, python, flex, make, gdb, bison, and many more.Update: For Fedora 20 (at least), you\u0026rsquo;ll additionally need to install gcc-c++.\n MySQL\n 从其他终端登录MySQL服务器: mysql -uUSERNAME -p -h HOSTNAME 查询数据库版本: mysql\u0026gt; SHOW VARIABLES LIKE \u0026quot;version\u0026quot;; Show Database Users: mysql\u0026gt; SELECT User,Host FROM mysql.user; Show available Databases: mysql\u0026gt; SHOW DATABASES; Show ownCloud Tables in Database: mysql\u0026gt; USE DatabaseName; SHOW TABLES; 网址收藏 阿里源\nhttps://iuscommunity.org\nhttps://packagist.org\nhttp://segmentfault.com\nhttp://www.phpcomposer.com\n老D博客的hosts文件更新\n来这里学习:https://laracasts.com\n","permalink":"https://huifeng.me/posts/alwaysforgottentickets/","tags":["tickets"," php"," linux"," windows"],"title":"AlwaysForgottenTickets"},{"categories":["Hexo"],"contents":"参考以下内容,感谢原作者,转载留个链接:\n Berry的博客: 已消失\u0026hellip;\u0026hellip; 添加新用户,SSH设置,参考了Linode官方帮助:Securing Your Server\n 两种方法\n 在VPS上执行hexo server,再配置Nginx反向代理,让blog的域名指向http://localhost:4000。\n 在本地生成静态文件,把静态文件部署到VPS上,用Nginx直接做Web服务。(嗯,我喜欢这种,就用这种吧)\n Nginx 配置 在Nginx中新建虚拟主机,我用的时linuxeye的oneinstack包安装的环境,所以,我的新建只需要sudo ./vhost.sh即可,然后将blog文件通过sftp或者scp上传到网站目录.\n自动部署 自动部署的意思是,每当我们执行hexo d后,我们的网站信息就发布到服务器上的虚拟目录里.一般的部署方式要么是git要么是rsync,rsync需要本地计算机和服务器都安装了rsync,然后是一翻配置,这里我们用更方便好用的Git来实现:\nGit 安装 若无特殊说明,所有安装都在CentOS-7.1上完成\n 想安装git 1.× 版本,在VPS上输入sudo yum install git 想安装git 2.× 版本,在VPS上输入sudo yum install git2u 生成SSH秘钥\n如果本机是linux或者Mac OS那就好办了,如果没有生成过ssh秘钥对可输入ssh-keygen -t rsa -C \u0026quot;blog\u0026quot;然后一路回车,问密码的地方可以留空,这样这个ssh连接就不在询问密码了,如果你输入了密码,奖励ssh连接的时候是要输入密码的.\n然后,我们可以在当前执行用户的目录下找到这个目录(隐藏的)cd ~/.ssh,ls -a可以看到有id_rsa,id_rsa.pub和known_hosts三个文件,其中id_rsa.pub是公钥.\n注意: 如果你事通过ssh-keygen -t rsa -C \u0026quot;blog\u0026quot;命令新建的ssh密钥对,那么秘钥对的名字应该是blog, blog.pub.\n多说两句,老鸟请绕行,公钥就是给别人的,放别人那里,私钥可以理解为是你这台机器的指纹,所以服务器上的当前用户目录下的~/.ssh/authorized_keys文件里应当包含你的公钥,这样你SSH的时候,服务器明白,哦,我有你的公钥,你的私钥和公钥配对,证明了你是自己人,可以进入系统\n注意: authorized_keys文件不一定是存在的,新建的服务器用户下面是没有这个文件的,需要自己touch进去,如果已经有这个文件了,里面应该有很多行,每行代表一个可以ssh连接的主机的公钥.\n服务器端配置 新建用户git: sudo adduser git 切换至git用户:su git,然后初始化git用户的环境 cd ~ mkdir .ssh \u0026amp;\u0026amp; cd .SSH touch authorized_keys vim authorized_keys 把blog.pub(刚才新建的)或id_rsa.pub的内容粘贴到authorized_keys\n在终端输入ssh git@your-ip-or-domain,如果能远程登录说明没有问题了.如果出问题了,请试试看看运行 ll -a /home/git/, 看看.ssh目录的拥有者是否是git:git,实在不行就运行: chown -R git:git .ssh chmod 700 .ssh chmod 600 .ssh/authorized_keys 为静态内容新建仓库: cd ~ mkdir blog.git \u0026amp;\u0026amp; cd blog.git git init --bare 本地设置 设置git用户名 git config --global user.email \u0026#34;email@example.com\u0026#34; git config --global user.name \u0026#34;username\u0026#34; 修改hexo配置文件里的deploy选项,git@12.34.56.78:后面跟的yournick/abcd.git相当于服务器目录:/home/git/yournick/abcd.git/ deploy: type: git repo: git@12.34.56.78:younick/abcd.git,master 运行hexo g hexo d,如果一切正常,静态文件已经被成功的push到了blog的仓库里,如果出现appears not to be a git repo的错误,删除hexo目录下的.deploy后再次hexo g hexo d就可以了 Git hooks 如果你上面都执行成功了,会发现,服务器的/home/git/××××.....××××.git/branches/目录是空的.这里引用下Berry 在他的文章中的解释:\n 既然blog.git是一个仓库,那么只要git clone /home/git/blog.git就可以取出仓库的内容了。顺着这个思路就有了下面的想法,使用git hooks在每次push完成后,执行一段脚本,把blog.git里的内容clone出来,再复制到/var/www/blog目录。\n 在/home/git/××××.....××××.git/branches/目录下会由hooks目录,里面可以写脚本,Berry的意思就是,每次hexo d提交了以后,网站数据进入git的之后执行脚本,将刚入进来的数据拷贝到网站目录去.\ncd ~/blog.git/hooks touch post-receive vi post-receive 使用下面的脚本\n#!/bin/bash -l GIT_REPO=/home/git/blog.git TMP_GIT_CLONE=/tmp/blog PUBLIC_WWW=/var/www/blog rm -rf ${TMP_GIT_CLONE} git clone $GIT_REPO $TMP_GIT_CLONE rm -rf ${PUBLIC_WWW}/* cp -rf ${TMP_GIT_CLONE}/* ${PUBLIC_WWW} 注意: 脚本里的rm等命令是否能执行成功有git的权限和它所操控的目录决定,所以我们要根据需要的修改下权限\n赋予脚本的执行权限:chmod +x post-receive\n赋予git对网站目录的所有权:chown git:git -R 你的网站目录位置\n以上执行完后,虽然我们这次部署的是静态网站,但是如果是php等动态网站的话,会发现,静态页面可以解析,动态页面解析不了,所以这里建议:\n修改php-fpm(如果你是用它来解析php)的配置文件www.conf,让user = git下面这项是我自己的个人爱好,你可以不做:\n让git的权利再大点,比如,修改nginx的nginx.conf文件,让user为git git,使它成为nginx的操作用户。\n 完工!!\n","permalink":"https://huifeng.me/posts/deploy-hexo-to-vps/","tags":["VPS"," hexo"," 部署"," nginx"," git"],"title":"Deploy Hexo sites to VPS"},{"categories":["Linux"],"contents":" 参考文献:https://www.linode.com/docs/\n 前面内容不再多说,直接说我开始的地方:\n Getting Started 登录VPS 首先是第一次登录,这里主要谈登陆失败的情况: 我之前做过一个vps,然后听说日本的好,然后就把之前的那个服务器删了,删除后才发现日本机房的根本买不上,买上的很多也是IP被封了.当时自己还刷了很久linode网站,无果,最终选择了美国西海岸机房.据说除了日本机房最好选它.于是重新添加硬盘,Rebuild,等等,系统起来了,准备ssh登录了,然后就报错了,\u0026ldquo;That’s because SSH clients try to match the remote host with the known keys on your desktop computer. When you rebuild your Linode, the remote host key changes. \u0026ldquo;下面动手删了那一行:\nvim ~/.ssh/known_hosts 找到之前的记录内容,删除掉就好了\nSetting the hostname CentOS 7 / Fedora version 18 and above\nhostnamectl set-hostname hostname Ubuntu 15.04 / Debian 8\nhostnamectl set-hostname hostname Setting the Timezone Arch Linux and CentOS 7\ntimedatectl list-timezones then\ntimedatectl set-timezone Asia/Shanghai Ubuntu / Debian\ndpkg-reconfigure tzdata checking the time\nNow try entering the following command to view the current date and time according to your server:\ndate installing software update yum update Securing Your Server Add a New User The problem with logging in as root is that you can execute any command - even a command that could accidentally break your server. For this reason and others, we recommend creating another user account and using that at all times.\n Open a terminal window and log in your linode server\n Create the user by entering the following command.Replace exampleuser to your desired username:\n adduser exampleuser Set the password for your new user by entering the following command. Replace exampleuser with your desired username: passwd exampleuser You will now need to edit your sudoers file to grant your new user the correct permissions. Enter the following command to open your sudoers file for editing: visudo add an entry for your user below the root user, granting all permissions. Replace exampleuser with your username: ## Allow root to run any commands anywhere root ALL=(ALL) ALL exampleuser ALL=(ALL) ALL Enter the command logout And then log in your linode again by the following command,Replace exampleuser with your username, and the example IP address with your Linode’s IP address: ssh exampleuser@123.456.78.90 Using SSH Key Pair Authentication(SSH认证配对) linux Or Mac OS, Entering the following command in a terminal window ssh-keygen copy the public key ~/.ssh/id_rsa.pub to your linode,you can entering the following command in a terminal window.Replace example_user with your username, and 123.456.78.90 with your Linode’s IP address. scp ~/.ssh/id_rsa.pub example_user@123.456.78.90: Create a directory for public key in your home directory (/home/yourusername) by entering the following command ** on your linode: ** mkdir .ssh move the file which is on your linode\u0026rsquo;s home directory to the directory your just create: mv id_rsa.pub .ssh/authorized_keys Modify the permissions on the public key by entering the following commands, one by one, on your linode. Replace example_user with your username. chown -R example_user:example_user .ssh chmod 700 .ssh chmod 600 .ssh/authorized_keys Disabling SSH Password Authentication and Root Login(禁止SSH的密码登录和root登陆) First, you’ll disable password authentication to require all users connecting via SSH to use key authentication. Next, you’ll disable root login to prevent the root user from logging in via SSH. These steps are optional, but are strongly recommended.\n Open the SSH configuration file for editing by entring the following command: sudo vim /etc/ssh/sshd_config Entring /, then PasswordAuthentication and push Enter key, push n to search the key word,change the keyword\u0026rsquo;s setting to no,Verify that the line is uncommented by removing the # in front of line: PasswordAuthentication no Change the PermitRootLogin setting to no as shown below: PermitRootLogin no save the configuration file (:wq) and restart the SSH service to load the new configuration: Fedora/CentOS:\nsudo systemctl restart sshd Debian/Ubuntu Users:\nsudo service ssh restart Creating a Firewall This step is optional, but we strongly recommend that you use the example below to block traffic to ports that are not commonly used. It’s a good way to deter would-be intruders! You can always modify the rules or disable the firewall later.\n Check your Linode’s default firewall rules by entering the following command: sudo iptables -L Examine the output. If you haven’t implemented any firewall rules yet, you should see an empty ruleset, as shown below: Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Create a file to hold your firewall rules by entering the following command: sudo vim /etc/iptables.firewall.rules We’ve created some basic rules to get you started. Copy and paste the rules shown below in to the iptables.firewall.rules file you just created. By default, the rules will allow traffic to the following services and ports: HTTP (80), HTTPS (443), SSH (22), and ping. All other ports will be blocked.\nFile:/etc/iptables.firewall.rules\n*filter # Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn\u0026#39;t use lo0 -A INPUT -i lo -j ACCEPT -A INPUT -d 127.0.0.0/8 -j REJECT # Accept all established inbound connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow all outbound traffic - you can modify this to only allow certain traffic -A OUTPUT -j ACCEPT # Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL). -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 443 -j ACCEPT # Allow SSH connections # # The -dport number should be the same port number you set in sshd_config # -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT # Allow ping -A INPUT -p icmp --icmp-type echo-request -j ACCEPT # Log iptables denied calls -A INPUT -m limit --limit 5/min -j LOG --log-prefix \u0026#34;iptables denied: \u0026#34; --log-level 7 # Drop all other inbound - default deny unless explicitly allowed policy -A INPUT -j DROP -A FORWARD -j DROP COMMIT Be sure to revise these rules if you add new services later.\n Optional: If you plan on using the Linode Longview service, add these additional lines above the # Drop all other inbound section: File:/etc/iptables.firewall.rules\n# Allow incoming Longview connections -A INPUT -s longview.linode.com -j ACCEPT # Allow metrics to be provided Longview -A OUTPUT -d longview.linode.com -j ACCEPT Save the changes by pressing :wq and then activate the firewall rules by entring the following command: sudo iptables-restore \u0026lt; /etc/iptables.firewall.rules Recheck your Linode’s firewall rules by entering the following command: sudo iptables -L Examine the output. The new ruleset should look like the one shown below: Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT all -- anywhere 127.0.0.0/8 reject-with icmp-port-unreachable ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT icmp -- anywhere anywhere LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix \u0026#34;iptables denied: \u0026#34; DROP all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination DROP all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere Now you need to ensure that the firewall rules are activated every time you restart your Linode.\n CentOS 6.2 or 6.5: /sbin/service iptables save\n CentOS 7 or Fedora 20:\n yum install -y iptables-services systemctl enable iptables systemctl start iptables To save your current rule set use the following command:\n/usr/libexec/iptables/iptables.init save Installing and Configuring Fail2Ban Fail2Ban is an application that prevents dictionary attacks on your server. When Fail2Ban detects multiple failed login attempts from the same IP address, it creates temporary firewall rules that block traffic from the attacker’s IP address. Attempted logins can be monitored on a variety of protocols, including SSH, HTTP, and SMTP. By default, Fail2Ban monitors SSH only.\n Install Fail2Ban by entering the following command: sudo yum install epel-release sudo yum install fail2ban Optionally, you can override the default Fail2Ban configuration by creating a new jail.local file. Enter the following command to create the file: sudo nano /etc/fail2ban/jail.local To learn more about Fail2Ban configuration options, see this article on the Fail2Ban website.\n Set the bantime variable to specify how long (in seconds) bans should last.\n Set the maxretry variable to specify the default number of tries a connection may be attempted before an attacker’s IP address is banned.\n Press Control-x and then press y to save the changes to the Fail2Ban configuration file.\n Restart Fail2Ban by using sudo service fail2ban restart.\n ","permalink":"https://huifeng.me/posts/linode-centos-init/","tags":["linux"," centos"," linode"," iptables"," fail2ban"],"title":"Linode 的 CentOS-7.1 初始化操作"},{"categories":["PHP"],"contents":"PHP标准组 提出并发布了一系列的风格建议。其中有部分是关于代码风格的,即 PSR-0, PSR-1, PSR-2 和 PSR-4。这些推荐只是一些被其他项目所遵循的规则,如 Drupal, Zend, Symfony, CakePHP, phpBB, AWS SDK, FuelPHP, Lithium 等。你可以把这些规则用在自己的项目中,或者继续使用自己的风格。通常情况下,你应该遵循一个已知的标准来编写 PHP 代码。可能是 PSR 的组合或者是 PEAR 或 Zend 编码准则中的一个。这代表其他开发者能够方便的阅读和使用你的代码,并且使用这些组件的应用程序可以和其他第三方的组件保持一致。\n 先推荐一个网址: PHP编码规范(中文版)导读\n PSR-0已弃用,从PSR-1开始,只罗列我感觉会忽视或我自己不清楚的地方:\n PSR-1 基本代码规范(Basic Coding Standard) 名词解释:从属效应? 一份PHP文件中应该要不就只定义新的声明,如类、函数或常量等不产生从属效应的操作,要不就只有会产生从属效应的逻辑操作,但不该同时具有两者。\n “从属效应”(side effects)一词的意思是,仅仅通过包含文件,不直接声明类、 函数和常量等,而执行的逻辑操作。\n 包含却不仅限于:生成输出、直接的 require 或 include、连接外部服务、修改 ini 配置、抛出错误或异常、修改全局或静态变量、读或写文件等。\n 类的命名必须遵循 StudlyCaps 大写开头的驼峰命名规范;\n 类中的常量所有字母都必须大写,单词间用下划线分隔;\n 方法名称必须符合 camelCase 式的小写开头驼峰命名规范。\n 类的属性命名可以遵循 大写开头的驼峰式 ($StudlyCaps)、小写开头的驼峰式 ($camelCase) 又或者是 下划线分隔式 ($under_score)\n PHP 5.3及以后版本的代码必须使用正式的命名空间。\n 5.3以后:\n\u0026lt;?php // PHP 5.3及以后版本的写法 namespace Vendor\\Model; class Foo { } 5.2.x及之前的版本应该使用伪命名空间的写法,约定俗成使用顶级的组织名称(vendor name)如 Vendor_ 为类前缀。\n\u0026lt;?php // 5.2.x及之前版本的写法 class Vendor_Model_Foo { } PHP代码文件必须以 不带BOM的 UTF-8 编码;\n PHP代码中应该只定义类、函数、常量等声明,或其他会产生 从属效应 的操作(如:生成文件输出以及修改.ini配置文件等),二者只能选其一;\n 反例,包含声明以及产生从属效应的代码:\n\u0026lt;?php // 从属效应:修改 ini 配置 ini_set(\u0026#39;error_reporting\u0026#39;, E_ALL); // 从属效应:引入文件 include \u0026#34;file.php\u0026#34;; // 从属效应:生成输出 echo \u0026#34;\u0026lt;html\u0026gt;\\n\u0026#34;; // 声明函数 function foo() { // 函数主体部分 } 正例,只包含声明不产生从属效应的代码:\n\u0026lt;?php // 声明函数 function foo() { // 函数主体部分 } // 条件声明**不**属于从属效应 if (! function_exists(\u0026#39;bar\u0026#39;)) { function bar() { // 函数主体部分 } } PSR-2 代码风格规范(Coding Style Guide) PSR-2 是 PSR-1 基本代码规范的继承与扩展。\n 1. 概览 代码必须遵循 PSR-1 中的编码规范 。\n 代码必须使用4个空格符而不是 tab键 进行缩进。\n 每行的字符数应该软性保持在80个之内, 理论上一定不可多于120个, 但一定不能有硬性限制。\n 每个 namespace 命名空间声明语句和 use 声明语句块后面,必须 插入一个空白行。\n 类的属性和方法必须添加访问修饰符(private、protected 以及 public), abstract 以及 final 必须声明在访问修饰符之前,而 static 必须声明在访问修饰符之后。\n 控制结构的关键字后必须要有一个空格符,而调用方法或函数时则一定不能有。\n 控制结构的开始花括号{必须写在声明的同一行,而结束花括号}必须写在主体后自成一行。\n 控制结构的开始左括号后和结束右括号前,都一定不能有空格符。\n 例子 以下例子程序简单地展示了以上大部分规范:\n\u0026lt;?php namespace Vendor\\Package; use FooInterface; use BarClass as Bar; use OtherVendor\\OtherPackage\\BazClass; class Foo extends Bar implements FooInterface { public function sampleFunction($a, $b = null) { if ($a === $b) { bar(); } elseif ($a \u0026gt; $b) { $foo-\u0026gt;bar($arg1); } else { BazClass::bar($arg2, $arg3); } } final public static function bar() { // method body } } 2. 通则 2.1 基本编码准则 代码必须符合 PSR-1 中的所有规范。 2.2 文件 所有PHP文件必须使用Unix LF (linefeed)作为行的结束符。\n 所有PHP文件必须以一个空白行作为结束。\n 纯PHP代码文件必须省略最后的 ?\u0026gt; 结束标签。\n 2.3 行 行的长度一定不能有硬性的约束。\n 软性的长度约束一定要限制在120个字符以内,若超过此长度,带代码规范检查的编辑器一定要发出警告,不过一定不可发出错误提示。\n 每行不应该多于80个字符,大于80字符的行应该折成多行。\n 非空行后一定不能有多余的空格符。\n 空行可以使得阅读代码更加方便以及有助于代码的分块。\n 每行一定不能存在多于一条语句。\n 代码必须使用4个空格符的缩进,一定不能用 tab键 。\n 备注: 使用空格而不是tab键缩进的好处在于, 避免在比较代码差异、打补丁、重阅代码以及注释时产生混淆。 并且,使用空格缩进,让对齐变得更方便。\n PHP所有 关键字必须全部小写。\n 常量 true 、false 和 null 也必须全部小写。\n 3. namespace 以及 use 声明 namespace 声明后 必须 插入一个空白行。\n所有 use 必须 在 namespace 后声明。\n每条 use 声明语句 必须 只有一个 use 关键词。\nuse 声明语句块后 必须 要有一个空白行。\n例子:\n\u0026lt;?php namespace Vendor\\Package; use FooClass; use BarClass as Bar; use OtherVendor\\OtherPackage\\BazClass; // ... additional PHP code ... 4. 类、属性和方法 此处的“类”泛指所有的class类、接口以及traits可复用代码块。\n4.1. 扩展与继承 关键词 extends 和 implements 必须 写在类名称的同一行。\n\u0026lt;?php namespace Vendor\\Package; use FooClass; use BarClass as Bar; use OtherVendor\\OtherPackage\\BazClass; class ClassName extends ParentClass implements \\ArrayAccess, \\Countable { // constants, properties, methods } implements 的继承列表也可以分成多行,这样的话,每个继承接口名称都必须分开独立成行,包括第一个。\n\u0026lt;?php namespace Vendor\\Package; use FooClass; use BarClass as Bar; use OtherVendor\\OtherPackage\\BazClass; class ClassName extends ParentClass implements \\ArrayAccess, \\Countable, \\Serializable { // constants, properties, methods } 4.2. 属性 每个属性都 必须 添加访问修饰符。\n绝不能 使用关键字 var 声明一个属性。\n每条语句只能定义 一个属性。\n不能 用 _ 作为前缀,来区分属性是 protected 或 private。\n以下是属性声明的一个范例:\n\u0026lt;?php namespace Vendor\\Package; class ClassName { public $foo = null; } 4.3. 方法 所有方法都 必须 添加访问修饰符。\n不能 用 _ 作为前缀,来区分方法是 protected 或 private。\n方法名称 后一定不能有空格符,其开始花括号必须独占一行,结束花括号也必须在方法主体后单独成一行。参数左括号后和右括号前一定 不能有空格。\n一个标准的方法声明可参照以下范例,留意其括号、逗号、空格以及花括号的位置。\n\u0026lt;?php namespace Vendor\\Package; class ClassName { public function fooBarBaz($arg1, \u0026amp;$arg2, $arg3 = []) { // method body } } 4.4. 方法的参数 参数列表中,每个逗号后面必须要有一个空格,而逗号前面一定不能有空格。\n有默认值的参数,必须放到参数列表的末尾。\n\u0026lt;?php namespace Vendor\\Package; class ClassName { public function foo($arg1, \u0026amp;$arg2, $arg3 = []) { // method body } } 参数列表可以分列成多行,这样,包括第一个参数在内的每个参数都必须单独成行。\n拆分成多行的参数列表后,结束括号以及方法开始花括号 必须 写在同一行,中间用一个 空格分隔。\n\u0026lt;?php namespace Vendor\\Package; class ClassName { public function aVeryLongMethodName( ClassTypeHint $arg1, \u0026amp;$arg2, array $arg3 = [] ) { // method body } } 4.5. abstract 、 final 、 以及 static 需要添加 abstract 或 final 声明时, 必须写在访问修饰符 前 ,而 static 则必须写在 其后。\n\u0026lt;?php namespace Vendor\\Package; abstract class ClassName { protected static $foo; abstract protected function zim(); final public static function bar() { // method body } } 4.6. 方法及函数调用 方法及函数调用时,方法名或函数名与参数左括号之间一定不能有空格,参数右括号前也 一定不能有空格。每个参数前一定不能有空格,但其后必须有一个空格。\n\u0026lt;?php bar(); $foo-\u0026gt;bar($arg1); Foo::bar($arg2, $arg3); 参数可以分裂成多行,此时包括第一个参数在内的每个参数都必须单独成行。\n\u0026lt;?php $foo-\u0026gt;bar( $longArgument, $longerArgument, $muchLongerArgument ); 使用一个或多个跨行的参数(如数组和匿名函数)不需要触发本节中关于参数列表的单行规定, 因此,在参数表中的数组和匿名函数是可以单独分列成多行的:\n\u0026lt;?php somefunction($foo, $bar, [ // ... ], $baz); $app-\u0026gt;get(\u0026#39;/hello/{name}\u0026#39;, function ($name) use ($app) { return \u0026#39;Hello \u0026#39;.$app-\u0026gt;escape($name); }); 5. 控制结构 控制结构的基本规范如下:\n 控制结构关键词后 必须 有一个空格。 左括号 ( 后一定不能有空格。 右括号 ) 前也一定不能有空格。 右括号 ) 与开始花括号 { 间一定有一个空格。 结构体主体一定要有一次缩进。 结束花括号 } 一定在结构体主体后单独成行。 每个结构体的主体都必须被包含在成对的花括号之中, 这能让结构体更加结构话,以及减少加入新行时,出错的可能性。\n5.1. if 、 elseif 和 else 标准的 if 结构如下代码所示,留意 括号、空格以及花括号的位置, 注意 else 和 elseif 都与前面的结束花括号在同一行。\n\u0026lt;?php if ($expr1) { // if body } elseif ($expr2) { // elseif body } else { // else body; } 应该使用关键词 elseif 代替所有 else if ,以使得所有的控制关键字都像是单独的一个词。\n5.2. switch 和 case 标准的 switch 结构如下代码所示,留意括号、空格以及花括号的位置。 case 语句必须相对 switch 进行一次缩进,而 break 语句以及 case 内的其它语句都 必须 相对 case 进行一次缩进。 如果存在非空的 case 直穿语句,主体里必须有类似 // no break 的注释。\n\u0026lt;?php switch ($expr) { case 0: echo \u0026#39;First case, with a break\u0026#39;; break; case 1: echo \u0026#39;Second case, which falls through\u0026#39;; // no break case 2: case 3: case 4: echo \u0026#39;Third case, return instead of break\u0026#39;; return; default: echo \u0026#39;Default case\u0026#39;; break; } 5.3. while 和 do while \u0026lt;?php while ($expr) { // structure body } \u0026lt;?php do { // structure body; } while ($expr); 5.4. for 标准的 for 语句如下所示,注意其 括号、空格以及花括号的位置。\n\u0026lt;?php for ($i = 0; $i \u0026lt; 10; $i++) { // for body } 5.5. foreach 标准的 foreach 语句如下所示,注意其 括号、空格以及花括号的位置。\n\u0026lt;?php foreach ($iterable as $key =\u0026gt; $value) { // foreach body } 5.6. try, catch 标准的 try catch 语句如下所示,注意其 括号、空格以及花括号的位置。\n\u0026lt;?php try { // try body } catch (FirstExceptionType $e) { // catch body } catch (OtherExceptionType $e) { // catch body } 6. 闭包 闭包声明时,关键词 function 后以及关键词 use 的前后都必须要有一个空格。\n开始花括号必须写在声明的同一行,结束花括号必须紧跟主体结束的下一行。\n参数列表和变量列表的左括号后以及右括号前,必须不能 有空格。\n参数和变量列表中,逗号前必须不能有空格,而逗号后必须要有空格。\n闭包中有默认值的参数必须放到列表的后面。\n标准的闭包声明语句如下所示,注意其 括号、逗号、空格以及花括号的位置。\n\u0026lt;?php $closureWithArgs = function ($arg1, $arg2) { // body }; $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) { // body }; 参数列表以及变量列表可以分成多行,这样,包括第一个在内的每个参数或变量都必须单独成行,而列表的右括号与闭包的开始花括号必须放在同一行。\n以下几个例子,包含了参数和变量列表被分成多行的多情况。\n\u0026lt;?php $longArgs_noVars = function ( $longArgument, $longerArgument, $muchLongerArgument ) { // body }; $noArgs_longVars = function () use ( $longVar1, $longerVar2, $muchLongerVar3 ) { // body }; $longArgs_longVars = function ( $longArgument, $longerArgument, $muchLongerArgument ) use ( $longVar1, $longerVar2, $muchLongerVar3 ) { // body }; $longArgs_shortVars = function ( $longArgument, $longerArgument, $muchLongerArgument ) use ($var1) { // body }; $shortArgs_longVars = function ($arg) use ( $longVar1, $longerVar2, $muchLongerVar3 ) { // body }; 注意,闭包被直接用作函数或方法调用的参数时,以上规则仍然适用。\n\u0026lt;?php $foo-\u0026gt;bar( $arg1, function ($arg2) use ($var1) { // body }, $arg3 ); PSR-3 日志接口规范(Logger Interface) 本规范的主要目的,是为了让日志类库以简单通用的方式,通过接收一个 Psr\\Log\\LoggerInterface 对象,来记录日志信息。\n 本文中的 实现者 指的是实现了 LoggerInterface 接口的类库或者框架,反过来讲,他们就是 LoggerInterface 的 使用者。\n 1. 规范说明 这部分内容等需要的时候在看,等需要了解的时候再看,确实有些枯燥!!\n1.1 基本规范 LoggerInterface 接口对外定义了八个方法,分别用来记录 RFC 5424 中定义的八个等级的日志:debug、 info、 notice、 warning、 error、 critical、 alert 以及 emergency 。\n 第九个方法 —— log,其第一个参数为记录的等级。可使用一个预先定义的等级常量作为参数来调用此方法,必须与直接调用以上八个方法具有相同的效果。如果传入的等级常量参数没有预先定义,则必须抛出 Psr\\Log\\InvalidArgumentException 类型的异常。在不确定的情况下,使用者不该使用未支持的等级常量来调用此方法。\n 1.2 记录信息 以上每个方法都接受一个字符串类型或者是有 __toString() 方法的对象作为记录信息参数,这样,实现者就能把它当成字符串来处理,否则实现者必须自己把它转换成字符串。\n 记录信息参数可以携带占位符,实现者可以根据上下文将其它替换成相应的值。\n其中占位符必须与上下文数组中的键名保持一致。\n占位符的名称必须由一个左花括号 { 以及一个右括号 } 包含。但花括号与名称之间一定不能有空格符。\n占位符的名称应该只由 A-Z、 a-z,0-9、下划线 _、以及英文的句号 .组成,其它字符作为将来占位符规范的保留。\n实现者可以通过对占位符采用不同的转义和转换策略,来生成最终的日志。 而使用者在不知道上下文的前提下,不该 提前转义占位符。\n以下是一个占位符使用的例子:\n/** * 用上下文信息替换记录信息中的占位符 */ function interpolate($message, array $context = array()) { // 构建一个花括号包含的键名的替换数组 $replace = array(); foreach ($context as $key =\u0026gt; $val) { $replace[\u0026#39;{\u0026#39; . $key . \u0026#39;}\u0026#39;] = $val; } // 替换记录信息中的占位符,最后返回修改后的记录信息。 return strtr($message, $replace); } // 含有带花括号占位符的记录信息。 $message = \u0026#34;User {username} created\u0026#34;; // 带有替换信息的上下文数组,键名为占位符名称,键值为替换值。 $context = array(\u0026#39;username\u0026#39; =\u0026gt; \u0026#39;bolivar\u0026#39;); // 输出 \u0026#34;Username bolivar created\u0026#34; echo interpolate($message, $context); 1.3 上下文 每个记录函数都接受一个上下文数组参数,用来装载字符串类型无法表示的信息。它可以装载任何信息,所以实现者必须确保能正确处理其装载的信息,对于其装载的数据,一定不能 抛出异常,或产生PHP出错、警告或提醒信息(error、warning、notice)。\n 如需通过上下文参数传入了一个 Exception 对象, 必须 以 'exception' 作为键名。 记录异常信息是很普遍的,所以如果它能够在记录类库的底层实现,就能够让实现者从异常信息中抽丝剥茧。 当然,实现者在使用它时,必须 确保键名为 'exception' 的键值是否真的是一个 Exception,毕竟它可以装载任何信息。\n 1.4 助手类和接口 Psr\\Log\\AbstractLogger 类使得只需继承它和实现其中的 log 方法,就能够很轻易地实现 LoggerInterface 接口,而另外八个方法就能够把记录信息和上下文信息传给它。\n 同样地,使用 Psr\\Log\\LoggerTrait 也只需实现其中的 log 方法。不过,需要特别注意的是,在traits可复用代码块还不能实现接口前,还需要 implement LoggerInterface。\n 在没有可用的日志记录器时, Psr\\Log\\NullLogger 接口可以为使用者提供一个备用的日志“黑洞”。不过,当上下文的构建非常消耗资源时,带条件检查的日志记录或许是更好的办法。\n Psr\\Log\\LoggerAwareInterface 接口仅包括一个 setLogger(LoggerInterface $logger) 方法,框架可以使用它实现自动连接任意的日志记录实例。\n Psr\\Log\\LoggerAwareTrait trait可复用代码块可以在任何的类里面使用,只需通过它提供的 $this-\u0026gt;logger,就可以轻松地实现等同的接口。\n Psr\\Log\\LogLevel 类装载了八个记录等级常量。\n 2. 包 上述的接口、类和相关的异常类,以及一系列的实现检测文件,都包含在 psr/log 文件包中。\n3. Psr\\Log\\LoggerInterface \u0026lt;?php namespace Psr\\Log; /** * 日志记录实例 * * 日志信息变量 —— message, **必须**是一个字符串或是实现了 __toString() 方法的对象。 * * 日志信息变量中**可以**包含格式如 “{foo}” (代表foo) 的占位符, * 它将会由上下文数组中键名为 \u0026#34;foo\u0026#34; 的键值替代。 * * 上下文数组可以携带任意的数据,唯一的限制是,当它携带的是一个 exception 对象时,它的键名 必须 是 \u0026#34;exception\u0026#34;。 * * 详情可参阅: https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-3-logger-interface-cn.md */ interface LoggerInterface { /** * 系统不可用 * * @param string $message * @param array $context * @return null */ public function emergency($message, array $context = array()); /** * **必须**立刻采取行动 * * 例如:在整个网站都垮掉了、数据库不可用了或者其他的情况下,**应该**发送一条警报短信把你叫醒。 * * @param string $message * @param array $context * @return null */ public function alert($message, array $context = array()); /** * 紧急情况 * * 例如:程序组件不可用或者出现非预期的异常。 * * @param string $message * @param array $context * @return null */ public function critical($message, array $context = array()); /** * 运行时出现的错误,不需要立刻采取行动,但必须记录下来以备检测。 * * @param string $message * @param array $context * @return null */ public function error($message, array $context = array()); /** * 出现非错误性的异常。 * * 例如:使用了被弃用的API、错误地使用了API或者非预想的不必要错误。 * * @param string $message * @param array $context * @return null */ public function warning($message, array $context = array()); /** * 一般性重要的事件。 * * @param string $message * @param array $context * @return null */ public function notice($message, array $context = array()); /** * 重要事件 * * 例如:用户登录和SQL记录。 * * @param string $message * @param array $context * @return null */ public function info($message, array $context = array()); /** * debug 详情 * * @param string $message * @param array $context * @return null */ public function debug($message, array $context = array()); /** * 任意等级的日志记录 * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()); } 4. Psr\\Log\\LoggerAwareInterface \u0026lt;?php namespace Psr\\Log; /** * logger-aware 定义实例 */ interface LoggerAwareInterface { /** * 设置一个日志记录实例 * * @param LoggerInterface $logger * @return null */ public function setLogger(LoggerInterface $logger); } 5. Psr\\Log\\LogLevel \u0026lt;?php namespace Psr\\Log; /** * 日志等级常量定义 */ class LogLevel { const EMERGENCY = \u0026#39;emergency\u0026#39;; const ALERT = \u0026#39;alert\u0026#39;; const CRITICAL = \u0026#39;critical\u0026#39;; const ERROR = \u0026#39;error\u0026#39;; const WARNING = \u0026#39;warning\u0026#39;; const NOTICE = \u0026#39;notice\u0026#39;; const INFO = \u0026#39;info\u0026#39;; const DEBUG = \u0026#39;debug\u0026#39;; } PSR-4 自动载入(Autoloader) 1. 概述 本 PSR 是关于由文件路径 自动载入 对应类的相关规范, 本规范是可互操作的,可以作为任一自动载入规范的补充,其中包括 PSR-0,此外, 本 PSR 还包括自动载入的类对应的文件存放路径规范。\n2. 详细说明 此处的“类”泛指所有的class类、接口、traits可复用代码块以及其它类似结构。\n 一个完整的类名需具有以下结构:\n `\\\u0026lt;命名空间\u0026gt;(\\\u0026lt;子命名空间\u0026gt;)*\\\u0026lt;类名\u0026gt;` 完整的类名 必须 要有一个顶级命名空间,被称为 \u0026ldquo;vendor namespace\u0026rdquo;;\n 完整的类名 可以 有一个或多个子命名空间;\n 完整的类名 必须 有一个最终的类名;\n 完整的类名中任意一部分中的下滑线都是没有特殊含义的;\n 完整的类名 可以 由任意大小写字母组成;\n 所有类名都 必须 是大小写敏感的。\n 当根据完整的类名载入相应的文件……\n 完整的类名中,去掉最前面的命名空间分隔符,前面连续的一个或多个命名空间和子命名空间,作为“命名空间前缀”,其必须与至少一个“文件基目录”相对应;\n 紧接命名空间前缀后的子命名空间 必须 与相应的”文件基目录“相匹配,其中的命名空间分隔符将作为目录分隔符。\n 末尾的类名必须与对应的以 .php 为后缀的文件同名。\n 自动加载器(autoloader)的实现 一定不能 抛出异常、一定不能 触发任一级别的错误信息以及 不应该 有返回值。\n 3. 例子 下表展示了符合规范完整类名、命名空间前缀和文件基目录所对应的文件路径。\n 完整类名 命名空间前缀 文件基目录 文件路径 \\Acme\\Log\\Writer\\File_Writer Acme\\Log\\Writer ./acme-log-writer/lib/ ./acme-log-writer/lib/File_Writer.php \\Aura\\Web\\Response\\Status Aura\\Web /path/to/aura-web/src/ /path/to/aura-web/src/Response/Status.php \\Symfony\\Core\\Request Symfony\\Core ./vendor/Symfony/Core/ ./vendor/Symfony/Core/Request.php \\Zend\\Acl Zend /usr/includes/Zend/ /usr/includes/Zend/Acl.php 关于本规范的实现,可参阅 相关实例 注意:实例并不属于规范的一部分,且随时会有所变动。\n","permalink":"https://huifeng.me/posts/php%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83-%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/","tags":["php"," TheRightWay"," PHP之道"," PSR"," 编码规范"],"title":"PHP编码规范-学习笔记"},{"categories":["Mac"],"contents":"为了装hexo-cli,需要先装配好npm环境和Git环境,于是接触到了npm的安装难的问题,我在Ubuntu系统上遇到的问题是个别目录无权限访问,我在Mac上也遇到了同样的问题,有建议是用root权限取安装就好了,但是我不想这样,这样势必是影响了我的操作习惯,root的根目录和非root用户的根目录不同的.所以我这么做了:\nsudo chown -R [你的当前用户名] /usr/local 如果你已经安装了很多了,建议直接删除掉项目里的node_moudles,重新安装.\n最后,如果你感到网速不给力,可以试试拜托大中华局域网的中国镜像,如:cnodejs或taobao.org\n如果你生除中国,更建议你用cnpm,它和npm同步更新的,足够你使用了:\nnpm install -g cnpm --registry=http://registry.npm.taobao.org 或\nnpm install -g cnpm 最后,感谢NPM维护者提供解决方案:https://github.com/npm/npm/issues/5922\n参考文献:关于MacOSX使用NPM的姿势补充\n","permalink":"https://huifeng.me/posts/macosx%E5%AE%89%E8%A3%85npm%E7%BB%8F%E9%AA%8C%E8%B0%88/","tags":["Mac"," npm"," node"," 安装"],"title":"MacOSX安装NPM经验谈"},{"categories":["PHP"],"contents":"这种情况一般是因为权限问题导致的,最开始遇到这种情是用linuxeye的一键遇到的,共享出来和本地映射的文件夹里的php代码不能被解析,在虚拟机里查看文件夹环境,发现都是www的用户和用户组,但是怎么改都改不过来,在宿主机上怎么改owner也是徒劳,怎么办呢?\n在Linux中运行的服务都会使用特定的用户,可以在各自的配置文件中修改:\n Nginx的工作进程默认会使用nginx这个用户 php-fpm工作进程默认会使用php-fpm这个用户 linuxeye一键包是www这个用户和用户组 如果是vagrant架设的虚拟linux建议做如下修改:\n linuxeye的一键包: sudo vim options.conf\n将run_user=www修改为run_user=vagrant\n或修改php-fpm配置:sudo vim /usr/local/php/etc/php-fpm.conf\n 自己架设的: sudo vim /lnmp/conf/nginx.conf\n将user www www; 修改为user vagrant www;\n如果是php-fpm来解析php,那么要修改php-fpm进程的所有者:\nsudo vim /etc/php-fpm.d/www.conf\n类似的,将user = php-fpm 改为user = vagrant\n","permalink":"https://huifeng.me/posts/%E9%97%AE%E9%A2%98-%E8%83%BD%E8%A7%A3%E6%9E%90html%E4%BD%86%E4%B8%8D%E8%83%BD%E8%A7%A3%E6%9E%90php/","tags":["linux"," html"," php"," php-fpm"," nginx"," 用户"," 用户组"," vagrant"],"title":"'问题:能解析html但不能解析php'"},{"categories":["Linux"],"contents":" vagrant+virtualbox 安装虚拟机会遇到服务器内容修改了但是页面不变化的问题\n 关闭Nginx的sendfile一项的属性:\nsudo vim /etc/nginx/nginx.conf 找到sendfile,将on改为off,保存关闭文件.\n","permalink":"https://huifeng.me/posts/%E9%97%AE%E9%A2%98-%E6%80%8E%E4%B9%88%E4%BF%AE%E6%94%B9%E9%A1%B5%E9%9D%A2%E9%83%BD%E4%B8%8D%E7%94%9F%E6%95%88/","tags":["linux"," nginx"," sendfile"," vagrant"," virtualbox"," 虚拟机"],"title":"'问题:怎么修改页面都不生效'"},{"categories":["Tickets"],"contents":"Session目录的权限 php.ini文件里一般会定义session文件的路径,但是php-fpm配置文件会覆盖php.ini里的配置.\n在/etc/php-fpm.d/www.conf文件中,一般在底部会有session.save_path,这里就是session文件的保存位置了\n 知道谁在运行服务 在Linux中运行的服务都会使用特定的用户,可以在各自的配置文件中修改:\n Nginx的工作进程默认会使用nginx这个用户\n php-fpm工作进程默认会使用php-fpm这个用户\n 查看系统进程:ps aux\n查看php相关进程:ps aux | grep php\n同理,查看nginx进程:ps aux | grep nginx\n 错误日志:告诉您哪里出错了 Nginx主配置文件/etc/nginx/nginx.conf中有一行是error_log开头的,这里告诉了你日志都放到了哪里,使用sudo tail /var/log/nginx/error.log命令来查看日志的最后部分.(一般是这个目录位置,根据error_log指定位置确定)\nphp-fpm的主配置文件/etc/php-fpm.d/www.conf中有一行包含[error_log],该行开头是php_admin_value[error_log],它说明了php错误日志的位置,一般是/var/log/php-fpm/www-error.log\n","permalink":"https://huifeng.me/posts/%E5%B8%B8%E8%AF%86%E4%B8%8D%E5%B8%B8%E8%AF%86/","tags":["linux"," nginx"," php"," php-fpm"," ini"," session"," 权限"," 日志"," 服务"," ps"," error"," error_log"],"title":"常识不常识"},{"categories":["Linux"],"contents":"sudo vim /etc/nginx/conf.d/default.conf(编辑其他配置文件也可)\n在server{}里面再添加一个location区块,或在index 设置行的下面添加一行include laravel.conf;(linuxeye一键包的方式)\nlocation / { try_files $uri $uri/ /index.php?$query_string; } 字段 说明 try_files 试着打开一系列的东西,如果都不能打开就重定向到最后一个参数 $uri 看服务器有没有请求包含的那个文件,如果有就打开它,如果没有就进行下一项匹配 $uri/ 看服务器有没有请求的目录,如果有就打开它,如果没有就进行下一项匹配 /index.php?$query_string; 这个好理解,自行理解吧,反正就是传参数 ","permalink":"https://huifeng.me/posts/07-%E9%85%8D%E7%BD%AEnginx%E4%BC%AA%E9%9D%99%E6%80%81/","tags":["linux"," nginx"," rewrite"," 伪静态"],"title":"配置Nginx伪静态"},{"categories":["Linux"],"contents":" 运行less /etc/php-fpm.conf查看配置,include=/etc/php-fpm.d/*.conf一行说明只要在这个目录下的conf类型的文件都会被包含到配置里.该目录下会有一个www.conf的文件,为默认配置文件. listen = 127.0.0.1:9000表示监听地址,如果有请求是PHP脚本就发送到这个地址,可以理解为PHP脚本是通过该地址的服务来解析的.可以是IP地址加端口号,也可以用socket的方式,socket方式更安全些. 修改Nginx的配置文件,在之前已经添加了!文件是:/etc/nginx/conf.d/default.conf,通过vi编辑器继续修改,添加nginx对php类文件的解析设置: server{ listen 80;\t# 监听端口 server_name mynginx.bhl.local;\t# 服务名,可以理解为网站的域名 root /vagrant/app/default/;\t# 网站文件在服务器上的位置 index index.php index.html;\t# 需要让nginx自动识别的文件 location ~ \\.php$ { fastcgi_pass 127.0.0.1:9000;\t##服务器上PHP-fpm的fastcgi服务监听的地址 fastcgi_index index.php;\t##服务器上监听的默认入口文件 include fastcgi.conf;\t##该文件在/etc/nginx/fastcgi.conf ##是nginx自带的fastcgi配置 } } 最后可以运行sudo nginx -t来测试看nginx的配置是否语法正确. **注意:**这里容易犯错:location空格~ \\.php$空格{这两个空格别落下!!\n","permalink":"https://huifeng.me/posts/06-%E9%85%8D%E7%BD%AEnginx%E5%A4%84%E7%90%86php%E8%AF%B7%E6%B1%82/","tags":["linux"," nginx"," php"," php-fpm"," fastcgi"," 测试"],"title":"配置Nginx处理PHP请求"},{"categories":["Linux"],"contents":"完全DIY配置的情况 默认情况下是安装在/etc/nginx目录下的:nginx.conf是主配置文件,里面有一个server区块是默认的,刚安装好打开的默认页面就是这里所设定的.include /etc/nginx/conf.d/*.conf;一行就是将所有conf.d目录下的所有.conf的配置文件全部加载进来,这样的话,我们要配置新的虚拟目录只需要将在该目录下添加.conf的配置文件即可,不同的站点可以是不同的配置文件.可以先配置一个模板型conf文件,比如我们可以先把自带的default.conf文件配置下:\nsudo vi /etc/nginx/conf.d/default.conf\nserver{ listen 80; #监听80端口 server_name default.myweb.local; #如果收到这个域名的请求直接引导到root目录去解析 root /vagrant/app/default/; #vagrant神器让我们实现本地开发虚拟机环境运行 index index.php index.html; } 设定的配置是否正确?输入命令测试:sudo nginx -t\n设置完毕需要重启nginx服务来启用新配置:sudo systemctl reload nginx\n下面设定主机名和IP地址的对应关系,设定好了才可以让一些自定义域名在访问的时候指向我们制定的IP地址, 然后让Nginx解析并引导至指定的服务器目录.\nlinux、Unix、MacOS系统编辑文件:sudo vi /etc/hosts\nwindows系统编辑文件:C:\\Windows\\System32\\Drivers\\etc\\hosts\n# 下面是定义的样例 192.168.33.33 default.myweb.local 这样,当你在本地浏览器输入default.myweb.local的时候就会访问nginx设定好的网站了,当然,你可以ping一下网址看看指向的IP地址是否正确.\n用\u0026quot;linuxeye\u0026quot;一键包的情况 安装位置有所不同,一键包都是安装在/usr/local下的,配置文件就在对应的目录下,如果实在找不到建议看看lnmp目录下的options.conf文件\n","permalink":"https://huifeng.me/posts/05-%E9%85%8D%E7%BD%AEnginx%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA/","tags":["linux"," nginx"," vhost"," 虚拟主机"," 配置"],"title":"配置Nginx虚拟主机"},{"categories":["Linux"],"contents":"这个简单,直接上命令:\nsudo yum install -y nginx 启动服务:sudo systemctl start nginx\n检查服务:systemctl status nginx\n设为启动项:sudo systemctl enable nginx\n","permalink":"https://huifeng.me/posts/04-%E5%AE%89%E8%A3%85web%E6%9C%8D%E5%8A%A1%E5%99%A8nginx/","tags":["linux"," nginx"],"title":"安装Web服务器:Nginx"},{"categories":["Linux"],"contents":"yum search php | grep fpm 可以找到一行是php56u-fpm.x86_64,就安装这个:\nsudo yum install -y php56u-fpm 用sudo systemctl start php-fpm启动php-fpm,用systemctl status php-fpm来看服务是否起来,用sudo systemctl enable php-fpm来将服务作为启动项同系统一起启动。\ncentos 6 设定开机启动:\nsudo chkconfig --add php-fpm sudo chkconfig php-fpm on 在基于Debian的发行版中你可以使用 update-rc.d:\nupdate-rc.d php-fpm defaults 下面我们安装常用扩展:\nsudo yum install -y php56u-gd php56u-mysqlnd php56u-pdo php56u-mcrypt php56u-mbstring php56u-xmlrpc php56u-pecl-jsonc php-cli的mcrypt扩展的安装 php-cli就是在命令行中输入php命令时执行的php,php -v可以看到版本,php -m可以看到已经安装和加载的模块\n如果你发现没有mcrypt ,可以运行:\nsudo apt-get install mcrypt\nsudo apt-get install php5-mcrypt\n此时,如果没有意外,你php -m依然没有mcrypt模块,怎么办呢?\n这是我查到的帮到我的页面 -\u0026gt; 短链接 原链接\n我做了以下两步就成了:\n cd /etc/php5/cli/conf.d ln -s ../../mods-available/mcrypt.ini 20-mcrypt.ini ","permalink":"https://huifeng.me/posts/03-%E5%AE%89%E8%A3%85php%E4%B8%8E%E5%B8%B8%E7%94%A8%E6%89%A9%E5%B1%95/","tags":["linux"," php"," php-fpm"," mcrypt"," php-cli"],"title":"安装PHP与常用扩展"},{"categories":["Linux"],"contents":" Maria数据库具体可以搜索看,完全可以替代了MySQL数据库,推荐使用MySQL原作者以自己女儿命名的开源数据库Maria,MySQL被Oracle收下了。恩恩。。\n 注意,能运行下面的命令,前提是你已经成功添加了资源仓库,并且是CentOS 7.X,如果是6.X,建议直接跳到最后一项.\n这里开始安装,命令行:\nsudo yum install -y mariadb100u-server mariadb100u 安装完毕后可能会有错误提示:\n错误:mariadb100u-config conflicts with 1: mariadb-libs-.......x86_64 这个冲突说明系统已经安装了Maria数据库,删除老的数据库:\nsudo yum remove -y mariadb-libs 然后再执行一遍安装命令:\nsudo yum install -y mariadb100u-server mariadb100u 命令执行完毕,mariadb应该就已经安装好了,我们现在启动该服务:\nsudo systemctl start mariadb 服务成功启动后查看下服务状态:\nsystemctl status mariadb 如果Active:选项显示active(running)说明服务运行正常,下面我们将服务设为启动项:\nsudo systemctl enable mariadb 然后在命令行输入mysql_secure_installation设置mariadb的安全选项:\n 第一个提示是问数据库系统的密码,这个一般为空,所以直接回车; 第二个提问应该是是否设置root用户的密码,输入y回车,接着命令行提示我们设置密码; 以此类推,第三个提问应该是是否删除匿名用户,我选择y; 是否禁用root用户的远程登陆,我选择y; 是否要删除test这个数据库,我选择y; 最后提示是否要重新加载权限,我选择y; 这样,我们就完成了mariadb的安装配置,登陆试试:\nmysql -u root -p show databases; 这里特别说说如果是CentOS 6.X怎么YUM安装MariaDB CentOS6.6也可以成安装资源仓库,但是即使你安装了,yum search mariadb也是搜不到mariadb的,我就遇到了这样的问题,解决办法:\n 访问这里:repository generator 选择你的系统,复制粘贴网站提供的代码,我的是CentOS 6 32位: 将代码复制到文件中,这个文件默认应该不存在,需要自己建立,sudo vim /etc/yum.repos.d/MariaDB.repo:\n# MariaDB 10.0 CentOS repository list - created 2015-08-21 11:06 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-x86 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 好了,现在应该可以安装了 sudo yum install MariaDB-server MariaDB-client ","permalink":"https://huifeng.me/posts/02-%E5%AE%89%E8%A3%85%E6%95%B0%E6%8D%AE%E5%BA%93%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9Fmariadb-or-mysql/","tags":["linux"," MySQL"," MariaDB"," Maria"," 安全选项"],"title":"安装数据库管理系统MariaDB(MySQL)"},{"categories":["Linux"],"contents":"由于centos自带的资源仓库里资源的版本不够新,所以我们选择添加两个资源仓库.\n虚拟机从 https://github.com/chef/bento 找,安装好后,进行下面的步骤:\n这里我安装了centos7.1版本\n下面开始:\n 访问网站:http://iuscommunity.org =\u0026gt; Repos\n在页面的最下方找到了CentOS 7 对应的两个连接,分别点开,复制关键连接(Packages下面),然后:\nsudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm sudo rpm -Uvh https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-14.ius.centos7.noarch.rpm Uvh表示显示安装的信息和安装进度\n最后,看下系统仓库的列表:yum repolist,包含epel/x86_64和ius/x86_64两个仓库说明一切正常.\n","permalink":"https://huifeng.me/posts/01-%E6%B7%BB%E5%8A%A0%E8%B5%84%E6%BA%90%E4%BB%93%E5%BA%93/","tags":["linux"," lnmp"," epel"," ius"," 资源仓库"," Uvh"," Repos"],"title":"添加资源仓库"},{"categories":["Linux"],"contents":"常用指令 ls 显示文件或目录 -l 列出文件详细信息l(list) -a 列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir 创建目录 -p 创建目录,若无父目录,则创建p(parent) cd 切换目录 touch 创建空文件 echo 创建带有内容的文件。 cat 查看文件内容 cp 拷贝 mv 移动或重命名 rm 删除文件 -r 递归删除,可删除子目录及文件 -f 强制删除 find 在文件系统中搜索某文件 wc 统计文本中行数、字数、字符数 grep 在文本文件中查找某个字符串 rmdir 删除空目录 tree 树形结构显示目录,需要安装tree包 pwd 显示当前目录 ln 创建链接文件 more、less 分页显示文本文件内容 head、tail 显示文件头、尾内容 ctrl+alt+F1 命令行全屏模式 设定开机启动 参考:https://mariadb.com/kb/zh-cn/iniciando-e-parando-mariadb-automaticamente/\nUbuntu\n服务启动:sudo /etc/init.d/mysql start或service mysql start\nCentOS 6\n在基于RPM的发行版系统(like Fedora and CentOS), 可以使用 chkconfig配置开机启动:\nchkconfig --add mysql chkconfig [--level 345] mysql on [\u0026ndash;level 345]为可选项\n系统管理命令 stat 显示指定文件的详细信息,比ls更详细 who 显示在线登陆用户 whoami 显示当前操作用户 hostname 显示主机名 uname 显示系统简要信息 -a 显示系统完整信息 top 动态显示当前耗费资源最多进程信息 ps 显示瞬间进程状态 ps aux -ef 显示系统常驻进程 du 查看目录大小 du -h /home带有单位显示目录信息 df 查看磁盘大小 df -h 带有单位显示磁盘信息 ifconfig 查看网络情况 ping 测试网络连通 netstat 显示网络状态信息 man 显示命令手册 clear 清屏 alias 对命令重命名 如:alias showmeit=”ps aux” ,另外解除使用unaliax showmeit kill 杀死进程,可以先用 ps 或 top 命令查看进程的id,然后再用kill命令杀死进程。 打包压缩相关命令 gzip: bzip2: tar: 打包压缩 -c 归档文件 -x 解压缩文件 -z gzip压缩文件 -j bzip2压缩文件 -v 显示压缩或解压缩过程 v(view) -f 使用档名 例:\n tar -cvf /home/abc.tar /home/abc 只打包,不压缩\n tar -zcvf /home/abc.tar.gz /home/abc 打包,并用gzip压缩\n tar -jcvf /home/abc.tar.bz2 /home/abc 打包,并用bzip2压缩\n如果想解压缩,就直接替换上面的命令 tar -cvf / tar -zcvf / tar -jcvf 中的“c” 换成“x” 就可以了。 关机/重启机器 shutdown -r 关机重启 -h 关机不重启 now 立刻关机 halt 关机 reboot 重启 init 0 立刻关机 init 6 重启 Linux管道 将一个命令的标准输出作为另一个命令的标准输入。也就是把几个命令组合起来使用,后一个命令处理前一个命令的输出结果。\n 例:grep -r “close” /home/* | more 在home目录下所有文件中查找,包括close的文件,并分页输出。\n 例: cat text.txt \u0026gt; tmp.txt 或 echo \u0026quot;something\u0026quot; \u0026gt; tmp.txt 会把前面的输出内容 覆盖 到tmp.txt里.\n 例: cat text.txt \u0026gt;\u0026gt; tmp.txt 或 echo \u0026quot;something\u0026quot; \u0026gt;\u0026gt; tmp.txt 会把前面的输出内容 追加 到tmp.txt里.\n Linux软件包管理 dpkg (Debian Package)管理工具,软件包名以.deb后缀。这种方法适合系统不能联网的情况下。 比如安装tree命令的安装包,先将tree.deb传到Linux系统中。再使用如下命令安装。\nsudo dpkg -i tree_1.5.3-1_i386.deb 安装软件 sudo dpkg -r tree 卸载软件 注:\n 将tree.deb传到Linux系统中,有多种方式。VMwareTool,使用挂载方式;使用winSCP工具等; APT(Advanced Packaging Tool)高级软件工具。这种方法适合系统能够连接互联网的情况。\n 依然以tree为例:\nsudo apt-get install tree 安装tree sudo apt-get remove tree 卸载tree sudo apt-get update 更新软件 sudo apt-get upgrade 将.rpm文件转为.deb文件\n.rpm为RedHat使用的软件格式。在Ubuntu下不能直接使用,所以需要转换一下。\nsudo alien filename.rpm\n vim使用 vim三种模式:命令模式、插入模式、编辑模式。使用ESC或i或:来切换模式。\n命令模式下:\n :q 退出 :q! 强制退出 :wq 保存并退出 :set number 显示行号 :set nonumber 隐藏行号 /apache 在文档中查找字符apache,按n跳到下一个,shift+n上一个 yyp 复制光标所在行,并粘贴 h(左移一个字符←)、j(下一行↓)、k(上一行↑)、l(右移一个字符→) 用户及用户组管理 /etc/passwd 存储用户账号 /etc/group 存储组账号 /etc/shadow 存储用户账号的密码 /etc/gshadow 存储用户组账号的密码 useradd user 添加用户 userdel user 删除用户 groupadd user 添加组用户 groupdel user 删除组用户 passwd root 给用户root设置密码 su root 临时提权到root用户 su – root 切换到root用户 /etc/profile 系统环境变量 bash_profile 用户环境变量 .bashrc 用户环境变量 su user 切换用户,加载配置文件.bashrc su – user 切换用户,加载配置文件/etc/profile ,加载bash_profile 更改文件的用户及用户组 sudo chown [-R递归] owner[:group] {File|Directory}\n要想切换文件所属的用户及组。可以使用命令:\nsudo chown root:root rarlinux-x64-5.1.b3.tar.gz\n文件权限管理 三种基本权限\nR 读 数值表示为4\nW 写 数值表示为2\nX 可执行 数值表示为1\n更改权限 sudo chmod [u所属用户 g所属组 o其他用户 a所有用户] [+增加权限 -减少权限] [r w x] 目录名\n例如:有一个文件filename,权限为“-rw-r—-x” ,将权限值改为”-rwxrw-r-x”,用数值表示为765\nsudo chmod u+x g+w o+r filename\n上面的例子可以用数值表示\nsudo chmod 765 filename\n","permalink":"https://huifeng.me/posts/linux-common-commands/","tags":["linux"," 命令"," vim"],"title":"Linux 系统常用命令"}]