linux question answer

 

centos7 ntp settings

install ntp service write
yum -y install ntp
enable ntp service 
systemctl enable ntpd
systemctl start ntpd
systemctl restart ntpd
set ntp server
server 0.cn.pool.ntp.org
When the local ntp service is not started, manually sync ntp server write
ntpdate ntpserver   (例如  ntpdate  192.168.1.201)

 

 

 

The difference between single quotes, double quotes or no quotes:

name explain
apostrophe What you see is what you get: that is, output everything inside the single quotes as they are, or describe what you see inside the single quotes and output what you see
Double quotes Output all the content in the quotation marks; if there are commands (to be backquoted), variables, special escape characters, etc. in the content, the variables, commands, and escape characters will be parsed first, and then the final content will be output.
no quotes Similar to the function of double quotation marks, but if there are special characters such as spaces in the string, it cannot be completely output, and double quotation marks need to be added; generally continuous strings, numbers, paths can be without any quotation marks, but the situation without quotation marks is the best Replace with double quotes.
The above conclusions may not be suitable for some languages, for example: awk has special internals.

Reference: The difference between linux shell single quotes, double quotes and no quotes ;

 

 

The content of the known file oldboy.txt is:

oldboy

oldboy is good

hainan

kangjia

Please filter out only the lines that contain oldboy ending and start with h

[root@cobub04 ~]# grep -E "oldboy$|^h" oldboy.txt
oldboy
hainan

 Please replace the words ending with oldboy in the oldboy.txt file with etiantian

[root@cobub04 ~]# sed -i 's#oldboy$#etiantian#g' oldboy.sh
[root@cobub04 ~]# cat oldboy.sh
etiantian
oldboy is good.
hainan
kangjia

 

 

CentOS root密码忘记了,如何再次获取root密码?

系统CentOS6:

· 开机进入grub引导模式:按下esc键,即可进入grub引导模式;

 

· 按下e键,进入编辑模式,选择kernel选项,并再次按下e键,进入编辑模式;

 

· 在最后行末尾添加single或者1(表示以单用户模式启动),然后按下回车键;

 

· 按下b键,启动boot引导程序,然后计算机启动完成;
· 进入计算机后,重置root密码:passwd     ## echo "1234" | passwd  --stdin  root
检查运行级别 runlevel


 

系统CentOS7  grub模式重置密码参考链接:

CentOS7 忘记root密码破解方法

 

 

/etc/fatab文件最后两列的数字分别表示什么意思?

 

Centos6修复/etc/fstab文件:

开机按下esc,进入grub模式,详细查看系统启动信息

进入系统后,修改/etc/fstab(由于/etc/fatab中有错误内容,此时不能对此文件进行修改,需要重新挂载根分区)

mount -o remount, rw /

 

 

SSH协议:

SSH是安全的加密协议,用于服务器远程连接;

2默认端口是22,安全协议版本ssh2;

3服务器主要包含两个服务功能1) ssh远程连接;2)sftp安全FTP文件传输;

SSH连接慢的问题

SSH安全被入侵案例:

http://phenixikki.blog.51cto.com/7572938/1546669;

 

 

磁盘分区:

分区实质:修改分区表,划分起始柱面号和扇区号.

一块磁盘分区:最多4p, 3p+1e, 2p+1e, 1p+1e, 1p, 2p, 3p

p主分区,e扩展分区,l逻辑分区

受操作系统的限制,最多有一个扩展分区;

扩展分区不能直接使用,必须要划分逻辑分区.

fdisk 分区原理,就是修改64字节分区表,不能对大于2T的磁盘分区;

parted GNU 分区工具,可以适合各种分区情况,当然也支持大于2T分区.

磁盘分区命令

fdisk   parted   mkfs(mkfs.ext4)   partprobe   mount  umount  dumpe2fs

 

生产分区建议

常规分区:web集群节点

/boot 100 - 200M
swap 内存 1.5G(大于8G,就只分8-16G)
/ 剩余分区

 

数据库和存储分区

/boot 100-200M
swap 内存1,5G(内存大于8G,就只分8-16G)
/80 - 200G
/ 80 - 200G
/data 数据分区

门户网站:灵活分区方式

/boot 100 - 200M
swap 内存1.5G(内存大于8G,就只分8-16G)
/ 80 - 200G
剩余分区不分,留着.将来领用的部门自己再分.

 

 

文件系统:

文件系统是组织和存储数据的一种机制.

磁盘分区后,使用前必须要格式化,创建文件系统,这样操作系统才能识别磁盘的文件组织格式,才能存放数据.

文件系统类型:

ext2 CDN 公司蓝讯用ext2 做缓存的文件系统;
ext3 (Centos5.X默认文件系统),具备日志功能;
ext4 (Centos6.X默认文件系统),常规应用,视频,数据库,存储; 
xfs  (数据库,淘宝)
jfs 
reiserfs (大量小文件(几十到上百k)首选),Centos5-6不支持,需要单独安装
=====
fat32
ntfs

选择文件系统的关键要看几个方面:维护成本,性能,可靠,要综合权衡.

选择文件系统不是特别的重要,重要的是前端的架构,例如

CDN ---> 内部web cache ---> 数据库和存储cache ---> 磁盘(数据库或存储)

 

/etc/fstab, /proc/mounts, /etc/mtab

 

 

网络文件系统NFS(MFS, GFS)

服务端:

/etc/init.d/rpcbind  start

/etc/init.d/nfs  start

客户端:

/etc/init.d/rpcbind start

showmount  -e  ip

/etc/exports

共享目录 IP或主机名(参数)

 

服务端默认参数: /var/lib/nfs/etab

客户端: /proc/mounts

 

优雅重启: /etc/init.d/nfs  reload

exportfs  -rv

exportfs  直接共享目录,而不需要放置在/etc/exports

exportfs  -o  rw,sync,ip:/data

nfs文件系统优势:1简单易用,2部署方便

劣势:1单点 2客户端和服务端耦合度太高

生产应用:大中小型网站的后面,做集群的共享存储.

解决耦合度太高的方案:

1挂在参数;

2autofs 自动挂载卸载

3弃用NFS,把数据推到应用服务器

 

 

linux下文件删除的原理

答:Linux是通过link的数量来控制文件删除的,只有当一个文件不存在任何link的时候,这个文件才会被删除。一般来说,每个文件都有2个link计数器:i_count 和 i_nlink。
i_count的意义是当前文件使用者(或被调用)的数量,i_nlink 的意义是介质连接的数量(硬链接的数量);可以理解为i_count是内存引用计数器,i_nlink是磁盘的引用计数器。
当一个文件被某一个进程引用时,对应i_count数就会增加;当创建文件的硬链接的时候,对应i_nlink数就会增加。
对于删除命令rm而言,实际就是减少磁盘引用计数i_nlink。这里就会有一个问题,如果一个文件正在被某个进程调用,而用户却执行rm操作把文件删除了,那么会出现什么结果呢?当用户执行rm操作删除文件后,再执行ls或者其他文件管理命令,无法再找到这个文件了,但是调用这个删除的文件的进程却在继续正常执行,依然能够从文件中正确的读取及写入内容。这又是为什么呢?
这是因为rm操作只是将文件的i_nlink减少了,如果没其它的链接i_nlink就为0了;但由于该文件依然被进程引用,因此,此时文件对应的i_count并不为0,所以即使执行rm操作,但系统并没有真正删除这个文件,当只有i_nlink及i_count都为0的时候,这个文件才会真正被删除。也就是说,还需要解除该进程的对该文件的调用才行。
以上讲的i_nlink及i_count是文件删除的真实条件,但是当文件没有被调用时,执行了rm操作删除文件后是否还可以找回被删的文件呢?
前面说了,rm操作只是将文件的i_nlink减少了,或者说置0了,实际就是将文件名到inode的链接删除了,此时,并没有删除文件的实体即(block数据块),此时,如果及时停止机器工作,数据是可以找回的,如果此时继续写入数据,那么当新数据就可能会被分配到被删除的数据的block数据块,此时,文件就会被真正的回收了,那时就是神仙也没有办法了。

 参考:

linux下文件删除的原理精华讲解

Web服务器磁盘满故障深入解析 

 

 

linux下软连接和硬连接的区别:

答:在linux系统中,链接分两种 :一种被称为硬链接(Hard Link),另一种被称为符号链接或软链接(Symbolic Link)。
1)默认不带参数情况下,ln命令创建的是硬链接。
2)硬链接文件与源文件的inode节点号相同,而软链接文件的inode节点号与源文件不同。
3)ln命令不能对目录创建硬链接,但可以创建软链接,对目录的软链接会经常被用到。
4)删除软链接文件,对源文件及硬链接文件无任何影响;
5)删除文件的硬链接文件,对源文件及软链接文件无任何影响;
6)删除链接文件的原文件,对硬链接文件无影响,会导致其软链接失效;
7)同时删除原文件及其硬链接文件,整个文件才会被真正的删除。
8)很多硬件设备中的快照功能,使用的就类似硬链接的原理。
9)软连接可以跨文件系统,硬链接不可以跨文件系统。

 参考:

http://oldboy.blog.51cto.com/2561410/791292

 

 

深入浅出awk,sed,grep

取出系统剩余内存

awk同时取行取列
[root@web monitor]# free -m
total used free shared buffers cached
Mem: 7991 7757 234 0 172 1605
-/+ buffers/cache: 5979 2011
Swap: 2047 583 1464
You have new mail in /var/spool/mail/root
[root@web monitor]# free -m|awk 'NR==3 {print $NF}'
2011
sed取行awk取列 
[es@master001 es-node01]$ free -m | sed -n '3p' | awk '{print $NF}'
22012

参考:

深入浅出三剑客之awk必杀技一例

深入浅出linux三剑客之sed必杀技一例

 

深入浅出linux系统umask值及其对应的文件权限:
参考: http://oldboy.blog.51cto.com/2561410/1060032

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326880276&siteId=291194637