Centos基础与安装

Centos基础与安装

Centos安装

1. Linux版本衍生
|-AT&T Unix: AT&T最初研发,后与Western Electric公司组建贝尔实验室继续研发 Unix 来自 UNIX 为 UNICS的谐音(UNiplexed Information and Computing Service) 而 unics Brian Kernighan是对 Multiplexed Information and Computing Service的取笑
  |-Unix:      闭源,研发者贝尔实验室,2015年4月被诺基亚收购,现为诺基亚下属研发部门,  
    |-Berkeley Software Distribution (BSD)  开源: 加州大学伯克利分校发布的unix版本
      |-Jolix | 386BSD: 加州大学伯克利分校的William Jolitz、Lynne Jolitz
        |-NetBSD:       The NetBSD Foundation
          |-OpenBSD:   The OpenBSD Project,从NetBSD Forked开发,主要贡献为OpenSSH
      |-FreeBSD:        The FreeBSD Project,因对386BSD未来研发计划不赞同,基于BSD的1992年的release版本重新开发
        |-Darwin: Apple Inc的开源版本操作系统
          |-MacOS:Apple Inc的闭源版本操作系统 Macintosh,源于一种叫做McIntosh的苹果,不知道是乔布斯故意还是无意拼错了
    |-Linux,Unix的开源实现(GPL),但未基于Unix代码
      |-Debian (Debian的创始人Ian Murdock 和他的爱妻Debra 两人的名字组合而成的)
        |-Red Hat Linux(RHL) 开源
          |-Red Hat Enterprise Linux(RHEL) 闭源           
          |-Fedora
          |-CentOS (Community Enterprise Operating System) Centos无自己的内核,使用redhat内核
          |-Oracle Linux (Oracle意思是神谕,因为CIA希望这个软件系统能够像神谕一样为他们指点迷津,快速找到所需要的信息,Oracle最早为CIA开发情报管理软件)
        |-Ubuntu:Canonical Ltd., Ubuntu community (名称来自非洲南部祖鲁语或豪萨语的“ubuntu”一词,意思是“人性”、“我的存在是因为大家的存在”,是非洲传统的一种价值观,类似华人社会的“仁爱”思想。)
      |-SUSE Linux (意思为"Software- und System-Entwicklung",是一句德文,英文为"Software and system development")
        |-openSUSE 
      |-Linux Router Project 
        |-LEAF (Linux Embedded Appliance Framework Project)
          |-Alpine Linux 
      |-linksys GPL (估计是基于linux内核)
        |- OpenWrt (Open Wireless Router), 最早用于Linksys WRT54G Wi-Fi 系列路由器而得名 目前以与(LEDE) Linux Embedded Development Environment合并
        |- DD-WRT (Open Wireless Router), 
      |-Android 内核采用GPL linux 有BSD libc进行授权分割
      |-PhotonOS (Vmware 面向容器开发的轻量级操作系统)

— 贝尔实验室(Bell Labs AT&T Bell Laboratories | Bell Telephone Laboratories | Bell Labs | Nokia Bell Labs)

1925年 Western Electric Research Laboratories 和 American Telephone & Telegraph company 的一部分工程部门 组件了贝尔实验室,两家公司平分所有权
https://upload.wikimedia.org/wikipedia/commons/1/1b/Linux_Distribution_Timeline.svg
https://en.wikipedia.org/wiki/Unix-like#/media/File:Unix_history-simple.svg

SSH可用前配置

  1. 修改网卡名称并禁用ipv6
    修改/etc/sysconfig/network-scripts/ifcfg-e***文件
NAME=eth0
DEVICE=eth0

重命名/etc/sysconfig/network-scripts/ifcfg-e***文件为ifcfg-eth0
修改/etc/default/grub文件 GRUBCMDLINELINUX变量

net.ifnames=0 biosdevname=0 ipv6.disable=1

运行命令

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

关闭防火墙(后期改为开发22端口和icmp协议)

systemctl stop firewalld
systemctl disable firewalld
  1. 设置静态IP
    修改/etc/sysconfig/network-scripts/ifcfg-eth0文件
BOOTPROTO="static"
IPADDR="198.18.0.129"
PREFIX="24"
GATEWAY="198.18.0.1"
ONBOOT="yes"
#DNS1(DNS可采用全局配置)
#DNS1

密码方式登录SSH配置其他选项

  1. 设置DNS /etc/resolv.conf
nameserver 223.5.5.5
nameserver 223.6.6.6
  1. 安装wget(Docker容器建议用curl代替)
yum install wget
  • yum源配置
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

非阿里云内网主机
修改/etc/yum.repos.d/CentOS-Base.repo文件
删除所有带有aliyuncs.com的链接

  1. 升级最新系统
    yum update
  2. 编辑器VIM安装
    yum -y install vim-enhanced telnet
  3. 关闭并禁用防火墙
    (临时解决方法,应设置防火墙过滤规则)
    systemctl stop firewalld
    systemctl disable firewalld
  4. 系统语言配置
    作用,防止各个平台出现中文乱码现象
    查看当前系统编码
locale

查看系统已安装编码

locale -a

语言编码切换
编译/etc/profile文件,在文件末尾加入代码

export LANG=en_US.UTF-8
  1. 时间服务器配置
    检查安装情况
rpm -q ntp

安装

yum -y install ntp
systemctl enable ntpd
systemctl start ntpd

手动时间同步

ntpdate -u ntp1.aliyun.com
clock -w(写入硬件CMOS 不然重启会还原)
  • 时区设置
    tzselect
  • 时区查看
    date -R
    TZ=‘Asia/Shanghai’; export TZ 添加到 /etc/profile
    timedatectl set-timezone Asia/Shanghai(此操作影响 /etc/localtime文件 不同软件可能采用不同方式获取时间和时区)
    阿里云NTP服务器
    ntp1.aliyun.com,0x1
    ntp2.aliyun.com,0x1
    ntp3.aliyun.com,0x1
    ntp4.aliyun.com,0x1
    ntp5.aliyun.com,0x1
    ntp6.aliyun.com,0x1
    ntp1.cloud.aliyuncs.com,0x1
    ntp2.cloud.aliyuncs.com,0x1
    ntp3.cloud.aliyuncs.com,0x1
    ntp4.cloud.aliyuncs.com,0x1
    ntp5.cloud.aliyuncs.com,0x1
    ntp6.cloud.aliyuncs.com,0x1
    ntp7.cloud.aliyuncs.com,0x1
    ntp8.cloud.aliyuncs.com,0x1
    ntp9.cloud.aliyuncs.com,0x1
    ntp10.cloud.aliyuncs.com,0x1
    ntp11.cloud.aliyuncs.com,0x1
    ntp12.cloud.aliyuncs.com,0x1

另一种方法chrony(centos7)
chronyc sourcestats && systemctl is-enabled ntpd && systemctl is-enabled chronyd

  1. SSH登录密钥生成与配置
    密钥生成
ssh-keygen -t rsa

将授权可以登陆的用户的pubkey复制到服务器的authorzied_keys文件内

~/.ssh/authorized_keys

确保authorized_keys文件权限为600 (否则会拒绝连接,且日志无记录)
用户登录欢迎词配置 修改/etc/motd文件
故障排查方法 /usr/sbin/sshd -d调试模式启动看日志
本地虚拟机 Welcome to SherryBlue.Org Virtual Host!
云服务器 Welcome to SherryBlue.Org @ Aliyun Elastic Compute Service!

  1. 设置主机名
hostnamectl set-hostname docker1

自动配置脚本

#!/bin/bash
#1.DNS配置
echo "nameserver 223.5.5.5" >> /etc/resolv.conf
echo "nameserver 223.6.6.6" >> /etc/resolv.conf
#2.yum源配置
yum -y install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i '/aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo 
yum clean metadata
yum makecache
yum -y update
# 安装epel阿里云源
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
#3.环境变量设置
echo "export LANG=en_US.UTF-8" >> /etc/profile #编码
echo "export TZ='Asia/Shanghai'" >> /etc/profile #时区
echo "MYDOCKER_HOME=/data;export MYDOCKER_HOME" >> /etc/profile #Docker
echo "export PATH=\$PATH:\$MYDOCKER_HOME/docker-file/bin" >> /etc/profile
echo "DOCKER_REGISTRY=registry-vpc.cn-hangzhou.aliyuncs.com/lineto; export DOCKER_REGISTRY" >> /etc/profile
source /etc/profile
#4.时区及时钟
timedatectl set-timezone Asia/Shanghai
yum -y install ntpdate
ntpdate ntp1.aliyun.com
clock -w
#5.SSH密钥登录配置
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/#PubkeyAuthentication/PubkeyAuthentication/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
mkdir -p /root/.ssh/
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjDQ6Ss/R65zPsdzGndM2qroAWHFuJ2LvxD3oLj9VIpGLqj1SfKTvLmUvDnG2kqD4P8lWjn9UiyYgYj3tLzxCRT1/QYW/R1a5NrpM2aAiZ6lVueeQ4anj2FRWqczEnxp+pidGh6vXF4dnE68am9A+/SDbsnu8UIZb2rxEfNp2W0t8WJQ5bTZtFHBmsa8/HCwX+DS8VABMgYJjWFExrO+qVejjUj8pz6QtOriQE7YT3s3pHXC4lt4usVcwB1SYTNrpgf1wrhDr7vSvOB7YPJAPQ1pCFXu+V3GfRkFoRJwZGqg4hSBheV9y66megsTriFMWYEjZR2tBT+dcmTtyFRwBd blue@blue.sherryblue.org" >> /root/.ssh/authorized_keys
/etc/motd
service sshd restart
#6.关闭SELinux (某些情况下SELinux会导致文件读取失败等权限问题)
setenforce 0 
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#7.安装防火墙服务(很多时候我们都需要地址映射功能,这个命令很方便)
yum -y install iptables-services
#8.关闭postfix服务(25号端口)
systemctl stop postfix #需要用邮件再开
systemctl disable postfix
#09.内存及SWAP优化
sysctl vm.swappiness=0 #优先使用物理RAM 详见性能测试内存部分
echo "vm.swappiness = 0" >> /etc/sysctl.conf
#10.主机名配置
hostnamectl set-hostname mesos-master
reboot

crontab -e

  • */1 * * * /usr/sbin/ntpdate ntp.d.com

其它常用调试工具

yum install lsof # Total download size: 331 k Installed size: 927 k
yum install iotop (进程级别的硬盘和网络io读写监视)
yum install sysstat (系统监视工具,iostat等)
yum install traceroute (路由追踪)
yum install hdparm (硬盘型号等参数查看)

iperf rpm包安装 # Installed size: 181 k (带宽检查)

内核参数(待检验)

vm.dirty_background_ratio=10
vm.dirty_ratio=20
某些情况下出现的 hung_task_timeout_secs错误

Sep 24 08:44:54 docker75 kernel: INFO: task nfsd:413 blocked for more than 120 seconds.
Sep 24 08:44:54 docker75 kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.

Centos内核升级

清华镜像 https://mirrors.tuna.tsinghua.edu.cn/elrepo/

#安装内核源
rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/x86_64/RPMS/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
#查看支持的mainline版本
yum --enablerepo=elrepo-kernel list  kernel-ml-devel kernel-ml --showduplicates
#安装最新mainline版本内核
yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y
#安装最新longtern版本内核
yum --enablerepo=elrepo-kernel list  kernel-lt-devel kernel-lt --showduplicates

H3C CAS平台虚拟机初始化流程

设置光驱优先启动
安装centos操作系统
安装CATools
关闭并禁用防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
安装蓝鲸客户端
利用蓝鲸进行服务器初始化配置
安装系统监视客户端
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值