禁止crontab -r清空定时任务列表误操作

关于crontab
1、附件cron.sh放/usr/bin目录下面
2、在/etc/bashrc文件末尾添加
alias crontab=’/usr/bin/cron.sh’

或者在当前root用户下在~/.bashrc文件末尾添加:
alias crontab=’/usr/bin/cron.sh’

===================================
cron.sh作用
1、禁止crontab -r
2、每次编辑都备份cron列表到~/cronbak目录下面

##########cron.sh

#!/bin/bash
source ~/.bashrc

etime=`date -d "0 days ago" +%Y%m%d_%H%M%S`

if [ "$1" = "-r" ] ; then
    echo "My God! Dangerous..."
    echo "Exit..."
    exit 2
fi

if [ "$1" = "-l" ] ; then
    /usr/bin/crontab -l
    exit 0
fi

if [ "$1" = "-e" ] ; then
    mkdir -p  ~/cronbak
    /usr/bin/crontab -l  >  ~/cronbak/cron.bak.$etime.a
    /usr/bin/crontab -e
    /usr/bin/crontab -l  >  ~/cronbak/cron.bak.$etime.b
fi

#linux

VMware安装CentOS后时间相差8小时解决方法

1、执行date查看时区设置是否正确,如果是CST就是中国标准时间

2、将/etc/localtime指向上海时间

ln –sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3、下载ntp(前提是机器能联网)

yum –y install ntp
4、执行对时

ntpdate cn.pool.ntp.org
5、对时后再次执行date查看时间,如果已经是正确的时间则进入下一步

6、将系统时间写入硬件(这步如果不执行重启机器后时间又会出问题)

hwclock -w

VMware虚拟机中Centos 6.x系统磁盘空间扩容实战

环境:
CentOS 6.9

平常在VMware上创建Linux系统虚拟机的时候,往往当时不会给太多的磁盘空间,在后期的使用过程中经常会遇到磁盘空间不足的情况,所以需要对Linux系统扩展磁盘空间。

扩展磁盘步骤:
1.磁盘扩展

注意:只能在虚拟机关机的情况下操作,并且这个虚拟机上没有磁盘快照文件,如有需要删除才可以扩展。

此时虽然在VMware虚拟机管理界面的扩容操作已经完成,但是这还只是扩容的第一步,后面还需要到操作系统内部进行操作。

2.查看分区信息

[root@test-centos6 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a16bc

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/vg_testcentos6-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_testcentos6-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@test-centos6 ~]# lsblk //列出块设备信息
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 447M 0 rom
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─vg_testcentos6-lv_root (dm-0) 253:0 0 17.5G 0 lvm /
└─vg_testcentos6-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]

可以看到目前磁盘/dev/sda已经有两个分区,分别为sda1、sda2。

3.新建分区sda3

[root@test-centos6 ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).

Command (m for help): m //列出可以执行的命令
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition //选择分区,删除现有分区
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): n //建立新的磁盘分区
Command action
e extended //逻辑分区
p primary partition (1-4) //主分区
p //建立主分区
Partition number (1-4): 3 //输入分区号
First cylinder (2611-7832, default 2611): //分区起始位置(可直接回车也可以根据情况输入)
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-7832, default 7832): //回车
Using default value 7832

Command (m for help): p //列出磁盘目前的分区情况

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a16bc

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 7832 41939020 83 Linux

Command (m for help): w //对分区操作进行保存
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks. //正在同步磁盘

[root@test-centos6 ~]# fdisk -l //查看分区创建情况

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a16bc

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 7832 41939020 83 Linux

Disk /dev/mapper/vg_testcentos6-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_testcentos6-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

4.重启系统并格式化分区sda3文件系统

[root@test-centos6 ~]# reboot

[root@test-centos6 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 447M 0 rom
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 19.5G 0 part
│ ├─vg_testcentos6-lv_root (dm-0) 253:0 0 17.5G 0 lvm /
│ └─vg_testcentos6-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]
└─sda3 8:3 0 40G 0 part

[root@test-centos6 ~]# mkfs.ext4 /dev/sda3 //将/dev/sda3分区文件系统格式化为ext4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10484755 blocks
524237 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

5.创建物理卷(pv)

此步骤可省略:当将分区直接添加到卷组(vg)时,LVM会自动将分区转换为物理卷(pv)。

[root@test-centos6 ~]# lvm
lvm> pvcreate /dev/sda3 //创建物理卷pv
Physical volume “/dev/sda3” successfully created
lvm> pvdisplay //显示物理卷pv信息
— Physical volume —
PV Name /dev/sda2
VG Name vg_testcentos6
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID jMIPOc-sduo-sl4T-6iQ5-ledQ-1w9O-cweeEC

“/dev/sda3” is a new physical volume of “40.00 GiB”
— NEW Physical volume —
PV Name /dev/sda3
VG Name
PV Size 40.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID PVrdc7-fUEX-PAxZ-ME92-IuNU-khDC-c5tYlp

lvm> pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name vg_testcentos6
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID jMIPOc-sduo-sl4T-6iQ5-ledQ-1w9O-cweeEC

“/dev/sda3” is a new physical volume of “40.00 GiB”
— NEW Physical volume —
PV Name /dev/sda3
VG Name
PV Size 40.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID PVrdc7-fUEX-PAxZ-ME92-IuNU-khDC-c5tYlp

6.查看并创建卷组(vg)

lvm> vgdisplay //查看需要扩展的卷组vg名称
— Volume group —
VG Name vg_testcentos6 //卷组vg名称
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 59.49 GiB
PE Size 4.00 MiB
Total PE 17790
Alloc PE / Size 15232 / 19.50 GiB
Free PE / Size 2558 / 9.99 GiB
VG UUID yVVWYi-mV3I-f1WI-2QeH-HkVT-oBXP-2KkQ8v

lvm> vgextend vg_testcentos6 /dev/sda3 //扩展卷组(这里的“vg_testcentos6”名称为上面的卷组名称)
Volume group “vg_testcentos6” successfully extended

7.扩展逻辑卷(lv)

[root@test-centos6 ~]# df -h //查看扩展路径,这里也可以用fdisk -l查看
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_testcentos6-lv_root —–》 //**扩展路径**
18G 18G 0 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 58M 403M 13% /boot

[root@test-centos6 ~]# lvm //进入LVM管理器

lvm> lvextend -L +39.99G /dev/mapper/vg_testcentos6-lv_root //扩展逻辑卷lv大小(通过fdisk -l/df -h查看要扩展过去的磁盘)
Rounding size to boundary between physical extents: 39.99 GiB.
Size of logical volume vg_testcentos6/lv_root changed from 17.51 GiB (4482 extents) to 57.50 GiB (14720 extents)
Logical volume lv_root successfully resized.

lvm> lvscan
ACTIVE ‘/dev/vg_testcentos6/lv_root’ [57.50 GiB] inherit
ACTIVE ‘/dev/vg_testcentos6/lv_swap’ [2.00 GiB] inherit

lvm> pvscan
PV /dev/sda2 VG vg_testcentos6 lvm2 [19.51 GiB / 0 free]
PV /dev/sda3 VG vg_testcentos6 lvm2 [39.99 GiB / 0 free]
Total: 2 [59.50 GiB] / in use: 2 [59.50 GiB] / in no VG: 0 [0 ]

lvm> exit
Exiting.

8.查看分区情况

[root@test-centos6 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a16bc

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 7832 41939020 83 Linux

Disk /dev/mapper/vg_testcentos6-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_testcentos6-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

注意:上面虽然显示物理卷/dev/sdb3有40G空闲,但是这里不能全部使用,可能只有39.99G可以使用。

7.激活即重新读取磁盘信息

查看/dev/mapper/vg_testcentos6-lv_root的Type为ext4,所以使用resize2fs;如果文件类型是 xfs ,则使用xfs_growfs命令格式化。

[root@test-centos6 ~]# blkid //查看文件系统
/dev/sda1: UUID=”32a489a3-65c2-43a4-9aff-12c03eabc4dd” TYPE=”ext4″
/dev/sda2: UUID=”jMIPOc-sduo-sl4T-6iQ5-ledQ-1w9O-cweeEC” TYPE=”LVM2_member”
/dev/sda3: UUID=”PVrdc7-fUEX-PAxZ-ME92-IuNU-khDC-c5tYlp” TYPE=”LVM2_member”
/dev/mapper/vg_testcentos6-lv_root: UUID=”e8adf717-e78c-4845-a750-2a22a60689ed” TYPE=”ext4″ //可以看到文件系统格式化为ext4
/dev/mapper/vg_testcentos6-lv_swap: UUID=”ac33f130-95cc-4046-8bdd-db2d7c450f6d” TYPE=”swap”

[root@test-centos6 ~]# resize2fs /dev/mapper/vg_testcentos6-lv_root //ext4文件系统使用resize2fs
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_testcentos6-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/vg_testcentos6-lv_root to 15073280 (4k) blocks.
The filesystem on /dev/mapper/vg_testcentos6-lv_root is now 15073280 blocks long.

[root@test-centos6 ~]# df -h //查看激活状态
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_testcentos6-lv_root
57G 4.4G 50G 9% /
tmpfs 1.9G 244K 1.9G 1% /dev/shm
/dev/sda1 485M 58M 403M 13% /boot

可以看到现在我们的磁盘已经从最开始的19G扩展到了57G。

CentosYUM源报错 Invalid release/repo/arch combination

记录线上Centos6系统服务器,yum报错问题

问题:
  • 线上6版本服务器突发yum执行报错,“Invalid release/repo/arch combination/”
处理过程:

由于Centos6已于今年11月停止支持,这是官方源站下的readme

This directory (and version of CentOS) is deprecated. Please see this FAQ
concerning the CentOS release scheme:

https://wiki.centos.org/FAQ/General

Please keep in mind that 6.0, 6.1, 6.2, 6.3, 6.4 , 6.5, 6.6, 6.7, 6.8 , 6.9 and 6.10 no longer get any updates, nor
any security fix's.
The whole CentOS 6 is *dead* and *shouldn't* be used anywhere at *all*

由于centos6停止支持,官方把源移到了https://vault.centos.org/6.8/下, 所以会报错。

解决办法:

原repo

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirrorlist.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

更改后:

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://vault.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
附repo配置
# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# vim /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://archives.fedoraproject.org/pub/archive/epel/6.2017-11-07/$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=https://archives.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=https://archives.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

由于后续centos会变为redhat的上游版本,后续可以支持Rocky Linux

centos7 tmp目录出现systemd-private 类似文件夹

  1. 解决向tmp 目录创建文件 ,系统转存到其他目录

症状
/tmp/systemd-private-9301532e5ff749e388f365a25f51e9ea-mariadb.service-zvKlrX/tmp/
/tmp/systemd-private-9301532e5ff749e388f365a25f51e9ea-httpd.service-HRR15v/

原因
为目录名称中提到的服务启用了安全Tmp系统功能。

解决方案
禁用服务的安全Tmp SystemD
//查看 使用了 tmp SystemD 的服务
grep -R PrivateTmp /etc/systemd/
//以 http 为例
vim /etc/systemd/system/multi-user.target.wants/httpd.service
//注意:http2.0在下面路径
vim /usr/lib/systemd/system/httpd.service
//将 PrivateTmp=true 改为
PrivateTmp=false

//重启  Tmp SystemD
systemctl daemon-reload
//重启 httpd
systemctl restart  httpd.service

awk配合xargs的一个用法

工作中有时候需要杀类似下面的很多子进程,想单个的杀实在是很困难(尤其是子进程很多时),

有什么好的办法呢?

[root@tesr root]# ps -ef|grep java|grep cn.

root      3994  3993  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      3995  3994  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      3996  3995  0 21:14 ?        00:00:04 /usr/j2sdk1.4.0_01/bin/java cn.c

root      3997  3995  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      3998  3995  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      3999  3995  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      4000  3995  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      4001  3995  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      4002  3995  0 21:14 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

root      4004  3995  1 21:14 ?        00:01:56 /usr/j2sdk1.4.0_01/bin/java cn.c

root      4005  3995  0 21:15 ?        00:00:00 /usr/j2sdk1.4.0_01/bin/java cn.c

其实就是要把这些行的第二列变成横向的,再全部写到kill -9 的后面就行了. 我们知道,

Awk就是用来取列的,但是awk取到的结果是分为多列的,

#ps -ef|grep java|grep cn.|awk {‘print $2’}

3994

3995

3996

3997

3998

3999

4000

4001

4002

4004

4005

如何让这些列变成行呢,xargs就可以!

# ps -ef|grep java|grep cn.|awk {‘print $2’}|xargs

3994 3995 3996 3997 3998 3999 4000 4001 4002 4004 4005

说白了,xarge就是把很多行变为一行!

如想删除数量比较多的文件
ls | xargs -n 20 rm -fr
ls当然是输出所有的文件名(用空格分割)
xargs就是将ls的输出,每20个为一组(以空格为分隔符),作为rm -rf的参数
也就是说将所有文件名20个为一组,由rm -rf删除,这样就不会超过命令行的长度了

再杀的话就很简单了!

Kill -9 3994 3995 3996 3997 3998 3999 4000 4001 4002 4004 4005就行了.

写下这点东西才真正的学会awk和xarge ,大家不妨也试试??

更多关于find,xargs请参考http://www.linuxsir.org/main/?q=node/137#3

Linux如何禁用root账户(There were XXXX failed login attempts since the last successful login.)

警告信息
自从有了一台有公网IP的Linux机器,每次登录就会有这样是信息:

There were 4899 failed login attempts since the last successful login.
Last login: Thu Aug 21 15:45:34 2014 from 87.201.230.138
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

搜搜网络会发现,有好多这样的问题:

其他网友的说法:
你服务器 IP 在那儿,那 SSH 开在 TCP 22 上谁都能连,连上了谁都能输密码,密码错了就在系统里留下一条记录。
要么是被(无差别地)扫到了,要么是有人在盯着你。只说 SSH 登陆这事,如果你关闭密码登陆(或者密码足够健壮),那有个就算有一百万个猴子在试你的密码,你也完全不用担心的。

作为一个不合格的猿人,看到这个信息,就不舒服

关了Root用户
禁用root用户后使用sftp时可能一些目录无法访问

使用root账户登录系统,添加一个普通账户例如test,并为其设置密码
useradd test
passwd test

编辑配置文件/etc/ssh/sshd_config 修改PermitRootLogin 后面的yes 为 no ,并且去掉前面的注释符,同时可以限制失败次数
注意: 这个失败次数是对所有用户都起作用的。

最后重启sshd服务 systemctl restart sshd.service,此时再用root用户登录,如果不能登陆则代表配置成功。如果需要使用root权限,可以使用su/sudo进行切换