Linux基礎

序列

隨機數

stat

cp /etc/skel/. /test/ -rf

cp -Rvp

vim

0 $ gg G gg=G

命令行快捷鍵

Ctrl + u 刪除當前到行首

Ctrl + k 刪除當前到行尾

Ctrl + a 跳轉行首

Ctrl + e 跳轉行尾

Ctrl + s  解救-->Ctrl + q

v V

Ctrl + shift + c 複製

Ctrl + shift + v 粘貼

ntpdate pool.ntp.org

rdate IP



wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

wget http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm


yum -y groupinstall "Additional Development" "Development tools" "Desktop Platform Development" "Server Platform Development"

yum -y install vim-common vim-enhanced

vim /etc/sysconfig/selinux

chkconfig --list|awk '{print $1}'


for i in `chkconfig --list|awk '{print $1}'`;do chkconfig $i off;done

for i in sshd network rsyslog;do chkconfig $i on;done


vim /etc/sysconfig/network-scripts/ifcfg-eth0 

vim /etc/ssh/sshd_config

UseDNS no

GSSAPIAuthentication no


yum -y install sysstat


sar

解決:

Cannot open /var/log/sa/sa30: No such file or directory

sar -o 1 2

sar -n DEV


yum -y install strace

yum -y install lsof


gdb

ldd 

lsof

ps

pstack

strace

ipcs

top

free

vmstat

iostat

sar

readelf

objdump

nm

size

wget

scp


mount -o remount,rw /


Linux 釋放內存

echo 3 > /proc/sys/vm/drop_caches 


開機-BIOS-mbr-grub-內核-init-inittab-sysinit-fstab-rc.local-登錄


find命令

crontab

分 時 日 月 周


nfs 服務建立步驟


複製隱藏文件

cp -Rvp /aaa/. /bbb


for i in `chkconfig --list|awk '{print $1}'`;do chkconfig $i off;done

for i in sshd network rsyslog;do chkconfig $i on;done


快速啓動:(刪除)

rhgb quiet


yum -y install xinetd

chkconfig xinetd on


簡單時間服務器:37 端口

time-dgram

time-stream

disable         = no

------------------------------------------------------------------------------------------------------------------

託管ssh到xinetd前:

[root@localhost ~]# netstat -ntulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1238/sshd           

tcp        0      0 :::37                       :::*                        LISTEN      1355/xinetd         

tcp        0      0 :::873                      :::*                        LISTEN      1355/xinetd         

tcp        0      0 :::22                       :::*                        LISTEN      1238/sshd           

udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1158/dhclient       

udp        0      0 :::37                       :::*                                    1355/xinetd   


[root@localhost ~]# which ssh

/usr/bin/ssh

[root@localhost ~]# which sshd

/usr/sbin/sshd

[root@localhost ~]# cat /etc/xinetd.d/rsync 

# default: off

# description: The rsync server is a good addition to an ftp server, as it \

#       allows crc checksumming etc.

service rsync

{

        disable = no

        flags           = IPv6

        socket_type     = stream

        wait            = no

        user            = root

        server          = /usr/bin/rsync

        server_args     = --daemon

        log_on_failure  += USERID

}

對比和rsync差別

[root@localhost ~]# cat /etc/xinetd.d/ssh 

# default: off

# description: The rsync server is a good addition to an ftp server, as it \

#       allows crc checksumming etc.

service ssh

{

        disable = no

        socket_type     = stream

        flags           = IPv6

        protocol        = tcp

        wait            = no

        user            = root

        server          = /usr/sbin/sshd

        server_args     = -i

        log_on_failure  += USERID

}


[root@localhost ~]# netstat -ntulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 :::37                       :::*                        LISTEN      1234/xinetd         

tcp        0      0 :::873                      :::*                        LISTEN      1234/xinetd         

tcp        0      0 :::22                       :::*                        LISTEN      1234/xinetd         

udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1160/dhclient       

udp        0      0 :::37                       :::*                                  



log_type            = FILE /var/log/servicelog

port = 2222 需要先修改裏面的端口號:/etc/services 對應端口號


[root@localhost ~]# cat /etc/xinetd.d/ssh 

# default: off

# description: The rsync server is a good addition to an ftp server, as it \

#       allows crc checksumming etc.

service ssh

{

        disable = yes

        socket_type     = stream

        flags           = IPv6

        protocol        = tcp

        wait            = no

        user            = root

        server          = /usr/sbin/sshd

        server_args     = -i

        log_on_failure  += USERID

        log_type        = FILE /var/log/ssh_xinetd.log

}


-------------------------------------------------------------------------------------------------------------------------

事務:作爲單個邏輯工作單元執行的一系列操作

ACID:

原子性:事務不可再分

一致性:前後狀態一直

隔離性:未提交不可見

持久性:一提交永久有效

隔離級別:

未提交讀

已提交讀

可重複讀

串行化

-------------------------------------------------------------------------------------------------------------------------

日誌

例如ssh:

SyslogFacility AUTHPRIV

#LogLevel INFO


日誌設備 日誌級別

vim /etc/rsyslog.conf 

# The authpriv file has restricted access.

authpriv.*                                              /var/log/secure


綜上所述:ssh 日誌 /var/log/secure

------------------------------------------------------------------------------------------------------------------------------


date +%F_%H_%M_%S

修改ssh日誌存放:

Starting sshd: /etc/ssh/sshd_config line 37: unsupported log facility 'FILE'

                                                           [FAILED]

  改爲local0-local7

Unspecified GSS failure:已解決GSSAPIAuthentication no

1.sshd 是獨立服務

vim /etc/ssh/sshd_config

SyslogFacility local0


vim /etc/rsyslog.conf 

local0.*                                                /var/log/ssh.log


分別重啓上述服務:service sshd restart service rsyslog restart


2.sshd 託管到xinetd

log_type        = FILE /var/log/ssh_xinetd.log

重啓service xinetd restart


man xinetd.conf

                        SYSLOG  syslog_facility [syslog_level]

                               The log output is sent  to  syslog  at  the

                               specified facility. Possible facility names

                               include:  daemon,  auth,  authpriv,   user,

                               mail,  lpr, news, uucp, ftp local0-7.  Pos-

                               sible level names  include:  emerg,  alert,

                               crit,  err,  warning,  notice, info, debug.

                               If a level is  not  present,  the  messages

                               will be recorded at the info level.


                        FILE  file [soft_limit [hard_limit]]

                               The  log  output  is appended to file which

                               will be created if it does not  exist.  Two

                               limits  on  the size of the log file can be

                               optionally specified.  The first limit is a

                               soft  one;  xinetd  will  log a message the

                               first  time  this  limit  is  exceeded  (if

                               xinetd  logs to syslog, the message will be

                               sent at the  alert  priority  level).   The

                               second  limit  is a hard limit; xinetd will

                               stop logging for the affected  service  (if

                               the  log  file  is  a common log file, then

                               more than one service may be affected)  and

                               will  log  a  message about this (if xinetd

                               logs to syslog, the message will be sent at

                               the alert priority level).  If a hard limit

                               is not specified, it defaults to  the  soft

                               limit  increased  by  1% but the extra size

                               must be within the parameters LOG_EXTRA_MIN

                               and  LOG_EXTRA_MAX  which default to 5K and

                               20K  respectively  (these   constants   are

                               defined in xconfig.h).


log_type        = SYSLOG local0 info

然後

vim /etc/rsyslog.conf 

local0.*                                                /var/log/ssh.log


-------------------------------------------------------------------------------------------------------------

時區時間:

/etc/sysconfig/clock 和 hwclock 相關


時區存放目錄:/usr/share/zoneinfo/

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  或者做軟連接


強制覆蓋:

[root@localhost ~]# alias 

alias cp='cp -i'

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias mv='mv -i'

alias rm='rm -i'

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

[root@localhost ~]# \cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 


交互式:

[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 

cp: overwrite `/etc/localtime'? y


克隆eth0 eth1

[root@localhost ~]# ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:50:56:36:1E:AC  


vim /etc/udev/rules.d/70-persistent-net.rules 

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:36:1E:AC",

 ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

 

vim /etc/sysconfig/network-scripts/ifcfg-eth0 

修改完畢

日誌集中化管理:

Starting system logger: -r option only supported in compatibility modes 0 to 2 - ignored


主服務器:(集中化管理端)

vim /etc/rsyslog.conf

$ModLoad imtcp

$InputTCPServerRun 514

$template RemoteLogs,"/var/log/%FROMHOST-IP%/%PROGRAMNAME%.log" *

*.* ?RemoteLogs

& ~


客戶端:

vim /etc/rsyslog.conf

*.* @@10.10.10.174:514



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章