【Linux】装机常用配置

15 篇文章 1 订阅


0. 可能遇到的问题

只有配置需求的同学可以直接跳过。

  • 问题 1 :在安装过程中 yum 突然报错 Error: Nothing to do 异常,提示Could not retrieve mirrorlist httpxxxx,网页打开url果然是失效的(deprecated)。另外,报错前下载的最后一个包是 scl。
    • 分析:yum 源里下载的 scl 会生成两个 .repo 文件,里面提及到的 url 就是上述提到的已经失效的链接。至于为什么会失效,貌似是 centos 7 在 2024 年 6 月 30 日后就不再维护,旧版本的链接已经无法使用。
    • 解决:👉来自一位老哥的博客
cd /etc/yum.repos.d

在这里插入图片描述
- 注意:这里面的注释 # 后面一定要留一个空格!!!!注释才会有效!!!


1. 下载常用软件包

yum install -y tree
yum install -y nano
yum install -y man man-pages
yum install -y zip unzip
yum install -y gcc-c++ libstdc++-devel

2. 更新yum源

cd /etc/yum.repos.d
mv CentOS-Base.repo backup_CentOS-Base.repo
wget http://mirrors.aliyun.com/repo/Centos-7.repo
mv Centos-7.repo CentOS-Base.repo
yum clean all
yum makecache

3. vim编辑器配置

  • 每个用户都需要单独配置,登入需要用户
cd
curl -sLf https://gitee.com/HGtz2222/VimForCpp/raw/master/install.sh -o ./install.sh && bash ./install.sh
(需要输入root的密码)
source ~/.bashrc // 按照”提示“输入指令

4. 安装C语言和C++的静态库(换root)

yum install glibc-static -y libstdc++-static

5. git

git --version(有的话就不用装了)
yum install -y git

6. sudo给普通用户提权

yum -y install sudo
vim /etc/sudoers
/**
*  ## Allows people in group wheel to run all commands
* %wheel  ALL=(ALL)       ALL
* tsq ALL=(ALL)       ALL    #这里就需要添加的地方
**/
// :wq! 强制退出
// 切换成普通用户后 sudo vim/etc/sudoers 能正常查看则成功

7. 更新git版本(centos默认安装1.8.x,我们更新到2.x)

sudo yum -y remove git
sudo yum -y remove git-*
sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
sudo yum -y install git
git version

8. getch

yum install -y ncurses ncurses-devel

9. json

yum makecache fast
yum -y install jsoncpp-devel

10. 升级gcc版本(4.8升级到7.x)

注意: centos7 及以前版本在第一步结束后 yum 会失效,请跳转至 第 0 小节

sudo yum install -y centos-release-scl-rh centos-release-scl
sudo yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++
source /opt/rh/devtoolset-7/enable 
echo "source /opt/rh/devtoolset-7/enable" >> ~/.bashrc
#查看版本情况
gcc -v
g++ -v

11. 跨系统数据传输

sudo yum install -y lrzsz

12.解决报错【g++: internal compiler error: Killed (program cc1plus)Please submit a full bug report,with preprocessed source if appropriate.】

  • 原因:内存满了
  • 方式:交换分区

【设置并启用分区】

  • 查看内存状态,下面的Swap也就是虚拟内存全为0
free -m
  • 该命令表示在opt分区建立名为swap,大小为1G的虚拟内存文件
sudo dd if=/dev/zero of=/opt/swap bs=1024 count=1024000
  • 修改swap目录的权限(可能权限不同,看报错提示)
sudo chmod 600 /opt/swap
  • 设置swap为分区
mkswap /opt/swap
  • 激活swap,启用分区交换文件
swapon /opt/swap

【关停分区】

  • 停止swap分区
swapoff /opt/swap
  • 其次删除掉swap文件
swapoff /opt/swap

13.ProtoBuf 的安装

  • 安装依赖库
sudo yum install -y autoconf automake libtool curl make gcc_c++ unzip
  • 下载编译器
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.9/protobuf-all-21.9.zip
  • 执行 autogen.sh(如果下的是all的需要这一步,单独的语言不需要这一步)
./ autogen.sh
  • 修改安装目录,统一安装在 /usr/local/protobuf 下(直接运行./configure更方便,不过 lib和bin就会是分散的)
./configure --prefix=/usr/local/protobuf
  • 执行,前两个花费15min左右
make
make check
sudo make install

13.2解决报错 make check:FAIL: protobuf-test
增大虚拟机内存 or 分区设置


14. docker的安装

【配置仓库】

  • 安装config-manager命令,配置仓库的工具所在工具包
sudo yum install -y yum-utils
  • 配置repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • 把/etc/yum.repos.d/docker-ce.repo里的gpgkey替换成国内镜像源(中科大)
sudo sed -i 's@//download.docker.com@//mirrors.ustc.edu.cn/docker-ce@g' /etc/yum.repos.d/docker-ce.repo

【安装docker】

sudo yum install -y docker-ce docker-ce-cli containerd.io dockerbuildx-plugin docker-compose-plugin

【验证】

  • 配置加载
sudo systemctl daemon-reload
  • 启动服务
sudo systemctl start docker
  • 开启启动(视需求添加)
sudo systemctl enable docker
  • 查看服务状态
sudo systemctl status docker
  • 运行docker
sudo docker run hello-world

15. cgroup的相关命令

  • pidstat命令
sodu yum install sysstat -y
  • stress命令
yum install stress -y

16. nginx 安装

  • centos 配置 nginx 源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  • 查看yum源
ll /etc/yum.repos.d
  • 配置源后建议构建缓存,加速下载
yum makecache
  • 下载
yum install -y nginx
  • 查看是否启动
ps -ef |grep nginx
  • 没有启动的话直接使用命令
nginx
  • 检查版本
nginx -v
  • 11
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值