Linux 重要配置和软件使用记录

12 minute

ftp

1apt install vsftpd
2systemctl status vsftpd

Hugo

1wget https://github.com/gohugoio/hugo/releases/download/v0.134.1/hugo_extended_0.134.1_linux-amd64.tar.gz
2tar -zxvf hugo_extended_0.134.1_linux-amd64.tar.gz

Startup

1# crontab -e
2@reboot  /root/startup.sh

v2ray

1# https://github.com/v2fly/fhs-install-v2ray
2bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
3# vim /usr/local/etc/v2ray/config.json

clash

1cd $code && mkdir clash && cd clash
2# 跑路了: wget https://github.com/Dreamacro/clash/releases/download/v1.11.8/clash-linux-amd64-v1.11.8.gz
3gzip -d clash-linux-amd64-v1.11.8.gz
4sudo mv clash-linux-amd64-v1.11.8 /usr/bin/clash
5chmod +x /usr/bin/clash
6wget -O config.yaml https://cop.stc-anycast.com/link/egTt2ZFed953e0m6?sub=3&client=clash
7nohup clash -d . >/dev/null 2>&1 &
8# config: clash.razord.top
 1# auto start: /etc/systemd/system/clash.service
 2[Unit]
 3Description=Clash Proxy
 4
 5[Service]
 6WorkingDirectory=/root
 7ExecStart=/usr/bin/clash -d /root/Codes/clash >/dev/null 2>&1
 8Type=simple
 9RemainAfterExit=yes
10
11[Install]
12WantedBy=multi-user.target
1systemctl daemon-reload
2systemctl start clash
3systemctl enable clash

mutt 邮件查看器

1apt install mutt

python-venv

1apt install python3-venv
2# xx/bin/python3 -m venv venv

git.io 短链生成

1curl -i https://git.io -F "url=https://raw.githubusercontent.com/akynazh/v2ray/master/install.sh" -F "code=v2ray.sh"

ElasticSearch

 1# 安装 8.12.0 版本
 2wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.12.0-linux-x86_64.tar.gz
 3wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.12.0-linux-x86_64.tar.gz.sha512
 4shasum -a 512 -c elasticsearch-8.12.0-linux-x86_64.tar.gz.sha512 
 5tar -xzf elasticsearch-8.12.0-linux-x86_64.tar.gz
 6cd elasticsearch-8.12.0/ 
 7# 安装 ik 中文分词器:
 8./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.12.0/elasticsearch-analysis-ik-8.12.0.zip
 9# 开启服务
10./bin/elasticsearch -d
11# 开启密码保护
12vim config/elasticsearch.yml
13xpack.security.enabled: true
14# 生成密码
15./elasticsearch-setup-passwords auto # 自动
16# ./elasticsearch-setup-passwords interactive # 手动

Github CLI

1type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
2curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
3&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
4&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
5&& sudo apt update \
6&& sudo apt install gh -y

Caddy

1sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
2curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
3curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
4sudo apt update
5sudo apt install caddy

安装后 caddy 默认启动,占用 80 和 2019 端口,其中 2019 为 admin api 调用地址,通过如下配置关闭该入口:

1# /etc/caddy/Caddyfile
2{
3  admin off
4}

服务配置:

 1# /etc/caddy/Caddyfile
 2
 3t.akynazh.site {
 4	# Set this path to your site's directory.
 5	# root * /usr/share/caddy
 6
 7	# Enable the static file server.
 8	# file_server
 9
10	# Another common task is to set up a reverse proxy:
11	# reverse_proxy localhost:1200
12    # reverse_proxy /api localhost:1200
13
14	# Or serve a PHP site through php-fpm:
15	# php_fastcgi localhost:9000
16
17    # test
18    respond "Hello, caddy!"
19}

Caddy serves public DNS names over HTTPS using certificates from a public ACME CA such as Let’s Encrypt or ZeroSSL.

Caddy keeps all managed certificates renewed and redirects HTTP (default port 80) to HTTPS (default port 443) automatically.

Let’s Encrypt

 1# not recommended
 2# apt install certbot
 3
 4# INSTALL
 5path_certbot=/usr/local/share/certbot
 6python3 -m venv $path_certbot
 7$path_certbot/bin/pip install certbot
 8ln -s $path_certbot/bin/certbot /usr/local/bin/certbot
 9
10# CERT
11certbot certonly --webroot -w /var/www/html -d akynazh.site -d www.akynazh.site
12# systemctl stop nginx # standalone mode need port 80 first
13certbot certonly --standalone -d api.akynazh.site # service
14
15# RENEW
16# renewal, add to crontab:
1730 2 5 * *  certbot renew --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx"
18# 30 2 5 * *  certbot renew

Nginx

1apt install nginx
 1; vim /etc/nginx/nginx.conf
 2worker_processes  2; # cpu * 1~2
 3
 4events {
 5    worker_connections  2048; # default 1024
 6}
 7
 8http {
 9    server {
10        listen 81;
11        listen [::]:81;
12
13        root /var/www/rss;
14        index index.html;
15
16        location / {
17            try_files $uri $uri/ =404;
18            # proxy_pass http://127.0.0.1:8000;
19        }
20    }
21}
1systemctl start nginx
2systemctl status nginx

RSSHub

 1git clone
 2pnpm install
 3# vim .env
 4# add some k=v
 5npm start
 6
 7# run in bg
 8npm install -g pm2
 9pm2 start lib/index.js --name rsshub
10pm2 stop rsshub
11
12# doc
13cd website
14pnpm i
15pnpm run start:zh # pnpm run start

lux

1# amd64
2wget https://github.com/iawia002/lux/releases/download/v0.22.0/lux_0.22.0_Linux_x86_64.tar.gz
3tar -zxvf lux_0.22.0_Linux_x86_64.tar.gz
4mv ./lux /usr/local/bin/
5lux -v

locate

1apt install mlocate
2updatedb
3locate "bot.py"
4
5# updatedb 需要手动执行,否则新文件不会被索引到

fzf

1apt install fzf
2fzf --version
3
4ctrl + r -> search command history
5fzf

ripgrep

1apt install ripgrep
2rg --version 
3
4rg -i "test"
5rg -ic "test"
6rg -uuu -ic "test"

bat

1# amd64
2wget https://github.com/sharkdp/bat/releases/download/v0.24.0/bat-musl_0.24.0_amd64.deb
3dpkg -i bat-musl_0.24.0_amd64.deb
4bat --version

Vim

1# /etc/vimrc # or: /etc/vim/vimrc
2
3set tabstop=4 # 修改vim中tab长度
4set shiftwidth=4 # 修改vim自动缩进长度
5set noeb vb t_vb= # 禁用vim蜂鸣声
6set number
1#/etc/inputrc
2
3set bell-style none # 禁用bash蜂鸣声

主机名称

1hostnamectl set-hostname xxx

登录欢迎信息

/etc/update-motd.d 自行修改基本欢迎信息。

命令提示符

1vim ~/.bashrc
2
3export PS1="[\u => \w]\$ "
 1\a	铃声字符
 2\d	格式为“日 月 年”的日期
 3\e	ASCII 转义字符
 4\h	本地主机名
 5\H	完全合格的限定域主机名
 6\j	shell 当前管理的作业数
 7\1	shell 终端设备名的基本名称
 8\n	ASCII 换行字符
 9\r	ASCII 回车
10\s	shell 的名称
11\t	格式为“小时:分钟:秒”的24小时制的当前时间
12\T	格式为“小时:分钟:秒”的12小时制的当前时间
13\A	格式为“小时:分钟”的24小时制的当前时间
14@	格式为 am/pm 的12小时制的当前时间
15\s	shell的名字
16\u	当前用户的用户名
17\v	bash shell 的版本
18\V	bash shell 的发布级别
19\w	当前工作目录
20\W	当前工作目录的基本名称
21!	该命令的 bash shell 历史数
22#	该命令的命令数量
23$	如果是普通用户,则为美元符号$;如果超级用户(root 用户),则为井号#。
24\nnn	对应于八进制值 nnn 的字符
25\	斜杠
26[	控制码序列的开头
27]	控制码序列的结尾

时区更改

系统时区修改

 1root@OranMe2474:~# timedatectl list-timezones | grep Shanghai
 2Asia/Shanghai
 3root@OranMe2474:~# timedatectl set-timezone Asia/Shanghai
 4root@OranMe2474:~# timedatectl
 5               Local time: Mon 2022-11-28 10:59:39 CST
 6           Universal time: Mon 2022-11-28 02:59:39 UTC
 7                 RTC time: n/a
 8                Time zone: Asia/Shanghai (CST, +0800)
 9System clock synchronized: yes
10              NTP service: inactive
11          RTC in local TZ: no

Crontab 时区修改

1# /etc/crontab
2
3CRON_TZ=Asia/Shanghai
4TZ=Asia/Shanghai
1systemctl restart cron

rclone

1# pp:Apps -> pikpak-login beta for rclone
2curl https://rclone.org/install.sh | sudo bash
3rclone -v
4rclone version
5## webdav
6## rclone copy local_path webdav:/
7## rclone sync local_path webdav:/local_path

pikpakcli

1wget https://github.com/52funny/pikpakcli/releases/download/v0.15/pikpakcli_0.15_Linux_x86_64.tar.gz
2tar -zxvf pikpakcli_0.15_Linux_x86_64.tar.gz
3mv ./pikpakcli /usr/bin/
4pikpakcli -h
5mkdir -p ~/.config/pikpakcli
6echo "username:" >> ~/.config/pikpakcli/config.yaml
7echo "password:" >> ~/.config/pikpakcli/config.yaml
8vim ~/.config/pikpakcli/config.yaml

iotop

IO top command

1apt install iotop
2## iostat top

jq

1## centos
2## yum install epel-release
3yum install jq
4## ubuntu
5apt install -y jq

Linux apt & yum

1apt update -y
2apt install curl wget vim net-tools  git nginx -y
3## apt install openssh*
4
5--------------------------------------------
6
7yum update -y
8yum install curl wget vim net-tools git nginx -y
9yum install openssh*

yum 镜像

 1## huawei
 2cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
 3wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
 4
 5## aliyun
 6## mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
 7## wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
 8
 9yum clean all
10yum makecache
11yum -y update

apt 镜像

Debian

1deb http://deb.debian.org/debian buster main contrib non-free
2deb http://deb.debian.org/debian buster-updates main contrib non-free
3deb http://deb.debian.org/debian buster-backports main contrib non-free
4deb http://security.debian.org/debian-security/ buster/updates main contrib non-free

Ubuntu

 1cp /etc/apt/sources.list /etc/apt/sources.list.bak
 2vim /etc/apt/sources.list
 3
 4lsb_release -c 查看版本代码
 5
 6如要用于其他版本,把 focal 换成其他版本代号即可: 22.04:jammy;20.04:focal;18.04:bionic;16.04:xenial;14.04:trusty。
 7
 8deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
 9deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
10deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
11deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
12
13---------------------------------------------
14
15deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
16deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
17deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
18deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

python3

pip

如果系统已经安装 python3 但未安装 pip:

1apt install python3-pip

安装

 1yum update
 2yum install wget gcc openssl-devel bzip2-devel libffi-devel -y
 3yum groupinstall "Development Tools" -y
 4wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz
 5tar -zxvf Python-3.10.2.tgz
 6cd Python-3.10.2
 7./configure --enable-optimizations
 8make altinstall
 9ln -sf /usr/local/bin/python3.10 /usr/bin/python3
10ln -sf /usr/local/bin/python3.10 /bin/python3
11ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3
12ln -sf /usr/local/bin/pip3.10 /usr/bin/pip
13
14------------------------------------------------------
15
16apt update
17apt install software-properties-common -y
18add-apt-repository ppa:deadsnakes/ppa && apt update
19apt install python3.10 -y
20ln -sf /usr/bin/python3.10 /usr/bin/python3
21curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py
22ln -sf /usr/local/bin/pip3.10 /usr/bin/pip

Pip 镜像配置

1pip config set global.index-url http://pypi.douban.com/simple
2pip config set install.trusted-host pypi.douban.com

遇到的问题

“ssl module in Python is not available” in CentOS

CentOS 7 and RHEL 7 ship an unsupported OpenSSL version. CentOS 7’s EPEL repository comes with openssl11 package. The package install files in non-standard locations and uses a custom pkgconf module name openssl11. You can patch Python’s configure script to use the custom build:

 1yum install -y epel
 2......
 3No package epel available.
 4yum search epel
 5......
 6================================ N/S matched: epel ================================
 7epel-release.noarch : Extra Packages for Enterprise Linux repository configuration
 8yum install epel-release.noarch
 9yum install -y openssl11-devel
10cd /path/to/cpython-sources
11sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
12./configure --enable-optimizations
13make altinstall

No module named ‘distutils.cmd’

1apt install python3-distutils -y

setup

python setup.py egg_info did not run successfully.

1pip install setuptools -U

lzma

ModuleNotFoundError: No module named ‘_lzma’ 解決方法:

1yum install xz-devel
2yum install python-backports-lzma
3pip install backports.lzma

找到 lzma.py,如日誌提示的 /usr/local/lib/python3.7/lzma.py,修改 zma.py 文件中的導入部份如下:

修改前:

1from _lzma import *
2from _lzma import _encode_filter_properties, _decode_filter_properties

修改後:

1try:
2    from _lzma import *
3    from _lzma import _encode_filter_properties, _decode_filter_properties
4except ImportError:
5    from backports.lzma import *
6    from backports.lzma import _encode_filter_properties, _decode_filter_properties

verysync

1curl http://www.verysync.com/shell/verysync-linux-installer/go-installer.sh > go-installer.sh
2chmod +x go-installer.sh
3./go-installer.sh

java

安装

1wget https://repo.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-x64.tar.gz
2tar -zxvf jdk-8u151-linux-x64.tar.gz
3sudo mkdir /usr/local/java
4sudo mv jdk1.8.0_151 /usr/local/java/jdk1.8

环境变量

1## java env
2export JAVA_HOME=/usr/local/java/jdk1.8
3export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
4export PATH=$PATH:$JAVA_HOME/bin

maven

安装

1maven_version="3.6.3" ## 3.9.4
2wget "https://archive.apache.org/dist/maven/maven-3/$maven_version/binaries/apache-maven-$maven_version-bin.tar.gz"
3sudo mkdir /usr/local/maven
4tar -zxvf apache-maven-$maven_version-bin.tar.gz
5sudo mv apache-maven-$maven_version /usr/local/maven/$maven_version
6
7## 环境变量
8## MAVEN_HOME=/usr/local/maven/{$maven_version}
9## export PATH=$PATH:$MAVEN_HOME/bin

镜像

1sudo vim ~/.m2/settings.xml
 1<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
 2    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
 4
 5    <mirrors>
 6        <mirror>
 7            <id>alimaven</id>
 8            <name>aliyun maven</name>
 9            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
10            <mirrorOf>central</mirrorOf>
11        </mirror>
12    </mirrors>
13</settings>

node

安装 node /npm

1apt install nodejs npm

(NVM) 安装和更新 node / npm

 1## install nvm pkg manager
 2export NVM_DIR="$HOME/.nvm" && (
 3  git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
 4  cd "$NVM_DIR"
 5  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
 6) && \. "$NVM_DIR/nvm.sh"
 7
 8# 添加一下脚本到 .*rc 文件中
 9export NVM_DIR="$HOME/.nvm"
10[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
11[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
12
13## close and reopen your terminal to start using nvm
14nvm install node ## This will install the latest version of Node.js and npm.
15
16node -v
17npm -v
18
19nvm current
20## list all the available versions of Node.js that you can install
21nvm ls-remote
22
23## Identify the latest version of Node.js and install it using the following command:
24nvm install <version>
25## nvm install 16.8.0
26
27## If you want to set the newly installed version of Node.js as the default version, you can run the following command:
28nvm alias default <version>

安装 yarn

1npm install -g yarn

安装 pnpm

1npm install -g pnpm

镜像

npm 设置为淘宝源:

1npm config set registry http://registry.npm.taobao.org/

npm 设置为默认源:

1npm config set registry https://registry.npmjs.org/

yarn 设置为淘宝源:

1yarn config set registry https://registry.npm.taobao.org

yarn 设置为默认源:

1yarn config set registry https://registry.yarnpkg.com

mysql

安装

1wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
3rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
4yum install mysql-community-server -y

配置root密码

vim /etc/my.cnf

1+ skip-grant-tables
1mysql
2flush privileges;
3alter mysql.user 'root'@'localhost' identified by 'xxxxxx';

vim /etc/my.cnf

1- skip-grant-tables

redis

 1yum install epel-release
 2yum install -y redis
 3
 4-------------------------------------
 5
 6apt install redis-server
 7
 8-------------------------------------
 9
10## 启动 Redis
11redis-server
12## 检查 Redis 是否正在运行
13redis-cli ping
14## 访问Redis
15redis-cli
16## 停止 Redis
17systemctl stop redis-server

c/c++

1yum install gcc -y
2yum install gcc-c++ -y
3yum install gdb -y

git

安装

1yum install git -y
2
3------------------------------------
4
5apt install git -y

配置密钥

将公钥手动部署到github

配置提交人信息

1git config --global user.name "akynazh"
2git config --global user.email "1945561232@qq.com"

http代理

1git config --global http.https://github.com.proxy socks5://127.0.0.1:7891

ssh代理

 1## ~/.ssh/config
 2
 3Host github.com
 4    User git
 5    Port 22
 6    Hostname github.com
 7    IdentityFile ~/.ssh/id_rsa
 8    ProxyCommand nc -v --proxy-type socks5 --proxy 127.0.0.1:7891 %h %p
 9
10Host ssh.github.com
11    User git
12    Port 443
13    Hostname ssh.github.com
14    IdentityFile ~/.ssh/id_rsa
15    ProxyCommand nc -v --proxy-type socks5 --proxy 127.0.0.1:7891 %h %p

unix系统使用nc(netcat)命令,若未安装netcat,需先安装:

1yum install nc

Go

1# apt install golang-go
2
3wget https://go.dev/dl/go1.22.4.linux-amd64.tar.gz
4
5export PATH="$PATH:/usr/local/share/go/bin"
6export GO111MODULE=on
7export GOPROXY=https://goproxy.io,direct
8export GOPATH=$HOME/.go