zoukankan      html  css  js  c++  java
  • Linux 常用命令

    从本机拷贝文件到远端机器:

    scp jdk-6u37-linux-x64-rpm.bin root@192.168.72.102:/root

    vi复制一行并粘贴:

    1)把光标移动到要复制的行上
    2)按yy
    3)把光标移动到要复制的位置
    4)按p

    vi/vim后退(取消修改):按u

    vi/vim添加新行:按A,然后回车

     Mysql备份数据库:

     mysqldump -u root -p密码 dbname >d:\test.sql 

    centOS7 firewall-cmd 端口转发:

    # 允许防火墙伪装IP
    firewall-cmd --add-masquerade
    # 增加8393端口的映射到192.168.1.107的8393:
    firewall-cmd --add-forward-port=port=8393:proto=tcp:toaddr=192.168.1.107:toport=8393 --permanent
    # 增加8066端口的映射到192.168.1.105的8066:
    firewall-cmd --add-forward-port=port=8066:proto=tcp:toaddr=192.168.1.105:toport=8066 --permanent


     Mysql还原数据库:

    先登录: mysql -uroot -p

    再创建需要还原的数据库 create database 数据库名

    切换到创建的数据库:use 数据库名

    执行sql脚本:source 脚本.sql

    linux 创建用户并设定主目录:

    useradd -d /data/cdnlab cdnlab

    设定用户的密码:

    passwd cdnlab

     centos配置ntp:

    修改ntp.conf配置文件

    # Please consider joining the pool (http://www.pool.ntp.org/join.html).

    server 1.cn.pool.ntp.org

    server 1.asia.pool.ntp.org

    server 0.asia.pool.ntp.org

    用本机器与互联网时钟同步,即作为集群中其他机器的ntp服务器

    同理,在其他机器中修改ntp.conf配置文件

    server ntpserver

    启动axis2的webservice:

    nohup sh /opt/axis2-1.6.0/bin/axis2server.sh &>/root/websvr.log &

     centos 添加静态路由:

    #比如我有双网卡,分别是192.168.68.7/24 10.0.101.88/24 

    因为搭建了个实验网,所以想让所有10.0.0.0/8 的路由都通过10.0.101.1转发,下面这样配置就可以了:

    route add -net 10.0.0.0/8 gw 10.0.101.1

     启动AXIS2服务器:

    nohup sh axis2server.sh &>/var/logs/axis2.log &

    删除mysql

       yum remove  mysql mysql-server mysql-libs mysql-server;

        find / -name mysql 将找到的相关东西delete掉;

        rpm -qa|grep mysql(查询出来的东东yum remove掉)

    将某文件的指定行输出到新文件

    cat crawler.log | tail -n +438856 | head -n 281208 > yuanling.gov.cn.log

    意思是指从第438856行开始,连续显示 281208行数据,并且将结果重定向到yuanling.gov.cn.log

    CentOS7 防火墙允许端口:

    firewall-cmd --permanent --add-port=59999/tcp
    firewall-cmd --reload

     CentOS7 防火墙允许服务:

    firewall-cmd --permanent --add-service=https
    firewall-cmd --permanent --add-service=http
    firewall-cmd --reload

    systemd新增自定义服务:


    vim /usr/lib/systemd/system/ipsec.service

    [Unit]
    Description=ipsec - ipsec strongswan
    After=network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    ExecStart=/usr/local/sbin/ipsec start
    ExecReload=/usr/local/sbin/ipsec restart
    ExecStop=/usr/local/sbin/ipsec stop

    [Install]
    WantedBy=multi-user.target

    保存后,设置文件权限:

    chmod 754 /usr/lib/systemd/system/ipsec.service

    允许开机自启动:

    systemctl enable ipsec.service

    启动服务:

     systemctl start ipsec.service

    fedora 25 增加开机自启动脚本:

    1.修改 /usr/lib/systemd/system/rc-local.service

    在末尾增加如下代码:

    [Install]
    WantedBy=multi-user.target

    2.新建文件/etc/rc.d/rc.local

    并输入下面的内容,下面是示例内容:

    #!/bin/bash
    #下面是你需要执行的脚本
    /usr/bin/ssserver -c /etc/xxx.json -d start

    3.保存并退出。

    4.chmod +x /etc/rc.d/rc.local

    5.systemctl enable rc-local.service

    6. systemctl start rc-local.service

    完毕。。

    Linux 下安装pip:

    wget https://bootstrap.pypa.io/get-pip.py

    python get-pip.py

    pip -V

     CentOS 6 安装ncdu

    sudo yum update nss
    sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    sudo yum -y install ncdu

    #查看磁盘使用率
    #图形界面
    sudo ncdu /
    #json格式
    sudo ncdu / -o ncdu.log
    #查看根目录
    more ncdu.log |grep “asize”|sed ‘s/"/,/g’|awk -F , ‘{print $4,$8}’|sort -t “:” -k2 -rn|head -n 10

    #配置免密登录

    #配置相互免密登录
    #controller1
    ssh-keygen
    #三次回车
    #将密钥发送至其他机器上,每一次复制都要输入yes及当前用户的密码: 
    ssh-copy-id -i /home/nanjing/.ssh/id_rsa.pub crawler1
    ssh-copy-id -i /home/nanjing/.ssh/id_rsa.pub crawler2
    ssh-copy-id -i /home/nanjing/.ssh/id_rsa.pub crawler3
    ssh-copy-id -i /home/nanjing/.ssh/id_rsa.pub master1
    ssh-copy-id -i /home/nanjing/.ssh/id_rsa.pub slave1
    ssh-copy-id -i /home/nanjing/.ssh/id_rsa.pub slave2

    #其他机器同样的操作,注意修改机器名即可。前提是host里有这些机器的hostname和ip的配置

     CentOS 安装crontab

    sudo yum install -y vixie-cron
    sudo yum install -y crontabs

    ncdu查看Linux服务器各目录占用磁盘大小情况
    #为每台机器安装ncdu
    sudo yum -y update nss
    sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    sudo yum -y install ncdu
    #查看磁盘使用率
    #图形界面
    sudo ncdu /
    #json格式
    sudo ncdu / -o ncdu.log
    #查看根目录
    more ncdu.log |grep “asize”|sed ‘s/"/,/g’|awk -F , ‘{print $4,$8}’|sort -t “:” -k2 -rn|head -n 10 

     CentOS7 使用阿里云的epel源

    yum remove epel-release

    wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

     yum clean all && yum makecache

    Linux下 没有vi命令的时候 cat编辑文件:

    cat > test_hugedata.txt << EOF

    粘贴要输入的文字,然后回车,然后输入EOF结束。

     centos7修改系统时区后 jdk不生效的解决方法:

    timedatectl  set-timezone Asia/Shanghai

     Centos7修改机器名

     hostnamectl set-hostname yourHostName

     然后修改 /etc/hosts

     #CentOS7 disable selinux
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/'  /etc/selinux/config
    setenforce 0

    #CentOS7 set ntp
    yum install -y ntp

    #Edit the /etc/ntp.conf file  master
    server 120.25.108.11 iburst
    server 182.92.12.11 iburst

    #other server

    vim /etc/ntp.conf

    server 192.168.88.35
    fudge 192.168.88.35 stratum 10


    #check
    ntpdate -u 120.25.108.11

    sudo systemctl start ntpd
    sudo systemctl enable ntpd
    hwclock --systohc

    以CentOS7为例

    修改最大句柄数
    修改服务器配置(仔细检查各项配置,如果已经存在,则只需要修改为下面的值即可):
    vim /etc/systemd/system.conf
    查找并修改下列两行的值:
    DefaultLimitNOFILE=1024000
    DefaultLimitNPROC=1024000

    vim /etc/security/limits.conf
    在文件中添加:
    root            soft    fsize           unlimited
    root            hard    fsize           unlimited
    root            soft    cpu             unlimited
    root            hard    cpu             unlimited
    root            soft    as              unlimited
    root            hard    as              unlimited
    root            soft    nofile          1024000
    root            hard    nofile          1024000
    root            soft    nproc           1024000
    root            hard    nproc           1024000

    vim /etc/security/limits.d/20-nproc.conf
    *          soft    nproc     1024000
    root       soft    nproc     unlimited

     centos 升级内核

    1. 载入公钥

    [root@server-1 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

    2. 升级安装ELRepo

    3. 载入elrepo-kernel元数据

    [root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist

    4. 查看可用的rpm包

    yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*

    5. 安装最新版本的kernel

    [root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install  kernel-ml.x86_64  -y

    6. 删除旧版本工具包

    [root@server-1 ~]# yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64  -y

    7. 安装新版本工具包

    [root@server-1 ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install kernel-ml-tools.x86_64  -y

    8. 查看内核插入顺序

    [root@server-1 ~]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
    0 : CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)
    1 : CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)
    2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
    3 : CentOS Linux (0-rescue-ca0f6fb3c5f24478abc0a2e275281d7a) 7 (Core)

    9. 查看当前实际启动顺序

    [root@server-1 ~]# grub2-editenv list
    saved_entry=CentOS Linux (3.10.0-957.5.1.el7.x86_64) 7 (Core)

    10. 设置默认启动

    [root@server-1 ~]# grub2-set-default 'CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)'
    [root@server-1 ~]# grub2-editenv list
    saved_entry=CentOS Linux (4.20.12-1.el7.elrepo.x86_64) 7 (Core)

    或者直接设置数值

    [root@server-1 ~]# grub2-set-default 0  // 0代表当前第一行,也就是上面的4.20.12版本那一行内容
    [root@server-1 ~]# grub2-editenv list
    saved_entry=0

    11. 重启并检查

     [root@server-1 ~]# reboot 

     [root@server-1 ~]# uname -r

     

    centos7开启bbr

    sudo sysctl net.ipv4.tcp_available_congestion_control
    echo 'net.core.default_qdisc=fq' | sudo tee -a /etc/sysctl.conf
    echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a /etc/sysctl.conf
    sudo sysctl -p
    sudo sysctl net.ipv4.tcp_available_congestion_control
    sudo sysctl -n net.ipv4.tcp_congestion_control
    lsmod | grep bbr

    CentOS6 yum源失效的解决办法:

    阿里云:

    mkdir -p /etc/yum.repos.d/repo_backup
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_backup
    vim /etc/yum.repos.d/CentOS-Base.repo
    
    [base]
    name=CentOS-6.5 - Base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos-vault/6.5/os/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
     
    [updates]
    name=CentOS-6.5 - Updates - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos-vault/6.5/updates/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
     
    [extras]
    name=CentOS-6.5 - Extras - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos-vault/6.5/extras/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
     
    [centosplus]
    name=CentOS-6.5 - Plus - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos-vault/6.5/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
     
    [contrib]
    name=CentOS-6.5 - Contrib - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos-vault/6.5/contrib/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

    epel:

    #install epel vault source
    
    wget https://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm
    rpm -ivh epel-release-6-8.noarch.rpm
    yum --disablerepo=epel -y update ca-certificates
    yum clean all 
    yum makecache

    官方:

    epel.repo:

    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    baseurl=https://archives.fedoraproject.org/pub/archive/epel/6/$basearch
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
    #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=1
    
    [epel-source]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Source
    #baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
    mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=1

    禁用base,新建CentOS-Vault.repo:

    # CentOS-Vault.repo
    #
    # CentOS Vault holds packages from previous releases within the same CentOS Version
    # these are packages obsoleted by the current release and should usually not 
    # be used in production
    #-----------------
    
    [C6.0-base]
    name=CentOS-6.0 - Base
    baseurl=http://vault.centos.org/6.0/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.0-updates]
    name=CentOS-6.0 - Updates
    baseurl=http://vault.centos.org/6.0/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.0-extras]
    name=CentOS-6.0 - Extras
    baseurl=http://vault.centos.org/6.0/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.0-contrib]
    name=CentOS-6.0 - Contrib
    baseurl=http://vault.centos.org/6.0/contrib/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.0-centosplus]
    name=CentOS-6.0 - CentOSPlus
    baseurl=http://vault.centos.org/6.0/centosplus/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    #-----------------
    
    [C6.1-base]
    name=CentOS-6.1 - Base
    baseurl=http://vault.centos.org/6.1/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.1-updates]
    name=CentOS-6.1 - Updates
    baseurl=http://vault.centos.org/6.1/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.1-extras]
    name=CentOS-6.1 - Extras
    baseurl=http://vault.centos.org/6.1/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.1-contrib]
    name=CentOS-6.1 - Contrib
    baseurl=http://vault.centos.org/6.1/contrib/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.1-centosplus]
    name=CentOS-6.1 - CentOSPlus
    baseurl=http://vault.centos.org/6.1/centosplus/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    #-----------------
    
    [C6.2-base]
    name=CentOS-6.2 - Base
    baseurl=http://vault.centos.org/6.2/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.2-updates]
    name=CentOS-6.2 - Updates
    baseurl=http://vault.centos.org/6.2/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.2-extras]
    name=CentOS-6.2 - Extras
    baseurl=http://vault.centos.org/6.2/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.2-contrib]
    name=CentOS-6.2 - Contrib
    baseurl=http://vault.centos.org/6.2/contrib/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.2-centosplus]
    name=CentOS-6.2 - CentOSPlus
    baseurl=http://vault.centos.org/6.2/centosplus/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    #-----------------
    
    [C6.3-base]
    name=CentOS-6.3 - Base
    baseurl=http://vault.centos.org/6.3/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.3-updates]
    name=CentOS-6.3 - Updates
    baseurl=http://vault.centos.org/6.3/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.3-extras]
    name=CentOS-6.3 - Extras
    baseurl=http://vault.centos.org/6.3/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.3-contrib]
    name=CentOS-6.3 - Contrib
    baseurl=http://vault.centos.org/6.3/contrib/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0
    
    [C6.3-centosplus]
    name=CentOS-6.3 - CentOSPlus
    baseurl=http://vault.centos.org/6.3/centosplus/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=0

    yum --disablerepo=epel -y update ca-certificates

    yum clean all

    yum makecache

    如果遇到ssl错误,则将epel.repoo中的https换成http,然后 yum install ca-certificates yum update curl 即可,可以选择将http修改回https。

    centos6 修改机器名:

    vi /etc/sysconfig/network

    重启

    查看linux系统网卡绑定的CPU:

    mpstat -P ALL 1

    输出中查明:里面的 %irq 一列即说明了CPU忙于处理中断的时间占比

    CentOS6.x查看CPU,可以参看以下命令来查看

          1.查看CPU型号

               cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c 

          2.查看物理CPU的个数

                 cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 

          3.查看逻辑CPU的个数

                   cat /proc/cpuinfo |grep "processor"|wc -l 

           4.查看CPU是几核

                    cat /proc/cpuinfo |grep "cores"|uniq

    lscpu

    CENTOS 编译安装tcpdump:

    yum -y install gcc make cmake  flex bison

    然后去下载源代码后编译安装:http://www.tcpdump.org/#latest-release

    ./configure

    make && make install

    tcpdump监控所有的80、443端口流量

     tcpdump.4.99.1 'tcp port 80 or 443 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -w http_88.26_20210727_001.pcap

    查看进程打开的句柄数:

    lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more

    centos7 设置nto与腾讯云服务器同步

    vim /etc/ntp.conf :

    注释掉原来的时间服务器,增加下列配置:

    disable monitor
    server time1.cloud.tencent.com iburst
    server time2.cloud.tencent.com iburst
    server time3.cloud.tencent.com iburst
    server time4.cloud.tencent.com iburst
    server time5.cloud.tencent.com iburst

    Linux 查看网卡型号

    lspci | grep -i ethernet

    CentOS7新安装系统优化

    ////////////////////////////////
    ////////Sixi. Let it be.../////
    //////////////////////////////

  • 相关阅读:
    day08超市商品库存案例
    day07
    day06_03
    day06_02
    day06_01
    最简单的库存管理java案例
    Day05_homework
    方法的使用注意事项
    day05
    冒泡排序
  • 原文地址:https://www.cnblogs.com/sixiweb/p/3071696.html
Copyright © 2011-2022 走看看