0%

全局配置 /usr/share/vim/vimrc,不建议修改。建议修改当前用户配置 ~/.vimrc,加载配置时会覆盖全局配置。

  • 我的Vim配置,我只是轻量级用户,不像某些大佬(变态)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
syntax on
set smartindent
set autoindent
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
set ic "搜索忽略大小写
set hlsearch
set incsearch
set number
set ruler
set cursorline
set nocompatible "关闭vi兼容
set nowrap "关闭超屏自动换行
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,GB2312,big5
filetype plugin indent on

nnoremap . $
nnoremap , ^
nnoremap <F2> :set number!<CR>
nnoremap <F3> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>
nnoremap <F4> :set wrap!<CR>
nnoremap <F5> :set hlsearch!<CR>

"自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction

Tips

  • 主要设置语法高亮、智能缩进、高亮搜索、显示行号、编码格式
  • 配置快捷键映射,,跳转到行首.跳转到行尾,F2开关显示行号,F3开关语法高亮,F4开关超屏换行,F5开关高亮搜索
  • nnoremap中n表示normal模式,i表示insert模式,nore表示no recursion非递归映射,<CR>表示回车
  • 最后是设置智能补全
  • .rc(run commands) 文件,通常在程序的启动阶段被调用

References

前言

Git 是目前世界上最先进的分布式版本控制系统。相比较CVS及SVN这种老式的集中式版本控制系统,要更加灵活方便,也更安全稳定。集中式是指版本库是放在中央服务器中,需要联网才能工作。分布式是指没有中央服务器,每个人电脑上有个完整的版本仓库,可以本地修改代码再联网提交到Git服务器上,Git服务器作用仅仅“交换”大家的修改即代码同步。此外,Git还拥有极其强大的分支管理功能。

Git 命令

本文主要介绍基础的 Git 命令,更加复杂的 Git 命令可以查看:Git 进阶教程。另外 Git 的常用命令文档可以参考:git-cheatsheet

创建仓库

始终要记住你的本地和Git服务器上都存在版本仓库(repository),Git实现代码同步实际上是同步你的本地仓库和远程仓库。有两种方式创建仓库:1. 从服务器上克隆一个仓库;2. 初始化一个本地仓库。

从Git服务器上克隆(clone)一个仓库下来,可以通过sshhttp的方式。ssh需要将你的公钥存放在Git服务器上,而http不需要但是速度相较ssh要慢。

1
2
git clone git@github.com:s1mplecc/MyHashMap.git
git clone https://github.com/s1mplecc/MyHashMap.git

从远程库克隆下来的是完整的版本库,含有.git文件夹,其下的config文件夹包括了本仓库的配置信息。包含了url、远程库的名字以及分支等:

1
2
3
4
5
6
7
8
➜ cat .git/config

[remote "origin"]
url = git@github.com:s1mplecc/MyHashMap.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
阅读全文 »

Preface

应公司需求,搭建Git和Maven的企业私服,Maven私服使用Nexus搭建。

Prerequisites

  • 一台服务器,4核8G、1TB硬盘,Ubuntu 16.04
  • apache-maven-3.5.2-bin.tar.gz
  • nexus-3.6.1-02-unix.tar.gz,官网下载
  • jdk-8u151-linux-x64.tar.gz

搭建Git

  • 安装Git,git --version查看版本

    1
    sudo apt-get install git
  • 创建git用户,该命令会创建git组、git用户,并设置/home/git为用户目录

    1
    adduser git
  • 为了安全,禁止git用户bash登录,vi /etc/passwd

    1
    git:x:1001:1001:,,,:/home/git:/bin/bash

    修改为

    1
    git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

Tips

git-shell : 提供了受限的git访问,只允许push/pull命令,官网解释:
This is a login shell for SSH accounts to provide restricted Git access. It permits execution only of server-side Git commands implementing the pull/push functionality, plus custom commands present in a subdirectory named git-shell-commands in the user’s home directory.

测试Git

  • /opt创建文件夹,mkdir git-repo,并cd进去

  • 初始化一个Git仓库,在当前目录下生成了一个空的Git仓库,包含了一些初始文件

    1
    git init --bare helloworld.git
  • 更改权限

    1
    chown -R git:git helloworld.git 
  • 将用户的ssh公钥加入到/home/git/.ssh/authorized_keys中,并重启sshd服务

  • 本地机器上将其clone下来

    1
    git clone git@{IP}:/opt/git-repo/helloworld.git

    会发现当前目录下多了个名为helloworld的文件夹

  • 现在我们添加一个文件,测试将其push到服务器上

    1
    2
    3
    4
    touch abc.txt
    git add .
    git commit -m "first commit"
    git push -u origin master
阅读全文 »

Preface

配置Nginx目录,可以很方便的下载镜像,查看文件等等

  • 效果图
    -----2017-11-19---10.54.27

Configure Nginx

  • 前往nginx配置目录

    1
    cd /etc/nginx/sites-enabled
  • vi dir_80.conf添加配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    server {
    listen 80;
    listen [::]:80;

    server_name dir.s1mple.info www.dir.s1mple.info;
    root /var/www/html;

    location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    autoindex on;
    autoindex_exact_size off;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/s1mple.info/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/s1mple.info/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    # Redirect non-https traffic to https
    if ($scheme != "https") {
    return 301 https://$host$request_uri;
    } # managed by Certbot

    }
  • service nginx restart重启nginx服务

Tips

  1. 监听80端口,域名为dir.s1mple.info和www.dir.s1mple.info
  2. 根目录为/var/www/html
  3. autoindex on打开目录浏览功能
  4. autoindex_exact_size默认为on,显示文件确切大小,单位bytes,改为off后显示大概大小,单位kB或者MB或者GB
  5. 剩下的是Certbot重定位https的配置

Configure Certbot

  • 重新配置Certbot

    1
    certbot run
  • 它会自动检测nginx的配置文件
    -----2017-11-19---10.31.17

  • 提示已经存在证书,并且已经配置了一些域名,询问是否扩充,选择E
    -----2017-11-19---10.32.45

  • 询问是否将HTTP重定位到HTTPS,选择2是所有请求均重定位到HTTPS
    -----2017-11-19---10.38.24

准备工作

服务器相关设置

三台服务器节点,采用一主二从的模式,需要修改主机名并建立服务器间的 ssh 通信便于各服务器间免密访问以及 scp 命令分发文件。

host相关设置

执行vi /etc/hostname修改主机名,主节点命名为master,从节点命名为slave01和slave02,执行reboot重启服务器生效。

三台服务器都修改/etc/hosts文件,IP地址为内网IP。

1
2
3
192.168.10.6 master
192.168.10.7 slave01
192.168.10.8 slave02

配置ssh免密通信

普通用户登录后,执行sudo passwd root修改root密码,su root切换为root用户。

阅读全文 »