分类 环境 下的文章

  1. SSH禁用密码登录,修改端口

    # 复制公钥到服务器
    vi ~/.ssh/authorized_keys
    # 修改sshd配置文件
    Port 1234
    PermitRootLogin prohibit-password
    PubkeyAuthentication yes
    PasswordAuthentication no
    ChallengeResponseAuthentication no
    # 重启ssh服务
    systemctl restart ssh
    service ssh restart
  2. 同步Git公钥

    # 生成SSH密钥对
    ssh-keygen -t rsa -b 4096 -C "****@gmail.com"
    # 将SSH公钥添加到Git服务
    cat ~/.ssh/id_rsa.pub
  3. 安装Docker

    Debian install docker

  1. 查看Pod镜像tag

    kubectl describe pod -n <namespace> <podname>
  1. 通过Dockerfile编写相同tag的镜像

    FROM <docker_image_name>:<docker_image_tag>
    ADD ./test.txt /opt/test.txt
    docker build . --tag=<docker_image_name>:<docker_image_tag>
  1. 通过K8s更新pod

    kubectl get pod  -n <namespace> <podname> -o yaml | kubectl replace --force -f -

在子系统中获取Win10宿主机的IP
cat /etc/resolv.conf|grep nameserver|awk '{print $2}'

添加代理 nano ~/.bashrc

export PROXY_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export PROXY_PORT=1001

alias proxy='
    export https_proxy="http://${PROXY_IP}:${PROXY_PORT}";
    export http_proxy="http://${PROXY_IP}:${PROXY_PORT}";
    echo "Acquire::http::Proxy \"http://${PROXY_IP}:${PROXY_PORT}\";" | sudo tee /etc/apt/apt.conf.d/proxy.conf > /dev/null;
    echo "Acquire::https::Proxy \"http://${PROXY_IP}:${PROXY_PORT}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null
'

alias unproxy='
    unset https_proxy;
    unset http_proxy;
    rm -f /etc/apt/apt.conf.d/proxy.conf
'

开放WSL网卡防火墙使子系统能够访问宿主机

New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

Hyper-V虚拟机使用宿主机代理

vim ~/.bashrc

export hostip=$(cat /etc/network/interfaces|grep gateway| awk '{print $2}')

alias proxy='
    export https_proxy="http://${hostip}:port";
    export http_proxy="http://${hostip}:port";'

alias unproxy='
    unset https_proxy;
    unset http_proxy;'

# 取消文件跟踪
git rm -r --cached folder_name
# 撤销本地commit
git reset HEAD~
# 撤销刚刚的push(会覆盖别人提交的代码)
git reset --soft HEAD~1
git push origin <分支名> --force
# ssh 错误:no matching cipher found. Their offer: aes128-cbc
# 在ssh config中添加行Ciphers +aes128-cbc
Ciphers +aes128-cbc,aes256-cbc,3des-cbc

git pull时忽略本地文件变动冲突

方法1

# 暂存本地更改
git stash
# 拉取远程分支更新
git pull
# 恢复暂存的更改
git stash pop

方法2

# 强制拉取并覆盖本地更改
git fetch --all
git reset --hard origin/你的分支名

方法3

# 保存未提交的更改
git diff > my_changes.patch
# 撤销本地更改
git reset --hard
# 拉取远程分支更新
git pull
# 应用之前保存的更改
git apply my_changes.patch

方法4

git pull -X theirs  # 使用远程分支的版本
# 或
git pull -X ours    # 使用本地分支的版本

  1. Supervisor官网
  2. 安装pip install supervisor
  3. 配置

    • 生成默认配置echo_supervisord_conf > /etc/supervisord.conf
    • 自定义配置
    ;django-channels配置
    [fcgi-program:my_channels]
    socket = tcp://0.0.0.0:2020
    directory = /home/my_channels
    numprocs = 8
    process_name = my_channels_2020-%(process_num)d
    command = /root/.virtualenvs/my_channels/bin/daphne -u /home/my_channels/runtime/my_channels_2020-%(process_num)d.sock --fd 0 --access-log - --proxy-headers my_channels.asgi:application
    autostart = true
    autorestart = true
    stdout_logfile = /home/my_channels/logging/my_channels.log
    stdout_logfile_maxbytes = 50MB
    stdout_logfile_backups = 10
    redirect_stderr = true
    priority = 997
    user = root
    killasgroup = true
    stopasgroup = true
    startsecs = 15
    ;CeleryWorker配置
    [program:celery-worker-my_channels]
    command = /root/.virtualenvs/my_channels/bin/celery -A my_channels worker -l info -Q default,manager
    directory = /home/my_channels
    stdout_logfile = /home/my_channels/logging/celery-worker-my_channels.log
    stdout_logfile_maxbytes = 50MB
    stdout_logfile_backups = 10
    stderr_logfile = /home/my_channels/logging/celery-worker-my_channels-error.log
    stderr_logfile_maxbytes = 50MB
    stderr_logfile_backups = 10
    autostart = true
    autorestart = true
    priority = 997
    user = root
    killasgroup = true
    stopasgroup = true
    redirect_stderr = true
    startsecs = 15
    ;Celery定时任务配置
    [program:celery-beat-my_channels]
    command = /root/.virtualenvs/my_channels/bin/celery -A my_channels beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
    directory = /home/my_channels
    stdout_logfile = /home/my_channels/logging/celery-beat-my_channels.log
    stdout_logfile_maxbytes = 50MB
    stdout_logfile_backups = 10
    stderr_logfile = /home/my_channels/logging/celery-beat-my_channels-error.log
    stderr_logfile_maxbytes = 50MB
    stderr_logfile_backups = 10
    autostart = true
    autorestart = true
    priority = 997
    user = root
    killasgroup = true
    stopasgroup = true
    redirect_stderr = true
    startsecs = 15

    启动命令supervisord -c /etc/supervisord.conf
    更新配置supervisorctl update

方法一:

pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
#pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

方法二:

家目录创建.pip文件夹
mkdir ~/.pip
cd ~/.pip
创建pip.conf
touch pip.conf
vi pip.conf
编辑写入下列代码
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn

# 更新pip
pip3 install --upgrade pip
# 安装virtualenv、virtualenvwrapper
pip3 install virtualenv
pip3 install virtualenvwrapper
# 进入.bash_profile文件中,定义virtualenvwrapper路径
vim ~/.bashrc
# 文末添加代码
VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3.6    # virtualenvwrapper执行的python版本路径
export WORKON_HOME=$HOME/.virtualenvs    # 虚拟环境存放目录
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python3/bin/virtualenv    # virtualenv所在目录
source /usr/local/python3/bin/virtualenvwrapper.sh    # virtualenvwrapper.sh所在目录
# Python版本的路径用
which python3
虚拟环境存放目录可自定义
# virtualenv所在目录用
find / -name virtualenv
# virtualenvwrapper.sh所在目录可用
find / -name virtualenvwrapper.sh
# 重新加载配置文件
source ~/.bashrc
# 创建虚拟环境
mkvirtualenv py3
# 进入虚拟环境
workon py3
# 快速配置环境
pip install -r requirements.txt

yum -y groupinstall "Development tools"
# apt-get install build-essential
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
# 安装位置
cd /usr/local
# 下载Python3.6.8
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
# 解压
tar -xf Python-3.6.8.tar.xz
# 创建安装文件夹
mkdir python3
mv Python-3.6.8 python3
cd python3/Python-3.6.8
# 安装
./configure --prefix=/usr/local/python3 --enable-optimizations
make && make altinstall
# 创建软连接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3

清华大学安装教程

git安装

在终端中输入git,根据提示安装

brew安装

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

更换中科大更新源

  • 更换brew.git

    cd "$(brew --repo)"
    git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
  • 更换核心软件仓库(homebrew-core.git)

    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
  • 更换Home cask软件仓库

    cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
    # 如果未找到就不执行
    git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
  • 更换Home Bottles源
    bash终端:

    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
    source ~/.bash_profile

    zhs终端:

    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
    source ~/.zsh
  • 更新

    brew update

    重置默认源

  • 重置brew.git

    cd "$(brew --repo)"
    git remote set-url origin https://github.com/Homebrew/brew.git
  • 重置核心软件仓库

    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://github.com/Homebrew/homebrew-core.git
  • 重置Homebrew cask软件仓库

    cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
    git remote set-url origin https://github.com/Homebrew/homebrew-cask
  • 重置Homebrew Bottles源

    # 注释掉终端配置文件里的有关Homebrew Bottles即可恢复官方源。 重启终端或重读配置文件
  • mac系统从Sierra后,无法安装不被认可的软件,必须恢复“任何来源”

    sudo spctl --master-disable

查看已经安装的shell

cat /etc/shells

安装zsh

brew install zsh

设置默认shell

chsh -s /bin/zsh
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

配置zsh

vi ~/.zshrc

修改主题

ZSH_THEME="ys"

配置插件

cd .oh-my-zsh/plugins
  • zsh-syntax-highlighting语法高亮插件

    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
  • zsh-autosuggestions记录输入命令插件

    git clone https://github.com/zsh-users/zsh-autosuggestions.git

    在.zshrc中修改配置

plugins=(其他插件 zsh-syntax-highlighting zsh-autosuggestions) # 注意空格隔开
source ~/.zshrc
  • 报错

    Error: Oh My Zsh can't be loaded from: bash. You need to run zsh instead # 退出终端重进