http://mirrors.163.com/centos/ https://www.centos.org/download/
linux系统为了安全将内存分用户区与内核区两大部分, 内核区域加载OS相关代码,不允许用户直接访问,提供了一系列接口, 外部设备,比如磁盘,音响,耳机都有驱动程序, 这些驱动程序可直接加载到内核中运行, 并告诉内核该如何运行这些设备
|
linux
[python@localhost ~]$ cat /etc/os-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.5 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.5"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.5
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.5"
ubuntu
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
|
|
linux
$ ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
Ubuntu
$ ldd --version
ldd (Ubuntu GLIBC 2.39-0ubuntu8.6) 2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
|
|
linux $ gcc -dumpversion 4.8.5 ubuntu $ gcc -dumpversion 13 =========================================================================== |
|
|
|
|
### gcc 安装 sudo yum -y install gcc gcc-c++ kernel-devel 对于 centos7,此命令安装的gcc版本是4.8.5 # gcc -dumpversion 4.8.5 ### gcc 升级-10 yum install centos-release-scl yum install devtoolset-10-gcc* /usr/bin/scl enable devtoolset-10 bash # gcc -dumpversion 10 ### gcc 升级-8 yum install centos-release-scl yum install devtoolset-8-gcc* /usr/bin/scl enable devtoolset-8 bash 其中下面这句话要加入服务器的启动项中,因为每次重启,GCC又会回到4.8.5;或者在编译文件时,重新手工执行 scl enable devtoolset-8 bash 或者将新安装的gcc通过软链接放到/bin下面 查看glibc版本 xt@xt:~$ ldd --version ldd (Ubuntu GLIBC 2.36-0ubuntu4) 2.36 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper. glibc版本升级 ### gcc 升级-10 yum install centos-release-scl yum install devtoolset-10-gcc* /usr/bin/scl enable devtoolset-10 bash # gcc -dumpversion 10 $ ldd --version ldd (GNU libc) 2.17 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper. # 升级 make(默认为3 升级为4) [root@nd make-4.3]# make --version GNU Make 3.82 Built for x86_64-redhat-linux-gnu wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz tar -xzvf make-4.3.tar.gz && cd make-4.3/ ./configure --prefix=/usr/local/make make && make install cd /usr/bin/ && mv make make.bak ln -sv /usr/local/make/bin/make /usr/bin/make # make --version GNU Make 4.3 wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz tar xf glibc-2.28.tar.gz cd glibc-2.28/ && mkdir build && cd build make all yum whatprovides libstdc++.so.6 yum update -y libstdc++.x86_64 sudo wget http://www.vuln.cn/wp-content/uploads/2019/08/libstdc.so_.6.0.26.zip unzip libstdc.so_.6.0.26.zip cp libstdc++.so.6.0.26 /lib64/ cd /lib64 # 把原来的命令做备份 cp libstdc++.so.6 libstdc++.so.6.bak rm -f libstdc++.so.6 # 重新链接 ln -s libstdc++.so.6.0.26 libstdc++.so.6 cd glibc-2.28/build ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin make make install |
sudo yum install centos-release-scl 安装所需版本的GCC(假设SCL仓库中有与7.3.0相近的版本,如devtoolset-7,实际使用时需替换为具体版本号): sudo yum install devtoolset-7-gcc devtoolset-7-gcc-c++ 注意:由于SCL仓库中可能不包含GCC 7.3.0,因此你需要查找并安装最接近的版本。 scl enable devtoolset-7 bash echo 'source scl_source enable devtoolset-7' >> ~/.bashrc source ~/.bashrc 源码安装 sudo yum groupinstall "Development Tools" sudo yum install wget bzip2 gcc-c++ make wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz tar -xzvf gcc-7.3.0.tar.gz cd gcc-7.3.0 ./contrib/download_prerequisites 如果遇到下载问题,可以检查并修改脚本中的下载地址,然后重新执行脚本 mkdir build cd build ../configure --prefix=/usr/local/gcc-7.3.0 --enable-languages=c,c++ --disable-multilib make -j$(nproc) # nproc命令用于获取CPU的核数,以加速编译过程 sudo make install echo 'export PATH=/usr/local/gcc-7.3.0/bin:$PATH' >> ~/.bashrc source ~/.bashrc |
xt@qisan:~$ ldd --version
ldd (Ubuntu GLIBC 2.39-0ubuntu8.6) 2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
|
|
|
|
Cannot find a valid baseurl for repo: base/7/x86_64 # cat /etc/resolv.conf # Generated by NetworkManager nameserver 192.168.228.41 nameserver 2409:8900:30e3:fc5::3e 改为 nameserver 8.8.8.8 这么改的确有用了,但原来不改的时候也执行成功过
|
mkdir /etc/yum.repos.d/backup && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
# 阿里云镜像源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache
yum repolist # 检查仓库列表是否正常加载
### 依赖安装
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel \
sqlite-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel \
libffi-devel gcc-c++ libstdc++-devel python-devel
yum install -y net-tools libaio numactl
yum -y install gcc gcc-c++ autoconf make
|
|
|
|
|
|
|
离线包安装 rpm -qa | grep readline-devel rpm -qa | grep zlib-devel yum search readline-devel mkdir -p /opt/soft/pg/rpm_centos7 yum install --downloadonly --downloaddir=/opt/soft/rpm/ readline-devel.x86_64 rpm -Uvh --force --nodeps *.rpm
|
CentOS7开启SSH服务 yum install openssh-server vim /etc/ssh/sshd_config Port 22 #AddressFamily any ListenAddress 0.0.0.0 ListenAddress :: PermitRootLogin yes sudo service sshd start ps -e | grep sshd windows免密登录centos7 centos7上执行,一路回车,如果执行过就不用执行了 ssh-keygen -t rsa windows上安装一个git,进入git bash 执行 ssh-keygen -t rsa cd /c/Users/ cd Administrator/ cd .ssh/ scp id_rsa.pub xt@192.168.56.104:/home/xt/.ssh/ 进入centos7 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 授权600,只认这个权限 chmod -R 600 authorized_keys rm ~/.ssh/id_rsa.pub 登录测试 ssh xt@192.168.56.104
|
# 生成 SSH 主机密钥(如果尚未生成)
ssh-keygen -A
# 启动 sshd 守护进程(前台运行)
/usr/sbin/sshd -D
这样会避免依赖 Systemd/D-Bus。
|
(pyai) [root@ml aitpf]# sudo service sshd start Redirecting to /bin/systemctl start sshd.service Failed to get D-Bus connection: Operation not permitted mv /usr/bin/systemctl /usr/bin/systemctl.old curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl chmod +x /usr/bin/systemctl 还原 mv /usr/bin/systemctl.old /usr/bin/systemctl (pyai) [root@ml aiwks]# service sshd start Redirecting to /bin/systemctl start sshd.service rsync -avP /usr/bin/systemctl /mnt/g/soft/systemctl_centos7 (pyai) [root@ml aiwks]# netstat -tunlp|grep 1225 tcp 0 0 0.0.0.0:12251 0.0.0.0:* LISTEN 629/sshd tcp6 0 0 :::12251 :::* LISTEN 629/sshd |
# 基础语法 ssh -L [本地绑定地址:]本地端口:目标地址:目标端口 用户名@SSH服务器 -f:后台运行 -N:不执行远程命令,仅用于转发 -C:启用压缩 -v:详细输出,用于调试 远程端口转发(Remote Port Forwarding) # 基础语法 ssh -R [远程绑定地址:]远程端口:本地地址:本地端口 用户名@SSH服务器 # 实际示例:将本地Web服务暴露到公网 ssh -R 8080:localhost:80 user@vps.example.com # 解释:任何人访问 vps.example.com:8080 ≈ 访问你本机的 localhost:80 |
|
|
vim中文乱码
在/etc/vimrc文件最后追加 vim /etc/vimrc set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8
less查看中文乱码
在下面这种方式上切换一下 export LESSCHARSET=latin1 export LESSCHARSET=utf-8
命令行中文乱码
# locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= centos 6 yum groupinstall chinese-support centos 7 yum install kde-l10n-Chinese # vim /etc/sysconfig/i18n LANG="zh_CN.UTF-8" SYSFONT="latarcyrheb-sun16" reboot # locale LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8"
crontab时间格式
分 时 天 周 月 */1 * * * * 每分钟 1 1 * * * 每天1点1分
开机启动
@reboot ( sleep 30 ; bash /opt/scripts/os_init.sh )
python添加脚本到crontab
from tempfile import NamedTemporaryFile
import os
def add_crontab(task):
with os.popen("crontab -l", "r") as pipe:
current = pipe.read()
current += task
with NamedTemporaryFile("w") as f:
f.write(current)
f.flush()
os.system(f"crontab {f.name}")
def clear_crontab():
with NamedTemporaryFile("w") as f:
f.write("\n")
f.flush()
os.system(f"crontab {f.name}")
def get_crontab():
with os.popen("crontab -l", "r") as pipe:
current = pipe.read()
print(current)
get_crontab()
file = "/opt/tpf/aiwks/code/aisty/test/crontab1/py_scripts.py &"
task1 = f"40 16 * * * /home/xt/anaconda3/bin/python {file}\n"
add_crontab(task1)
get_crontab()
crontab每分钟效果展示
脚本/opt/tpf/aiwks/code/aisty/test/crontab1/py_scripts.py
import os
import time
now =time.strftime("%H:%M:%S")
os.system(f"echo {now} >> /tmp/a.log")
任务计划
$ crontab -l
*/1 * * * * /home/xt/anaconda3/bin/python /opt/tpf/aiwks/code/aisty/test/crontab1/py_scripts.py &
结果输出
14:29:01
14:30:01
14:31:02
crontab每天效果展示
每天14点45分执行脚本 任务计划 $ crontab -l 45 14 * * * /home/xt/anaconda3/bin/python /opt/tpf/aiwks/code/aisty/test/crontab1/py_scripts.py & 结果输出 14:45:01
|
时间同步
$ date
Sun Jun 25 01:41:52 CST 2023
$ sudo date -s "09:45:02"
Sun Jun 25 09:45:02 CST 2023
$ date
Sun Jun 25 09:46:56 CST 2023
|
sudo vim /etc/timezone
Asia/Shanghai
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date
|
|
|
|
|
|
|