开发环境配置

开发环境配置

Tags
debian
develop environment
Published
July 5, 2020
本文主要介绍以 debian 作为开发机时的一些准备,也作为一个 cheat sheet 在需要时可供快速查阅。

配置代理

export http_proxy="http://192.168.3.163:8001"; export HTTP_PROXY="http://192.168.3.163:8001"; export https_proxy="http://192.168.3.163:8001"; export HTTPS_PROXY="http://192.168.3.163:8001";
ssh 代理连接远程服务器
ssh -o "ProxyCommand nc -X 5 -x proxy_host:proxy_port %h %p" -p 54321 remote_user@remote_host # 示例 ssh -o "ProxyCommand nc -X 5 -x 127.0.0.1:1081 %h %p" -p 54321 node_ipcm@us10.april.com # 将代理配置写到 ssh 配置文件中(mac) ➜ ~ sed -i '' "1i \\ dquote> ProxyCommand nc -X 5 -x 127.0.0.1:1081 %h %p \\ dquote> " ~/.ssh/config
apt-get 配置代理
apt-get -o Acquire::http::proxy="http://192.168.3.163:8001/" update vi /etc/apt/apt.conf.d/10proxy #这个文件正常不存在,会新建一个 #编辑内容为: Acquire::http::Proxy "http://user:pwd@192.168.3.163:8001";

配置

静态 ip

➜ ~ cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet static address 192.168.3.90 netmask 255.255.255.0 gateway 192.168.3.1

samba

apt-get install samba
  1. 配置smb,打开配置文件
➜ tail /etc/samba/smb.conf # Please note that you also need to set appropriate Unix permissions # to the drivers directory for these users to have write rights in it ; write list = root, @lpadmin [debian_x64] comment = debian_x64 path = / browseable = yes valid user = root writeable = yes guest ok = yes
  1. 添加smb的用户,smbpasswd -a root
  1. 配置完成后,需要重启samba服务器
service samba restart
  1. 连接 samba 服务器
  • window 下:win + R,输入debian的IP,输入用户名root,与密码。 就会看到一个共享文件,然后右键共享文件,选择映射到电脑上。这样方便使用。
  • mac下:finder 连接服务器,smb://xxx.xxx.xxx.xxxx,macos 下会有 ip 反查域名的问题,因此先修改 host 为:
$(samba server ip) $(domain.xxxx.com) # 192.168.3.254 april32.april.com # 通过 smb://april32.april.com 连接 samba 服务器

配置 rsync

  1. 生产公钥、私钥
ssh-keygen -t rsa -b 4096 cat ~/.ssh/id_rsa.pub
  1. 将公钥内容复制到远程主机用户根目录下的 .ssh/authorized_keys 目录下
  1. 配置 exclude.list
➜ cat ~/exclude.list .svn/* .git/* node_modules/* conf/* conf_node/*
  1. rsync 命令:
rsync -avz --exclude-from=~/exclude.list -e "ssh -p 22" $(local_dir) $(remote_user)@$(remote_ip):$(remote_dir)
示例,将本地的 project 目录同步到远程用户 june 的根目录下:
rsync -avz --exclude-from="/home/develop/exclude.list" -e "ssh -p 22" ~/project june@127.0.0.1:~

软件安装

zsh

sudo apt-get install zsh
安装 oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

tmux

将 tmux 的功能键 Ctrl+b 改为 Ctrl+z
> vi ~/.tmux.conf set -g prefix C-z unbind C-b bind C-z send-prefix
重载配置文件:
> source-file ~/.tmux.conf
快捷键:
  • Ctrl+b %:划分左右两个窗格。
  • Ctrl+b ":划分上下两个窗格。
  • Ctrl+b <arrow key>:光标切换到其他窗格。
    • 是指向要切换到的窗格的方向键,比如切换到下方窗格,就按方向键
  • Ctrl+b ;:光标切换到上一个窗格。
  • Ctrl+b o:光标切换到下一个窗格。
  • Ctrl+b {:当前窗格左移。
  • Ctrl+b }:当前窗格右移。
  • Ctrl+b Ctrl+o:当前窗格上移。
  • Ctrl+b Alt+o:当前窗格下移。
  • Ctrl+b x:关闭当前窗格。
  • Ctrl+b !:将当前窗格拆分为一个独立窗口。
  • Ctrl+b z:当前窗格全屏显示,再使用一次会变回原来大小。
  • Ctrl+b option+<arrow key>:按箭头方向调整窗格大小。
  • Ctrl+b q:显示窗格编号。

编译工具

apt-get install build-essential apt-get install make # update-alternatives 管理多版本gcc/g++ # 查看 gcc/g++ 版本 ls /usr/bin/gcc* # 添加新的 alternatives 组 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 49 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 49 # 查看gcc/g++软链接指向 ls -la /usr/bin/gcc # /usr/bin/gcc -> /etc/alternatives/gcc ls -la /etc/alternatives/gcc # /etc/alternatives/gcc -> /usr/bin/gcc-4.9 # 显示命令 <name> 信息及目标文件 update-alternatives --display gcc # 配置命令版本 sudo update-alternatives --config gcc # 移除系统中注册的某个<name>的某个软件版本<path> sudo update-alternatives --remove gcc /usr/bin/gcc-4.9

gcc 增加编译高亮

  • colorgcc让编译器的输出信息彩色高亮,
  • colormake 则可以为make增加高亮色彩
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' # 安装 colormake 和 colorgcc sudo apt-get install colormake colorgcc

nvs 安装node

export NVS_HOME="$HOME/.nvs" git clone https://github.com/jasongin/nvs --depth=1 "$NVS_HOME" . "$NVS_HOME/nvs.sh" install

vscode remotessh

  1. vscode 安装 remote development 插件
  1. 远程 Linux 主机有 curl 命令
  1. 配置 ssh,参考配置 rsync 部分
  1. 打开 vscode 的 command,输入 remote,连接到远程主机

docker

nginx

1.读取配置文件,/etc/nginx/nginx.conf 表示读取到本地的配置文件路径
docker run --name tmp-nginx-container -d nginx docker cp tmp-nginx-container:/etc/nginx/nginx.conf /host/path/nginx.conf docker rm -f tmp-nginx-container
2.启动
docker run --name mynginx-web-all -p 8000:80 -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v $(local_dir):/usr/share/nginx/html -d nginx

内网穿透

  1. 安装 autossh
    1. wget http://www.harding.motd.ca/autossh/autossh-1.4e.tgz ./configure make make install
  1. 通过有公网 IP 的主机建立 ssh 隧道
    1. autossh -M 5000 -NfR 9000:localhost:22 -p 54321 user@host
      • -p 54321 user@host: ssh 跳板机的配置,自动登录参考配置 rsync 部分
      • -M: 表示监听 ssh 自动连接的端口
       
      • -NfR: 表示跳板机的 9000 端口和本地的 ssh 端口 22 建立隧道
  1. 配置开机启动
    1. 编辑 /etc/rc.local 文件,添加上述 autossh 语句:
      autossh -M 5000 -NfR 9000:localhost:22 -p 54321 -i /root/.ssh/april april@host.april-zhh.cn
  1. 赋予执行权限
    1. > chmod +x /etc/rc.local
  1. ssh 客户端自身也具有发送心跳包维持连接的能力
    1. ssh -o TCPKeepAlive=yes -o ServerAliveInterval=300 -D 9527 -f -C -q -N user@host -p 54301