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



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