Skip to content

Linux CentOS相关

Kervin edited this page Mar 16, 2022 · 3 revisions

一、系统

1.源镜像配置

OS Vesion Image LTS
Centos 7 -
查看系统版本
yum install -y redhat-lsb
lsb_release -a

输出

root@server:~# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.9 (Final)
Release:	7.9
Codename:	Final

2.数据源

cd /etc/yum.repos.d
wget http://mirrors.aliyun.com/repo/Centos-7.repo -O CentOS7-Base-aliyun.repo

3.更新数据源

rm -rf /var/cache/yum/*
yum clean all 
yum makecache 
yum update -y
yum upgrade -y

4.常用插件

yum install -y vim
yum install -y redhat-lsb
yum install -y net-tools
yum install -y sysstat
yum install -y atsar
yum install -y rpm
yum install -y zip
yum install -y gzip
yum install -y curl
yum install -y vim redhat-lsb  net-tools sysstat atsar rpm zip gzip curl

5.更改网卡

方式1:

cd /usr/lib/udev/rules.d/
cat 60-net.rules
#ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", PROGRAM="/lib/udev/rename_device", RESULT=="?*", NAME="$result"
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", ATTR{address}="00:0c:29:0b:6a:7d", NAME="eth0"

方式2

cd /etc/sysconfig/network-scripts/
mv ifcfg-ens33  ifcfg-eth0
vim ifcfg-eth0

修改网卡名称

vim /etc/sysconfig/grub

#GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"

修改注释部分

grub2-mkconfig -o /boot/grub2/grub.cfg

生成启动菜单

6.升级内核

rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh  http://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-ml

yum install kmod-r8168
yum --disablerepo=\* --enablerepo=elrepo install kmod-nvidia

二、第三方软件

1.jdk安装openjdk

yum install -y java-1.8.0-openjdk.x86_64

查看JDK目录

 ls -lrt /etc/alternatives/java 

安装jdk命令

 yum list |grep jdk-devel
 # 找对应版本安装如下
 yum install -y java-1.8.0-openjdk-devel.x86_64

2.Docker安装

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io

三、应用

1.docker

  • docker镜像更改
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux  docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ##修改在目录下修改文件名
yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo ##修改在目录下修改文件名
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef017c13.m.daocloud.io
  • nexus v2/v3 安装

v2 安装

docker run -d -p 8081:8081 --name nexus2 --restart=always sonatype/nexus:oss
docker ps -l
curl http://localhost:8081/nexus/service/local/status
docker build --rm=true --tag=sonatype/nexus .
docker logs -f nexus

v3 安装

docker run -d -p 8082:8082 --name nexus3 --restart=always sonatype/nexus3
curl -u admin:admin123 http://localhost:8081/service/metrics/ping
docker build --rm=true --tag=sonatype/nexus3 .
rspec [--backtrace] spec/Dockerfile_spec.rb
docker logs -f nexus
  • MySQL 安装
docker search mysql
docker run -d -p 3306:3306 --name mysql5.7 --restart=always -e MYSQL_ROOT_PASSWORD=root  mysql:5.7
#映射路径
docker run -d -p 3306:3306 --name mysql5.7 --restart=always -e MYSQL_ROOT_PASSWORD=root -v /home/docker/mysql/conf:/etc/mysql -v /home/docker/mysql/data:/var/lib/mysql -v /etc/localtime:/etc/localtime mysql:5.7

docker run -d -p 3308:3308 --name mysql8 --restart=always -e MYSQL_ROOT_PASSWORD=root  mysql:8
  • PostgreSQL 安装
docker run --name postgres9 --restart=always -e POSTGRES_PASSWORD=root -p 5432:5432 -d postgres:9

docker run --name postgres11 --restart=always -e POSTGRES_PASSWORD=root -p 6543:5432 -d postgres:11
  • Jenkins 安装
#主键共享目录赋权
chown -R 1000:1000 /home/jenkins
docker run -itd -p 9999:8080 -p 50000:50000 --name jenkins  --restart=always --privileged=true  -v /home/jenkins:/var/jenkins_home -v /etc/localtime:/etc/localtime jenkins
#进入容器删除旧版本
docker exec -it -u root CONTAINERID bash
rm -rf /usr/share/jenkins/jenkins.war
#从外面拷贝新版本到容器中
docker cp /home/jenkins/jenkins.war CONTAINERID:/usr/share/jenkins/
  • docker-registry 安装
docker run --name registry --restart=always -v /opt/registry:/var/lib/registry -p 5000:5000 -d registry:2.7.1
#访问
http://172.21.32.128:5000/v2/_catalog
  • 常用命令
#移除exited状态容器:三种方式
docker rm `docker ps -a|grep Exited|awk '{print $1}'`

docker rm $(docker ps -qf status=exited)

docker container prune
#移除<none>的镜像
docker rmi $(docker images -qf dangling=true)
docker rmi -f $(docker images -a|grep -v grep|grep "none"| awk '{print $3}')
#docker服务重启
systemctl restart  docker

四、问题