centos7 ntp settings
systemctl start ntpd
systemctl restart ntpd
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
oldboy
hainan
Please replace the words ending with oldboy in the oldboy.txt file with etiantian
[root@cobub04 ~]# cat oldboy.sh
etiantian
oldboy is good.
hainan
kangjia
CentOS root密码忘记了,如何再次获取root密码?
系统CentOS6:
· 进入计算机后,重置root密码:passwd ## echo "1234" | passwd --stdin root
检查运行级别 runlevel
系统CentOS7 grub模式重置密码参考链接:
/etc/fatab文件最后两列的数字分别表示什么意思?
Centos6修复/etc/fstab文件:
开机按下esc,进入grub模式,详细查看系统启动信息
进入系统后,修改/etc/fstab(由于/etc/fatab中有错误内容,此时不能对此文件进行修改,需要重新挂载根分区)
SSH协议:
1SSH是安全的加密协议,用于服务器远程连接;
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分区.
磁盘分区命令
生产分区建议
常规分区:web集群节点
swap 内存 1.5G(大于8G,就只分8-16G)
/ 剩余分区
数据库和存储分区
swap 内存1,5G(内存大于8G,就只分8-16G)
/80 - 200G
/ 80 - 200G
/data 数据分区
门户网站:灵活分区方式
swap 内存1.5G(内存大于8G,就只分8-16G)
/ 80 - 200G
剩余分区不分,留着.将来领用的部门自己再分.
文件系统:
文件系统是组织和存储数据的一种机制.
磁盘分区后,使用前必须要格式化,创建文件系统,这样操作系统才能识别磁盘的文件组织格式,才能存放数据.
文件系统类型:
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下文件删除的原理
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下软连接和硬连接的区别:
1)默认不带参数情况下,ln命令创建的是硬链接。
2)硬链接文件与源文件的inode节点号相同,而软链接文件的inode节点号与源文件不同。
3)ln命令不能对目录创建硬链接,但可以创建软链接,对目录的软链接会经常被用到。
4)删除软链接文件,对源文件及硬链接文件无任何影响;
5)删除文件的硬链接文件,对源文件及软链接文件无任何影响;
6)删除链接文件的原文件,对硬链接文件无影响,会导致其软链接失效;
7)同时删除原文件及其硬链接文件,整个文件才会被真正的删除。
8)很多硬件设备中的快照功能,使用的就类似硬链接的原理。
9)软连接可以跨文件系统,硬链接不可以跨文件系统。
参考:
http://oldboy.blog.51cto.com/2561410/791292
深入浅出awk,sed,grep
取出系统剩余内存
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
22012
参考:
深入浅出linux系统umask值及其对应的文件权限:
参考: http://oldboy.blog.51cto.com/2561410/1060032