常用配置

2022/1/22 Utils

# 1. Docker

# 1.1 安装

sudo pacman -S docker

# 1.2 配置非root账户

sudo groupadd docker			# 创建Docker组
sudo gpasswd -a ${USER} docker 	# 将用户加入Docker组
sudo systemctl restart docker	# 重启Docker

配置完成后记得退出当前用户重新登陆

# 1.3 国内源

阿里云镜像地址 (opens new window)

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["阿里云分配的镜像加速器地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

# 1.4 常用镜像

Mysql

docker run -itd --name mysql -v 自己的路径/conf.d:/etc/mysql/conf.d -v 自己的路径/logs:/logs -v 自己的路径/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --restart=always mysql:8.0

如果需要修改配置文件,直接在映射的conf.d目录下新建my.cnf即可

Nginx

  1. 准备几个目录

    ├── nginx.conf -- 主配置文件
    ├── html 
    	└──  index.html -- 存放 nginx 默认 index.html
    ├── conf.d 
    	└──  default.conf -- 默认的子配置文件
    └── log -- nginx 日志存放目录
    
  2. 填写配置文件

    nginx.conf

    # nginx.conf 官方原文件
    
    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/conf.d/*.conf;
    }
    

    default.nginx

    # default.conf 官方原文件
    
    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
    
  3. 启动容器

    docker run --name nginx -d -p 80:80 -v 自己的路径/html:/usr/share/nginx/html -v 自己的路径/nginx.conf:/etc/nginx/nginx.conf -v 自己的路径/conf.d:/etc/nginx/conf.d -v 自己的路径/log:/var/log/nginx nginx:1.21.6
    

Redis

任意目录下新建

# 存放数据
data
# redis的配置文件
conf/redis.conf

redis.conf

# 注释bind表示允许远程连接
#bind 127.0.0.1
protected-mode no
# 持久化
appendonly yes
# 密码
requirepass 123456

docker启动

docker run --name redis -p 6379:6379 -v ~/redis/data:/data -v ~/redis/conf/redis.conf:/etc/redis/redis.conf -d redis:6.2.6 redis-server /etc/redis/redis.conf

如果遇到警告

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect
sudo vim /etc/sysctl.conf

# 文件末尾添加
vm.overcommit_memory=1

# 立即生效
sudo sysctl -p

jenkins

docker run -u root --name jenkins -d -p 8080:8080 -v ~/jenkins:/var/jenkins_home jenkinsci/blueocean:1.25.3

国内源进入updates目录,执行(切换为root用户后执行)

sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

zookeeper

docker run --name zookeeper -d -e TZ="Asia/Shanghai" -p 2181:2181 -v ~/zookeeper:/data zookeeper:3.5.9

# 2. Maven

# 2.1 国内源

<mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

# 3. Python

# 3.1 国内源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 4. Node

# 4.1 npm国内源

npm config set registry https://registry.npmmirror.com

# 4.2 NVM国内源

settings.txt中加入

node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
sass_binary_site=https://npmmirror.com/mirrors/node-sass
chromedriver_cdnurl=https://npmmirror.com/mirrors/chromedriver
phantomjs_cdnurl=https://npmmirror.com/mirrors/phantomjs
electron_mirror=https://npmmirror.com/mirrors/electron

# 5. Git

# 5.1 生成秘钥

ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"

# 5.2 配置账户

用户名

git config --global user.name "Your name"

密码

git config --global user.email "Your eamil"

# 6. Java

# 6.1 安装

Oralce官网 (opens new window)下载

解压

sudo tar -zxvf jdkxxx.tar.gz -C /usr/local/lib/

配置环境变量

vim /etc/profile

输入

export JAVA_HOME=/usr/local/lib/jdkxxx
export PATH=$PATH:$JAVA_HOME/bin

# 7. Gradle

# 7.1 使用本地maven仓库

设置环境变量为本地maven仓库地址即可

GRADLE_USER_HOME

# 7.1 全局国内源

USER_HOME/.gradle/下创建init.gradle文件

allprojects{
    repositories {
        def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
        def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
            }
        }
        maven {
            url ALIYUN_REPOSITORY_URL
            url ALIYUN_JCENTER_URL
        }
    }
}

# 8. powershell

# 8.1 设置代理

检查代理

netsh winhttp show proxy

设置代理(需要管理员权限)

netsh winhttp set proxy "127.0.0.1:8889"

清除代理(需要管理员权限)

netsh winhttp reset proxy

# 8.2 查找端口

# 查找8001端口的占用情况
netstat -aon|findstr 8001

# 杀死PID为18376的进程
taskkill /T /F /PID 18376

# 9. oh-my-zsh

  1. 下载码云安装包

    wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
    
  2. 编辑下载的文件install.sh

    REPO=${REPO:-ohmyzsh/ohmyzsh}
    REMOTE=${REMOTE:-https://github.com/${REPO}.git}
    # 修改为
    REPO=${REPO:-mirrors/oh-my-zsh}
    REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
    
  3. 授予可执行权限

    sudo chmod a+x install.sh
    
  4. 安装

    ./install.sh
    
  5. 修改更新镜像源

    cd ~/.oh-my-zsh
    git remote set-url origin https://gitee.com/mirrors/oh-my-zsh.git
    git pull
    
  6. 添加语法高亮以及自动补全插件

    git clone https://github.com.cnpmjs.org/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
    
    git clone https://github.com.cnpmjs.org/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    

    修改~/.zshrc

    vim ~/.zshrc
    
    plugins=(
            git
            zsh-syntax-highlighting
            zsh-autosuggestions
    )
    

# 10. rust

linux下安装

curl https://sh.rustup.rs -sSf | sh

遇到错误安装一个库文件

sudo apt install libc6-dev
最后修改时间: 5 minutes ago