Centos镜像下载

http://mirrors.163.com/centos/

https://www.centos.org/download/

Linux内核用户及设备

linux系统为了安全将内存分用户区与内核区两大部分,
内核区域加载OS相关代码,不允许用户直接访问,提供了一系列接口,

外部设备,比如磁盘,音响,耳机都有驱动程序,
这些驱动程序可直接加载到内核中运行,
并告诉内核该如何运行这些设备

GCC

### 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









yum

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

这么改的确有用了,但原来不改的时候也执行成功过

rpm离线包安装
离线包安装
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

ssh

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

linux中文乱码

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"


linux crontab

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

linux time

时间同步

    
$ 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 
    

 

    

 

    

 


 

  

 


参考文章