1、配置阿里云yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && yum clean all && yum makecache fast
2、开机加载网络ip、时间、防火墙、selinux等状态
curl -L https://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master/os/status.sh > /etc/profile.d/status.sh
或
git clone https://gitea.com/NingGuru/docker.git && sh docker/*
夜莺
git clone https://gitea.com/NingGuru/n9e.git
3、网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPADDR=10.20.157.100
PREFIX=24
GATEWAY=10.20.157.1
DNS1=114.114.114.114
DNS2=8.8.8.8
DEVICE="ens33"
ONBOOT="yes"
4、二进制计算
`128 64 32 16 8 4 2 1`
`例:181计算`
`1 0 1 1 0 1 0 1`
`Windows ip地址:10.36.181.18`
`二进制:00001010.00100100.10110101.00010010`
`net ip地址:192.168.42.128`
`二进制:11000000.10101000.00101010.10000000`
5、mysql版本更换(脚本用)
yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
yum repolist all |grep mysql
yum install -y yum-utils
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
#安装必要的软件包
[root@mysql ~]# yum -y groupinstall "Development Tools"
[root@mysql ~]# yum -y install mysql-community-server
从日志中找出密码(有可能没有密码)
[root@mysql ~]# grep "password" /var/log/mysqld.log
6、关闭防火墙和selinux
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config && setenforce 0
systemctl stop firewalld && systemctl disable firewalld
7、新机器基本配置
curl -L https://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master/os/get-os-init.sh | sh
8、查询登录用户所执行的命令
curl https://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master/os/get-cmd-history.sh >/etc/profile.d/history.sh
在/usr/share/.history查看
9、vim添加自定义个人信息
cat >/root/.vimrc << EOF
set ignorecase
set nu
set paste
set cursorline
set cursorcolumn
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e")== 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"#")
call setline(3,"############################################################")
call setline(4,"#Author: 行走的CD")
call setline(5,"#vx/Tel: 15596320353")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"############################################################")
call setline(9,"")
endif
endfunc
autocmd BufNewFile *normal G
EOF
10、记录哪个用户登录执行了什么命令
脚本:
USER_IP=$(echo -e "`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`")
IP=$(who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g')
USER=$(whoami)
USER_NAME=`echo -e "$(whoami)"`
HISTFILESIZE=100000
HISTSIZE=4096
HISTTIMEFORMAT="%F %T $USER_IP $USER_NAME "
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d /var/log/history ]
then
mkdir /var/log/history;
chmod 777 /var/log/history
fi
if [ ! -d /var/log/history/${LOGNAME} ]
then
mkdir /var/log/history/${LOGNAME};
chmod 300 /var/log/history/${LOGNAME}
fi
DT=`date +%Y%m%d_%H%M`
chmod 600 /var/log/history/${LOGNAME}/* 2>/dev/null
export PROMPT_COMMAND='{ date "+%Y-%m-%d %T ###### $(history 1 | { read x cmd; echo "$cmd";})"; } >> /var/log/history/${LOGNAME}/${DT}_${USER}_${IP}'
将此脚本追加至/etc/profile
source /etc/profile
[root@linshi history]# ll /var/log/history/
total 60
d-wx------ 2 root root 45056 Feb 7 17:47 root
[root@linshi history]# ll /var/log/history/root|more
total 2
-rw------- 1 root root 1559 Jan 24 2022 20220124_1741_root_30.1.1.1 #生成的记录以年、月、日、小时、分钟,具体操作用户以及登陆服务器时的源ip地址
-rw------- 1 root root 6787 Jan 24 2022 20220124_1754_root_30.1.1.5
11、一键安装docker脚本
curl -L https://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master/os/get-docker-latest.sh | sh
git clone https://gitea.com/NingGuru/docker.git
sh docker/docker.sh
# 1. 清理现有环境
sudo yum remove -y docker docker-common docker-selinux docker-engine
# 2. 安装依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 3. 添加阿里云 Docker CE 镜像源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 4. 更新缓存
sudo yum makecache fast
# 5. 查看可用版本
yum list docker-ce --showduplicates | sort -r
# 6. 安装指定版本(选择一个可用的版本)
sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io
# 7. 启动 Docker
sudo systemctl start docker
sudo systemctl enable docker
# 8. 验证安装
docker --version
12.docker镜像加速
vim /etc/docker/daemon.json添加
"registry-mirrors": ["https://docker.rainbond.cc"]
systemctl restart docker
13.查看所有访问本机的IP以及次数
netstat -nplta | awk -F ':' '{print $2}' | awk '{for (i=1;i<=NF;i++) count[$2]++ } END {for (i in count) print i, count[i]}' | sort -k 2 -n
14.升级docker-compose
curl -L https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
source ~/.bash_profile
source ~/.profile
15.docker/docker-compose安装
wget -O - https://gitea.com/NingGuru/docker/raw/commit/6c0b68782f803ba132226ad108b68f88a8e78f28/docker-new.sh | bash
16.VPN安装
1、wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
2、下载证书下载openvpn客户端
3、导入证书连接即可进行远程访问局域网会或者魔法上网等
17.FlowMaster - 开源的专业的网络流量监控系统
curl -o install.sh https://gh-proxy.com/https://raw.githubusercontent.com/vbskycn/FlowMaster/main/install.sh && chmod +x install.sh && sudo ./install.sh
18.alist
网盘转存工具
docker run -d --restart=unless-stopped -v /etc/alist:/opt/alist/data -p 5244:5244 -e PUID=0 -e PGID=0 -e UMASK=022 --name="alist" registry.cn-hangzhou.aliyuncs.com/always-on-line/alist:latest
19.python镜像源
清华大学TUNA镜像源: https://pypi.tuna.tsinghua.edu.cn/simple
阿里云镜像源: http://mirrors.aliyun.com/pypi/simple/
中国科学技术大学镜像源: https://mirrors.ustc.edu.cn/pypi/simple/
华为云镜像源: https://repo.huaweicloud.com/repository/pypi/simple/
腾讯云镜像源:https://mirrors.cloud.tencent.com/pypi/simple/
设为默认:
python -m pip install --upgrade pip
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
评论区