1.1,ubuntu设置ssh-agent进入shell时自动加载

一,添加自动加载脚本,vim /etc/profile.d/keychain.sh

# /etc/profile.d/keychain.sh
# 自动启动 ssh-agent 并加载多个私钥
export KEYCHAIN_HOME="/root/.keychain"
多个key,用英文空格拆分。例:export SSH_KEYS="/root/.ssh/id_rsa2 /root/.ssh/id_rsa3"
export SSH_KEYS="/root/.ssh/id_rsa2"
if [ -x /usr/bin/keychain ]; then
    eval $(/usr/bin/keychain --quiet --eval --agents ssh $SSH_KEYS)
fi
立即生效:  source /etc/profile
查看是否生效: ssh-add -l
验证: ssh -T git@github.com

1.2 ubuntu24必装命令

安装常用工具,执行:
apt update && apt -y install telnet plocate lrzsz zip unzip gcc g++ make perl iputils-ping net-tools git keychain dos2unix expect rsync sshpass nload ifstat build-essential clang pkg-config libssl-dev cargo p7zip-full
mysql8依赖:
apt -y install needrestart
apt -y install mecab-ipadic mecab-utils mecab-ipadic-utf8 libnuma1 libmecab2 psmisc

1.3 常用设置

查看所有时区:
timedatectl list-timezones
查看当前时区:
timedatectl
设置新加坡时区:
sudo timedatectl set-timezone Asia/Singapore

1.4 设置manager用户的通用环境变量

vim .run_with_env.sh
# 添加内容:
公共环境变量。 文件名: .run_with_env.sh
export FNM_HOME=/home/manager/program/fnm-linux
export JAVA_HOME=/home/manager/program/jdk1.8.0_461
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export MAVEN_HOME=/home/manager/program/apache-maven-3.9.12
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$FNM_HOME:$PATH
添加到 .bashrc  和 .profile 中
vim .bashrc
vim .profile
在最后添加内容:
公用环境变量
if [ -f "$HOME/.run_with_env.sh" ]; then
. "$HOME/.run_with_env.sh"
fi

2,windows用两个github账号

一,先创建RSA公私钥对

ssh-keygen -f ~/.ssh/id_rsa -N '' -t rsa -q -b 2048
生成一个旧格式的RSA公私钥对
ssh-keygen -f ~/.ssh/id_rsa6 -t rsa -b 4096 -m PEM -C "prod_jenkin_ubuntu24" -N ""
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

二,在C:\Users\当前用户\.ssh 目录下,创建文件 config,内容如下:

# 主账号(默认)abc16801
Host github.com-abc16801
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

# 副账号abc21
Host github.com-abc21
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa3
IdentitiesOnly yes

三,从github上拉取不同的github仓库

例1:要拉取 github平台的 abc16801 账户能访问的仓库 efg, 而efg所在的组织假设为 hijk

需要执行文件: git clone git@github.com-abc16801:hijk/efg.git

例1:要拉取 github平台的 abc21 账户能访问的仓库 efgh, 而efgh 所在的组织假设为 mnop

需要执行文件: git clone git@github.com-abc21:mnop/efgh.git

3,关于硬盘操作

3.1 在aws的EC2上面挂载附加的卷,即新买一个硬盘

4 网络

4.1 ubuntu24server安装好以后,设置网络

# 设置网络:sudo vim /etc/netplan/50-cloud-init.yaml 
# 权限设置 chmod 600 50-cloud-init.yaml
# 假设IP地址为:10.0.0.102
# 配置好以后,执行:sudo netplan apply 生效
network:
version: 2
renderer: networkd
ethernets:
ens18:
dhcp4: no
addresses: [10.0.0.102/24]
routes:
- to: default
via: 10.0.0.1
  nameservers:
    addresses:
      - 8.8.8.8
      - 223.5.5.5
      - 114.114.114.114

4.2 非ubuntu24版本:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens18:              # ← 改成你的网卡名
      dhcp4: no
      addresses:
        - 10.0.0.10/16  # ← 你的内网 IP
      gateway4: 10.0.0.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 223.5.5.5

配置好以后,执行:sudo netplan apply 生效

5,文件相关

5.1 ulimit文件句柄设置为1048576

vim /etc/sysctl.conf 添加如下内容: fs.file-max = 1048576

保存后,生效: sudo sysctl -p

再执行: vim /etc/security/limits.conf 添加内容:

* soft nofile 1048576
* hard nofile 1048576
root soft nofile 1048576
root hard nofile 1048576

然后执行:vim /etc/systemd/system.conf 添加内容:

DefaultLimitNOFILE=1048576

查看参数: ulimit -n

临时设置: ulimit -n 1048576

5.2 在PVE9上设置操作的Task超时时间。从10秒改成300秒

vim后搜索qemu_img_resize方法,将里面的时间【从10秒改为300秒】,用于解决在克隆VPS时,task处理超时的问题
vim /usr/share/perl5/PVE/Storage/Plugin.pm
vim /usr/share/perl5/PVE/Storage/Common.pm
然后重启pve虚拟服务:
systemctl restart pvedaemon
systemctl restart pveproxy
systemctl restart pvescheduler

6,在ubuntu上搭haproxy代理aws的aurora的mysql示例

一,环境
不要使用 include指令,ubuntu的haproxy默认不支持include指令。
假设aws的url为  abc.rds.amazonaws.com
mysql的对外端口是: 3306
代理机为: 11.22.33.55
代理机对外的mysql端口为: 3308
haproxy新添加的配置文件是: aurora_test_mysql.cfg
haproxy新添加的配置文件的路径是:  /etc/haproxy/aurora_test_mysql.cfg

二,常用命令

安装haproxy:  apt install -y haproxy
编辑命令:  sudo systemctl edit haproxy
重启命令:  sudo systemctl restart haproxy
systemctl重载: sudo systemctl daemon-reload
#配置,执行都成功后,通过 3308 来连接验证
#将nano改为vim, 执行: vim /etc/profile  然后添加内容:
export EDITOR=vim
export VISUAL=vim
执行命令:
echo 'EDITOR="vim"' | sudo tee -a /etc/environment
echo 'VISUAL="vim"' | sudo tee -a /etc/environment

三,添加配置文件。 vim aurora_test_mysql.cfg

# aurora test mysql8的域名链接的代理
# 文件名: aurora_test_mysql.cfg
resolvers dns
    nameserver ns1 8.8.8.8:53
    nameserver ns2 1.1.1.1:53
    resolve_retries 3
    timeout resolve 5s
    timeout retry 1s
    hold valid 30s
frontend mysql_front
bind *:3308
mode tcp
default_backend mysql_back
backend mysql_back
mode tcp
server rds abc.rds.amazonaws.com:3306 check resolvers dns resolve-prefer ipv4 init-addr none

四,修改systemctl的haproxy启动。执行命令: systemctl edit haproxy 添加内容如下

# systemctl edit haproxy
[Service]
ExecStart=
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/aurora_test_mysql.cfg
ExecReload=
ExecReload=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/aurora_test_mysql.cfg -c -q
配置完成后, 执行nano的保存+退出命令: ctrl+o, ctrl+x

五,重新启动haproxy

 

配置完成后,执行以下命令使新配置生效:

sudo systemctl restart haproxy

sudo systemctl daemon-reload



重启后建议验证代理是否正常:

sudo systemctl status haproxy

六,配置crontab定时停止 haproxy

执行命令: crontab -e  添加:
*/30 * * * * systemctl stop haproxy

## end

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐