zoukankan      html  css  js  c++  java
  • centos7新特性

    centos7-docker镜像

    docker pull registry.cn-hangzhou.aliyuncs.com/moensun/centos7
    docker pull registry.cn-hangzhou.aliyuncs.com/benpaoz/centos7.4:1.0.3 (使用这个版本)

    单用户模式

    (1)在对应的内核条目上,按下e,会进入edit模式,搜寻ro那一行,以linux16开关的,按end键到最后,输入rd.break,再按ctrl+x进入。
        注意:需要修改LANG=en_US_UTF-8 , 不然会是乱码
    (2)进入后重新挂载/sysroot/,增加写权限
        mount #查看到只有读权限
        mount -o remount,rw /sysroot/
    (3)切换到原始系统下
        chroot /sysroot/
        touch /.autorelabel  #这句是为了selinux生效
        passwd root
    (4)退出单用户的方法是
        先ctrl+d退出,然后reboot

    救援模式

    (1)修改bios设置dvd_drive首选启动
    (2)选择 troubleshoot ing 回车启动
    (3) rescue a centos system 救援模式。然后两次回车
    (4)选择 1) continue  两次回车
    (5) chroot /mnt/sysimage
        touch /.autorelabel  #这句是为了selinux生效,使用这个 重启不会有检测
    (6) passwd root
    (7) exit
    (8) reboot

    /etc/rc.local不启动

    chmod a+x /etc/rc.d/rc.local  #添加执行权限

    设置ip

    
    
    # systemctl stop NetworkManager        --停止服务
    # systemctl status NetworkManager    --查看状态,确认为关闭了
    # systemctl disable NetworkManager    --设置为开机不自动启动
    dhclient
    ip addr    #ip命令是通过 iproute这个包提供的。
    #如果要用ifconfig
        yum install -y net-tools
    vim /etc/sysconfig/network-scripts/ifcfg-eno16777736  #(包括克隆出来的,只需要更改网卡名和驱动名、ip)
        TYPE=Ethernet
        BOOTPROTO=static
        DEFROUTE=yes
        PEERDNS=yes
        PEERROUTES=yes
        NAME=ens33   #网卡名
        DEVICE=ens33 #网卡名
        ONBOOT=yes
        IPADDR=192.168.159.30
        NETMASK=255.255.255.0
        GATEWAY=192.168.159.2
        DNS1=114.114.114.114
    # /etc/init.d/network restart        --network服务这里默认还是可以使用原来的管理方法
    # chkconfig network on
     

    时间同步

    方法1:
    # yum install ntp  ntpdate    --安装ntp时间同步相关软件包
    # vim /etc/ntp.conf        --确认配置文件里有下列的时间同步源
    server 0.rhel.pool.ntp.org iburst
    server 1.rhel.pool.ntp.org iburst
    server 2.rhel.pool.ntp.org iburst
    server 3.rhel.pool.ntp.org iburst
    # systemctl enable ntpd        --设置开机自动启动ntpd
    # systemctl start ntpd        --立即启动ntpd服务
    # date                --确认时间与现在时间一致
    # ntpdate 0.rhel.pool.ntp.org    --如果还没有同步成功,你可以用此命令手动同步一下
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   #更改时区为上海
    
    方法2:
    # yum install xinetd -y
    # vim /etc/xinet.d/time-dgram
        disable         = no    (--yes改为no)
    # vim /etc/xinetd.d/time-stream
        disable         = no    (--yes改为no)
    # systemctl restart xinetd
    # systemctl status xinetd
    # systemctl enable xinetd
    
    
    方法3:
    yum install ntpd -y
    echo "30 * * * *      root    /usr/sbin/ntpdate   ntp.api.bz" >> /etc/crontab

    设置主机名和命令参数补全

    设置主机名
        (1)centos7
        hostnamectl set-hostname test1
        cat /etc/hostname #用上面的命令会直接修改这个配置文件的内容
    
        hostnamectl status #查看hostname状态
        (2)centos6
        hostname test1
        cat /etc/sysconfig/network #上面命令不会修改配置文件的内容
    命令参数补全
        yum install -y bash-completion
        source /etc/profile

    centos7防火墙

    若不想使用firewalld,继续使用iptables,可以停掉firewalld,并且安装iptables-services包
    systemctl stop firewalld
    systemctl disable firewalld
    yum install -y iptables-services
    systemctl enable iptables
    systemctl start iptables

    安装好centos7后忧化

    https://www.cnblogs.com/benjamin77/p/8473129.html
    设置hostname
    命令补全
    sshd加速
    关闭selinux firewalld
    安装yum install -y rsync openssl openssl-devel gcc gcc-c++ wget curl unzip lrzsz sysstat ntp man vim bash-completion ntpd screen expect autoconf automake bzip2 bzip2-devel openssh-clients

    centos7优化脚本 

    #!/bin/bash
    ####centos 7 装好  优化初始脚本
    ##运行此脚本 需要通网络  用root用户
    #Auther      :hanxiaohui
    #Date        :2015-06-18
    #User        :Set basic environment
    
    function FAILED(){
        if [ `echo $?` -ne 0 ];then
                exit
        fi
    }
    
    #检查用户是否为root
    USER=`whoami`
    if [ "$USER"  != 'root' ];then
            echo "Please user root"
            exit
    fi
    
    #优化内核参数:
    if [ ! -f '/etc/sysctl.conf.bak' ];then
     cp /etc/sysctl.conf{,.bak}
    cat << eof > /etc/sysctl.conf
    net.ipv4.tcp_syncookies = 1  #表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
    net.ipv4.tcp_tw_recycle = 1  #表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭;
    net.ipv4.tcp_tw_reuse = 1  #表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
    net.ipv4.tcp_fin_timeout = 3  #修改系统默认的 TIMEOUT 时间。
    net.ipv4.tcp_max_tw_buckets = 20000
    net.ipv4.ip_forward = 0  
    net.ipv4.conf.default.rp_filter = 1  
    net.ipv4.conf.default.accept_source_route = 0  
    kernel.sysrq = 0  
    kernel.core_uses_pid = 1  
    kernel.msgmnb = 65536  
    kernel.msgmax = 65536  
    kernel.shmmax = 68719476736  
    kernel.shmall = 4294967296  
    net.ipv4.tcp_max_tw_buckets = 10000
    net.ipv4.tcp_sack = 1  
    net.ipv4.tcp_window_scaling = 1  
    net.ipv4.tcp_rmem = 4096 87380 4194304   
    net.ipv4.tcp_wmem = 4096 16384 4194304   
    net.core.wmem_default = 8388608  
    net.core.rmem_default = 8388608  
    net.core.rmem_max = 16777216  
    net.core.wmem_max = 16777216  
    net.core.netdev_max_backlog = 262144  
    net.core.somaxconn = 262144  
    net.ipv4.tcp_max_orphans = 3276800  
    net.ipv4.tcp_max_syn_backlog = 262144  
    net.ipv4.tcp_timestamps = 0  
    net.ipv4.tcp_synack_retries = 1  
    net.ipv4.tcp_syn_retries = 1  
    net.ipv4.tcp_mem = 94500000 915000000 927000000   
    net.ipv4.tcp_keepalive_time = 30  
    net.ipv4.ip_local_port_range = 1024 65000
    vm.overcommit_memory = 1
    eof
    fi
    
    #刷新系统内核参数:
    /sbin/sysctl -p
    
    #配置PS 环境:
    if [ -z `egrep -i ps1 /etc/profile |awk '{print $1}'` ];then
            echo "PS1='[e[35;1m][u@h w 	&&#]\$[e[m]'" >> /etc/profile && source /etc/profile
    fi
    
    #做本机的hosts 解析:
    ETH=`awk '{if($2>0 && NR > 2) print substr($1, 0, index($1, ":") - 1)}' /proc/net/dev |grep -v lo |head -n 1`
    HOSTS=`egrep -i $(echo $HOSTNAME) /etc/hosts |awk '{print $2}'`
    if  [  -z "$HOSTS" ];then
            echo $(ip ad |grep "global $ETH" |awk -F "/" '{print $1}' |awk '{print $2}' && echo $HOSTNAME) >> /etc/hosts
    fi
    
    #关闭selinux
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
    
    #禁止使用DNS反向解析:
    sed -i 's/^#UseDNS yes/UseDNS no/'  /etc/ssh/sshd_config
    
    #加快登陆速度:
    sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g'  /etc/ssh/sshd_config
    
    #重新加载openssh
    service sshd restart
    
    #更改语言为en
    lang=`grep -i lang /etc/locale.conf |awk -F '"' '{print $2}'`
    if [ "$LANG" != 'en_US.UTF-8' ];then 
           sed -i  "s/${LANG}/en_US.UTF-8/" /etc/locale.conf
    fi
    
    #设置时区
    if [ ! -f /etc/localtime.bak ];then
            cp /etc/localtime{,.bak}
            yes|cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    fi
    
    
    
    
    
    #安装必要的维护工具
    yum install -y rsync openssl openssl-devel gcc gcc-c++ wget curl unzip lrzsz sysstat ntp man vim bash-completion ntpd screen expect autoconf automake bzip2 bzip2-devel openssh-clients
    FAILED #修改国内源和安装epel源: [
    -d /etc/yum.repos.d.bak ] && rm -rf /etc/yum.repos.d.bak cp -a /etc/yum.repos.d{,.bak} rm -rf /etc/yum.repos.d/* wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo yum clean all yum makecache
    sleep 2 yum install -y epel-release wget -O /etc/yum.repos.d/epel-7.repo
    http://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache #命令补全 yum install -y bash-completion source /etc/profile #每半个小时从网络上更新一次系统时间 NTPDATE=`egrep -i ntpdate /etc/crontab |awk -F '/' '{print $4}' |awk '{print $1}'` if [ "$NTPDATE" == "" ];then echo "#每半个小时从网络上更新一次系统时间" >> /etc/crontab echo "30 * * * * root /usr/sbin/ntpdate ntp.api.bz" >> /etc/crontab fi /usr/sbin/ntpdate ntp.api.bz #或者写成: #if [ ! -z `egrep -i ntpdate /etc/crontab |awk -F '/' '{print $4}' |awk '{print $1}'` ];then # echo "#每半个小时从网络上更新一次系统时间" >> /etc/crontab # echo "30 * * * * root /usr/sbin/ntpdate time-a.nist.gov" >> /etc/crontab #fi #配置limit ulimit -SHn ,, ulimit -SHu ,, LIMIT=`egrep -i -v '^#|^$' /etc/security/limits.conf` if [ -z "$LIMIT" ] then cp /etc/security/limits.conf{,.bak} sed -i "49i * hard nproc 65535 * soft nproc 65535 * hard nofile 65535 * soft nofile 65535 " /etc/security/limits.conf fi iptables -F ;iptables-save > /opt/sh/iptables.bak systemctl disable firewalld
    systemctl disable NetworkManager #systemctl stop firewalld #重启系统 sync && reboot

    centos7配置国内源和epel源

    cd /etc/yum.repos.d/
    mkdir repo_bak mv
    *.repo repo_bak/ wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo yum clean all # 清除系统所有的yum缓存 yum makecache # 生成yum缓存 yum install -y epel-release # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件 wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo # 下载阿里开源镜像的epel源文件 多了epel-7.repo #再次重新生成yum缓存 yum clean all yum makecache yum repolist enabled #查看系统可用的yum源 yum repolist all #所有的yum源

    centos7修改系统语言和设置时区 

    查看系当前语言包
        locale
    查看系统拥有语言包
        locale -a   (zh_CN.UTF-8是简体中文,如果没有zh_CN.UTF-8,就安装语言包,如果存在可以直接设置)
    安装简体中文语言包
        yum install kde-l10n-Chinese
    
    设置为中文
        临时
        LANG="zh_CN.UTF-8"    #修改为中文
        LANG="en_US.UTF-8"    #修改为英文
    
        永久
        方法(一)
        vi /etc/locale.conf
        ##加下面内容到第一行,设置中文
        LANG=zh_CN.UTF8
    
        方法(二)
        localectl  set-locale LANG=zh_CN.UTF8
    修改时区为亚洲上海
        ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

      centos7不再有chkconfig工具了,而是使用systemd

    使某服务自启动 systemctl enable httpd.service
    不自启动 systemctl disable httpd.service
    查看服务状态 systemctl status httpd.service
    查看所有服务 systemctl list-units --type=service
    启动服务  systemctl start httpd.service
    停止服务  systemctl stop httpd.service
    重启服务  systemctl restart httpd.service
    systemctl daemon-reload  #改配置后需要执行这个
    启动脚本路径  
      
    /usr/lib/systemd/system/ 检查一个服务是否为开机启动
      systemctl
    is-enabled httpd
    列出所有正在运行的、类型为service的Unit
      systemctl list-units --type=service
    systemctl list-unit-files | grep enabled | grep service #这个好用

    查看启动时的默认Target:
      systemctl get-default

    设置启动时的默认 Target: systemctl set-default multi-user.target
    切换 Target 时,默认不关闭前一个 Target 启动的进程,systemctl isolate 命令改变这种行为,关闭前一个 Target 里面所有不属于后一个 Target 的进程
      systemctl isolate multi-user.target
    查看运行级别:

      runlevel

    查看一个service属于哪个target,需要cat 具体的service文件:

      cat /usr/lib/systemd/system/sshd.service    #看里面[install]部分

     

     systemd - unit

    systemd管理服务的机制的特点:
        支持服务并列启动,不用顺序启动,从而开机时间缩短
        支持自动检测服务依赖的服务
        Systemd 可以管理所有系统资源。不同的资源统称为 Unit(单位)。
    Unit 一共分成12种类型
        Service unit:系统服务
        Target unit:多个 Unit 构成的一个组
        Device Unit:硬件设备
        Mount Unit:文件系统的挂载点
        Automount Unit:自动挂载点
        Path Unit:文件或路径
        Scope Unit:不是由 Systemd 启动的外部进程
        Slice Unit:进程组
        Snapshot Unit:Systemd 快照,可以切回某个快照
        Socket Unit:进程间通信的 socket
        Swap Unit:swap 文件
        Timer Unit:定时器
    systemd - unit相关命令:
        列出正在运行的 Unit
            systemctl list-units
        列出所有Unit,包括没有找到配置文件的或者启动失败的
            systemctl list-units --all
        列出所有没有运行的 Unit
            systemctl list-units --all --state=inactive
        列出所有加载失败的 Unit
            systemctl list-units --failed
        列出所有正在运行的、类型为 service 的 Unit
            systemctl list-units --type=service
        显示某个 Unit 是否正在运行
            systemctl is-active application.service
        显示某个 Unit 是否处于启动失败状态
            systemctl is-failed application.service
        显示某个 Unit 服务是否建立了启动链接
            systemctl is-enabled application.service

     systemd target启动级别

    centos7里不再有0-6启动级别,而是4个target
    graphical.targe 多人模式,支持图形和命令行两种登陆,对应之前的3,5级别
    multi-user.target 多人模式,只支持命令行登录,对应之前的3级别
    rescue.target 单人模式,对应之前的1级别
    emergency.target 单人模式,不过系统进入后根目录是只读的。
    
    target类似于centos6里面的启动级别,但target支持多个target同时启动。target其实是多个unit的组合,系统启动说白了就是启动多个unit,为了管理方便,就使用target来管理这些unit。
    
    查看当前系统的所有 Target
        systemctl list-unit-files --type=target
    查看一个 Target 包含的所有 Unit
        systemctl list-dependencies multi-user.target
    查看启动时的默认 Target
        systemctl get-default
    设置启动时的默认 Target
        systemctl set-default multi-user.target
    切换 Target 时,默认不关闭前一个 Target 启动的进程,
        systemctl isolate 命令改变这种行为,关闭前一个 Target 里面所有不属于后一个 Target 的进程
        systemctl isolate multi-user.target
    查看运行级别
        runlevel

     systemd unit 关联target

    主配置文件
        /etc/systemd/system.conf
    开机会先加载
        /etc/systemd/system/default.target
    所有的service和target在
        /usr/lib/systemd/system/
    ls -l /etc/systemd/system/defaut.target
        是一个软连接,软连接到了/usr/lib/systemd/system/multi-user.target
        它会加载/usr/lib/systemd/system/multi-user.target.wants下面的service
    查看一个service属于哪个target,需要cat 具体的service文件
        cat /usr/lib/systemd/system/sshd.service
        看里面[install]部分
  • 相关阅读:
    arcgis pro加载其他数据
    ArcGIS Pro运行Python脚本
    获得ArcGIS Pro的版本
    ArcGIS Pro使用键盘控制地图平移
    ArcGIS Pro添加注记工具
    ArcGIS Pro二次开发添加网络图层
    ArcGIS Pro放大缩小按钮
    ArcGIS Pro做一个矩形选择按钮
    ArcGIS Pro获得一个图层的样式
    ArcGIS Pro二次开发闪烁对象
  • 原文地址:https://www.cnblogs.com/hanxiaohui/p/8887089.html
Copyright © 2011-2022 走看看