顯示文章

這裡允許您檢視這個會員的所有文章。請注意, 您只能看見您有權限閱讀的文章。


文章 - biao007h

頁: [1] 2 3
1
     你这个问题太多而且没问到点子上。  什么安全上下文,内容上下文这种称谓不是很好理解,  你可以把它们当成一个个标签,相同的便签的文件或进程具有相同的属性。比如有人送我一堆水果,我可以分成苹果、梨等堆加以区别,这种是根据类型进行区分,我们也可以根据榨汁,生吃等用途进行区别。   但是我们又不知道下一次别人会送我们什么类型的水果,可能这种水果跟以前给的不一样,所以我们需要默认的一堆来放这些东西(在linux上,假设我们安装一个从前没有的软件就属于这种情况,在/etc/selinux/targeted/ 下,我们看到很多对默认类型的定义) 
     selinux这种特性使得我们可以针对特定的软件进行特定的权限限制,这是原先的DAC机制所不具备的,但是selinux受制于DAC机制  (一个例子,一个group组里面有A、B、C三个用户,现有文件1.sh,我想让group组里的A、B可以查看而C不行,B、C可以执行A不行,这种情况用原先的DAC机制就做不到,而用MAC机制就可以)。

2
最近用tc做流控,奈何小弟悟性不高实在看不懂官方文档,小弟想问几个问题,求各位大大解惑
我使用的tc命令如下:
      tc qdisc del dev $DEV root &>/dev/null
      tc qdisc add dev $DEV root handle 1: htb default 2
      tc class add dev $DEV parent 1: classid 1:1 htb rate $[$flow_max*8]kbps ceil $[$flow_max*8]kbps
      tc class add dev $DEV parent 1: classid 1:2 htb rate 1Mbps ceil 1Mbps
      tc qdisc add dev $DEV parent 1:1 handle 11 sfq perturb 10
      tc qdisc add dev $DEV parent 1:2 handle 12 sfq perturb 10
      tc filter add dev $DEV parent 1: protocol  ip prio 8 handle 111 fw classid 1:1
      iptables  -t  mangle -A POSTROUTING -m set --match-set  $IPSET dst -j MARK --set-mark 111
问题1:子类中classid 1:1 htb rate 中htb是子类1:1的默认排序规则吗,后面我们又加了sfq算法在1:1,它会覆盖这个算法,还是先sfq再htb

问题2:handle的作用是什么,为什么qdisc和filter都需要handle而类不需要?

3
Linux 討論版 / 无人值守安装linux问题
« 於: 2016-09-09 15:26 »
小弟想自动化安装linux,操作如下:
1.利用system-config-kickstart生成kickstart配置文件ks.cfg
2.挂载CentOS-6.5-x86_64-minimal.iso,我是虚拟机做的所以我mount   /dev/sr0 /tmp/source
3.cp -rdp /tmp/source/* /tmp/iso/    ;cp ~/ks.cfg  /tmp/iso/
4.编辑/tmp/iso/isolinux/isolinux.cfg  在append initrd=initrd.img 后面加上ks=cdrom:/ks.cfg
5.mkisofs  -quiet -V "make centos" -J -R -T -v -boot-info-table -no-emul-boot -boot-load-size 4 -b isolinux/isolinux.bin -c boot.cat -o ./install.iso  /tmp/iso

6.在新的虚拟机中使用镜像报错:The CentOS disc was not found in any of  your CDROM drives .Please insert the CentOS disc and  press OK to retry.

请问各位大大,我哪步操作错了吗?


我的ks.cfg内容如下:
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$IZh0CBZRKLl8jhl8$84RcFSZwW6SrQZqbtnsrupGIAF5sa6NfM7hLmPvxPDRQaDLO.YDd1tCYRCpE4S.dJ1v2Dtf13/MScQm5mfqHK1
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Chongqing
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --none

#part /boot --fstype=ext4 --size=200
#part / --fstype=ext3 --grow --size=200


repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100

%packages --nobase
@core
%end

4
Linux 討論版 / Re: iptables limit 模块显示问题
« 於: 2016-09-02 10:23 »
–limit
followed by a number; specifies the maximum average number of matches to allow per second.

理論上數字越大,match 的封包就越多...
小弟猜想并验证了下,发现这个参数其实是区间式的,当设定的值低于555的时候,那么就按你设定的值来,当大于555小于588的时候,那么match的都是588,大概情形如下:
n<555                    n
555<n<588           588
588<n<625           625
625<n<666           666
666<n<714           714
714<n<769           769
....

n的峰值为10000,超过10000报错

5
Linux 討論版 / iptables limit 模块显示问题
« 於: 2016-09-01 18:13 »
小弟发现iptables 使用limit模块的时候如果数值小于一定数就显示正常,否则就会偏大,比如
我使用  iptables -R OUTPUT 1 -m set --match-set limitip src -m limit --limit 270/s -j ACCEPT
iptables -n -v -L 显示:
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    3   340 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           match-set limitip src limit: avg 270/sec burst 5

但是如果使用:iptables -R OUTPUT 1 -m set --match-set limitip src -m limit --limit 1855/s -j ACCEPT
显示:
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    5   540 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           match-set limitip src limit: avg 2000/sec burst 5

这个是什么原因导致的呢?

6
Linux 討論版 / Re: rsync读写问题
« 於: 2016-08-23 17:40 »
rsync執行成功的回傳,就是傳輸完畢了
要詳細判斷就要另外用其他指令檢查與比對
文字內容的rsync應該是不會出錯,不放心的話也有checksum的參數,但會多花點效能和時間
同步binary檔比較有可能會不一致,像是mysql的檔案...等等
谢谢rainday大

7
Linux 討論版 / Re: rsync读写问题
« 於: 2016-08-22 14:57 »
找到问题根源了,我脚本中用了IP=`ifconfig |grep "inet addr:"|cut -d: -f2|awk '{print $1}'|grep -v 127.0.0|head -1`,把IP写死就解决了,让IP=具体ip  ,具体原因,有待研究.. 
 顺便问下有什么办法可以判断文件是否传输完毕?$?只能判断命令执行成功与否

8
iptables 有个recent 模块可以限制尝试次数

9
Linux 討論版 / rsync读写问题
« 於: 2016-08-19 16:13 »
rsync 如果同步的时候,被同步的目录正在被其他程序读写,那会发生什么情况?
我rsync远程同步日志到 /home/log/1.1.1.1,但是日志全都放到/home/log下了,我发现/home/log/1.1.1.1目录长期被读写,其他/home/log/2.2.2.2不读写就不会同步到外面,这种问题有什么方法解决吗?

10
是阿,我印象中也是個 function ... ^_^
:'(印象中一直认为function在 /etc/sysconfig/functions 里,惯性思维惹得祸.. 话说这个论坛不能手动删帖,有时候发错帖误导大家也是很头疼呐

11
发现问题所在了..忘记在/etc/rc.d/init.d/functions
里面找了,这里面有个status函数..

12
Linux 討論版 / httpd 启动脚本status执行问题
« 於: 2016-06-17 16:18 »
无意间发现httpd脚本status语句写法很诡异:

 status)
        if ! test -f ${pidfile}; then
            echo $prog is stopped
            RETVAL=3
        else 
            status -p ${pidfile} $httpd
            RETVAL=$?
        fi
        ;;

开始以为status是个函数,后来才发现它是个initctl命令,在脚本中执行的时候是这样的:
[root@cqhdtest ~]# bash  -x  /etc/init.d/httpd status
+ . /etc/rc.d/init.d/functions
++ TEXTDOMAIN=initscripts
++ umask 022
++ PATH=/sbin:/usr/sbin:/bin:/usr/bin
++ export PATH
++ '[' -z '' ']'
++ COLUMNS=80
++ '[' -z '' ']'
+++ /sbin/consoletype
++ CONSOLETYPE=pty
++ '[' -f /etc/sysconfig/i18n -a -z '' -a -z '' ']'
++ . /etc/profile.d/lang.sh
++ unset LANGSH_SOURCED
++ '[' -z '' ']'
++ '[' -f /etc/sysconfig/init ']'
++ . /etc/sysconfig/init
+++ BOOTUP=color
+++ RES_COL=60
+++ MOVE_TO_COL='echo -en \033[60G'
+++ SETCOLOR_SUCCESS='echo -en \033[0;32m'
+++ SETCOLOR_FAILURE='echo -en \033[0;31m'
+++ SETCOLOR_WARNING='echo -en \033[0;33m'
+++ SETCOLOR_NORMAL='echo -en \033[0;39m'
+++ PROMPT=yes
+++ AUTOSWAP=no
+++ ACTIVE_CONSOLES='/dev/tty[1-6]'
+++ SINGLE=/sbin/sushell
++ '[' pty = serial ']'
++ __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'
++ sed -e 's/^[SK][0-9][0-9]//'
++ basename /etc/init.d/httpd
+ prog=httpd
+ '[' -f /etc/sysconfig/httpd ']'
+ HTTPD_LANG=C
+ INITLOG_ARGS=
+ httpd=/usr/local/apache2/bin/httpd
+ pidfile=/usr/local/apache2/logs/httpd.pid
+ lockfile=/var/lock/subsys/httpd
+ RETVAL=0
+ case "$1" in
+ test -f /usr/local/apache2/logs/httpd.pid
+ status -p /usr/local/apache2/logs/httpd.pid /usr/local/apache2/bin/httpd
+ local base pid lock_file= pid_file=
+ '[' 3 = 0 ']'
+ '[' -p = -p ']'
+ pid_file=/usr/local/apache2/logs/httpd.pid
+ shift 2
+ '[' /usr/local/apache2/bin/httpd = -l ']'
+ base=httpd
+ __pids_var_run /usr/local/apache2/bin/httpd /usr/local/apache2/logs/httpd.pid
+ local base=httpd
+ local pid_file=/usr/local/apache2/logs/httpd.pid
+ pid=
+ '[' -f /usr/local/apache2/logs/httpd.pid ']'
+ local line p
+ '[' '!' -r /usr/local/apache2/logs/httpd.pid ']'
+ :
+ read line
+ '[' -z 5333 ']'
+ for p in '$line'
+ '[' -z '' -a -d /proc/5333 ']'
+ pid=' 5333'
+ :
+ read line
+ '[' -z '' ']'
+ break
+ '[' -n ' 5333' ']'
+ return 0
+ RC=0
+ '[' -z /usr/local/apache2/logs/httpd.pid -a -z ' 5333' ']'
+ '[' -n ' 5333' ']'
+ echo 'httpd (pid  5333) is running...'
httpd (pid  5333) is running...
+ return 0
+ RETVAL=0
+ exit 0

但是我手动执行
[root@cqhdtest ~]# status -p /usr/local/apache2/logs/httpd.pid /usr/local/apache2/bin/httpd
status: invalid option: -p
Try `status --help' for more information.

会报错,看了很久的initctl的man文档,也没明白它是怎么执行的,求各位大大解释下


13
肉腳版 / Re: nginx的rewrite规则
« 於: 2016-05-20 09:56 »
聽起來像是要做 r-proxy?

rewrite_log on 再去看 log 吧.
谢谢twu2

14
肉腳版 / nginx的rewrite规则
« 於: 2016-05-19 10:56 »
nginx 怎么把所有请求rewrite成对 某个ip的访问,比如 www.test.com 转成对 192.168.1.2:8080的访问
我写成:       
 if ( $host != 192.168.1.2:8080 ) {
        rewrite ^(.*)$  http://192.168.1.2:8080 last;
}
一直提示访问不了,不加判断的话又提示重定向次数过多,求各位大大解答下

15
雜七雜八 / ffmpeg怎么加参数到srs中
« 於: 2016-05-06 17:45 »
最近小弟有个视频,需要加个ffmpeg 的  vsync drop 方可正常播放,但是需要与srs(simple rtmp server)配合使用,不知道怎么把这个参数加到配置里面,想问下有人清楚吗?

16
Linux 討論版 / Re: linux管道的执行顺序
« 於: 2016-05-04 17:39 »
唔,我先前都沒有想過這個問題呢....
查了一下再加上一些驗證後
我想管線命令的執行狀況大概是這樣:
1.
管線命令會觸發一個緩衝區(buffer)的建立,讓不同程式從中讀取、寫入資料
2.
管線最末端的程式結束時會觸發緩衝區停止擴充
3.
管線前端的程式則會因為無法再寫入至緩衝區、發生錯誤而終止

測試程式:
代碼: [選擇]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
p = 0

txt = open("log.txt", "w")

while p < int(sys.argv[1]):
    p = p + 1
    txt.write("%d\n" % p)
    print(p)

txt.close()

程式列印 1000 次,儘管 head 後只顯示 5,但 log.txt 仍寫入了 1000 行:
代碼: [選擇]
./pipe_test.py 1000 |head -5
程式列印 3000 次,出現 IOError,log.txt 內則寫入了 2680 行:
代碼: [選擇]
./pipe_test.py 3000 |head -5
代碼: [選擇]
IOError: [Errno 32] Broken pipe
若改寫成忽略 IOError:
代碼: [選擇]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
p = 0

txt = open("log.txt", "w")

while p < int(sys.argv[1]):
    p = p + 1
    txt.write("%d\n" % p)

    try:
        print(p)
    except IOError as error:
        pass

txt.close()

則 log.txt 可以順利寫入到 3000 行
ho li high!! :o

17
Linux 討論版 / Re: linux管道的执行顺序
« 於: 2016-05-04 17:24 »
多谢各位大大,小弟也试了下,应该是head取完值就不执行了
[root@cqhdtest ~]# time  (for i in {1..10};do echo $i ;sleep 1; done)|tail -1
10

real   0m10.029s
user   0m0.013s
sys   0m0.006s
[root@cqhdtest ~]# time  (for i in {1..10};do echo $i ;sleep 1; done)|head -1
1

real   0m1.008s
user   0m0.001s
sys   0m0.005s

18
Linux 討論版 / linux管道的执行顺序
« 於: 2016-05-04 10:32 »
最近有个疑问,netstat  -antup|head  -500   类似这条命令中,是netstat 执行完然后截取前500条记录还是,netstat 与head 并行执行,netstat 执行完500条就不再继续?

19
Linux 討論版 / Re: break在括号中失效问题
« 於: 2016-04-20 15:56 »
這個我會 ... 我知道 ...

小括號是 "子程序"
大括號才延續當前程序

另外 ..
你將這幾行打在指令列 , 執行後再用方向鍵 "上" 叫出來看

while : ;do    ewch 1 &>/dev/null||(echo 2 && break);    echo 3 && break; done
小括號裡猶如一個指令一般

while : ;do ewch 1 &>/dev/null||{ echo 2 && break; };    echo 3 && break; done
前大括號後面要空格 , 後大括號前要分號斷行
好厉害!!请收下我的膝盖 ;D ;D

20
Linux 討論版 / break在括号中失效问题
« 於: 2016-04-19 18:13 »
今天发现了一个shell问题,break在脚本里面会失效,比如下面这个脚本:
#!/bin/bash
while : ;do
   ewch 1 &>/dev/null||(echo 2 && break)
   echo 3 && break
done

这个的执行结果是先打印2 和3 然后再break,我不确定是不是我的逻辑有问题,求各位大大指点下

21
http://serverfault.com/questions/191560/how-can-i-do-traffic-shaping-in-linux-by-ip
多谢了哈!其实我自己也有写脚本实现了,但是boss说我的方法太土了,说tc有自带,我找了半天是没有,我自己写的脚本是这样的:
#!/bin/bash
#
. /root/tc_functions
NUM=2
DEV=eth0
init_tc $NUM
while : ; do
#IP=`netstat  -antup|grep ESTABLISHED |grep  80|cut -d ":" -f8`
IP=`netstat -antup|grep ESTABLISHED|grep 80|awk '{print $5}' |grep  -o  "\([0-9]\{1,3\}\.\)\{1,3\}[0-9]\{1,3\}"|sort  -rn |uniq -c|awk '{print $2}'`
free=0
for  i  in $IP
do
   IP16=`ip_to_16 $i`
   if  tc -s filter ls dev $DEV | grep $IP16 &>/dev/null ;then
      continue;
   fi
   for x in `seq $NUM`
   do
      change $x
      if [  $free -eq 1 ];then
         tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip dst $i flowid 1:$x ;
         free=0;
         break 1;
      fi
   done
   
done
 tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip dst 0.0.0.0/0 flowid 1:$[$NUM+1] ;
sleep 30
tc filter del dev eth0 parent 1: protocol ip prio 16 u32;   
done


下面是tc_functions的内容
function hd(){
case $1 in
   10)
      echo a;;
   11)   
      echo b;;
   12)
      echo c;;
   13)
      echo d;;
   14)
      echo e;;
   15)   
      echo f;;
   *)   
      echo $1;;
esac
}
function ip_to_16(){
a=`echo $1|cut -d '.' -f1 `
b=`echo $1|cut -d '.' -f2 `
c=`echo $1|cut -d '.' -f3 `
d=`echo $1|cut -d '.' -f4 `
a1=$[$a/16]
a2=$[$a%16]
b1=$[$b/16]
b2=$[$b%16]
c1=$[$c/16]
c2=$[$c%16]
d1=$[$d/16]
d2=$[$d%16]
q1=`hd $a1`
q2=`hd $a2`
q3=`hd $b1`
q4=`hd $b2`
q5=`hd $c1`
q6=`hd $c2`
q7=`hd $d1`
q8=`hd $d2`
echo $q1$q2$q3$q4$q5$q6$q7$q8
}
function change(){
        PAST=`tc -s class ls dev $DEV|grep  Sent |cut -d ' ' -f3|head -$1|tail -1`
        sleep 1
        NOW=`tc -s class ls dev $DEV|grep  Sent |cut -d ' ' -f3|head -$1|tail -1`
        [ $NOW  -eq $PAST ]&& free=1
}
function init_tc(){
tc qdisc del dev eth0 root
tc qdisc add dev eth0 root handle 1: htb r2q 1
local i
for  i  in `seq $1`
do
   tc class add dev eth0 parent 1: classid 1:$i htb rate 1mbit ceil 1mbit
done
tc class add dev eth0 parent 1: classid 1:$[$i+1] htb rate 2mbit ceil 2mbit
}

测试了下可以运行的,但是不是很好,欢迎大家提出更好的解决方法和建议哈 ;D

22
如题,ip都是随机的,我想让每个ip拥有固定的稳定1M带宽,应该如何设置呢,我使用以下命令:
tc qdisc del dev eth0 root  #删除原有的队列
tc qdisc add dev eth0 root handle 1: htb r2q 1  # 添加队列
tc class add dev eth0 parent 1: classid 1:1 htb rate 1mbit ceil 1mbit #设置带宽
tc qdisc add dev eth0 parent 1:1 handle 10: sfq perturb 10  #给分类配置特殊的排队规则sfq,perturd 10指10s更新一次散列算法
tc filter add dev eth0 parent 1: protocol ip prio 16 u32 match ip dst 0.0.0.0/0 flowid 1:1 #指定filter的过滤规则

但是这样做的结果是所有ip加起来的总带宽才1Mbit,老板要每个ip都那么大带宽,goole了很久没找到解决方法,求各位大大指点下迷津,江湖救急 :'( :'(

23
Linux 討論版 / Re: netstat ip显示问题
« 於: 2016-04-18 11:59 »
看起來沒有不完整
己經是真實連線的IP
確認那台是否有設定錯ip
或是.199.12這台是gateway? nat?...
没有设置错的,你可以做下实验,把ip设成全三位的xxx.xxx.xxx.xxx,netstat会显示不全的,不是全三位的就能正常显示

24
Linux 討論版 / Re: netstat ip显示问题
« 於: 2016-04-18 11:58 »
IPv4-mapped IPv6 ?
http://www.tcpipguide.com/free/t_IPv6IPv4AddressEmbedding-2.htm

但爲什麼不完整我就不知道了... Orz
应该是bug :(

25
Linux 討論版 / netstat ip显示问题
« 於: 2016-04-15 18:09 »
工作中遇到个问题,用netstat -antup显示网络状态的时候,有些ip会显示不全,像下面这个
[root@cqhdtest ~]# netstat -antup
Active Internet connections (servers and established)
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      956/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1034/master         
tcp        0     52 192.168.199.117:22          192.168.199.31:54850        ESTABLISHED 5364/sshd           
tcp        0      0 :::80                       :::*                        LISTEN      1498/httpd         
tcp        0      0 :::22                       :::*                        LISTEN      956/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1034/master         
tcp        0 129941 ::ffff:192.168.199.117:80   ::ffff:192.168.199.12:65060 FIN_WAIT1   -                   
tcp        0 138881 ::ffff:192.168.199.117:80   ::ffff:192.168.199.12:55097 FIN_WAIT1   -     

这个上面的ip 192.168.199.12 实际上是192.168.199.123的ip,请教下有什么办法让它显示完全?

26
谢谢netman大大 ;D

27
一直都认为数据放在最外面的磁道读写速度会比较快,因为线速度快,但是看到硬盘容量计算公式:

硬盘的容量=柱面数(CYLINDER)*磁头数(HEAD)*扇区数(SECTOR)*512B

又产生了疑问,这个计算公式里面的每个磁道的扇区数一样的,如果扇区数一样,说明每个磁道存储的数据一样,所以外面的磁道分布会松散些,也就是不同磁道相同时间内扫过的数据一样的,所以磁道外面的速度并不会比里面的快,所以百思不得解,求各位大大解答下

28
Linux 討論版 / Re: 硬盘mount不上
« 於: 2015-10-29 15:59 »
拿一片live cd從光碟開機到root使用者視窗,用檔案總管視窗去看那一顆壞硬碟有沒有你要的資料不是很快。
挂载都挂载不上,怎么看?

29
Linux 討論版 / 硬盘mount不上
« 於: 2015-10-28 20:48 »
我有个硬盘坏掉了,我用新盘装了centos6.5 32位的系统(原来的盘版本差不多,我要把原来的盘sdb3的数据考到这个盘sdba1)

然后 用命令 mount   /dev/sdb3  /worktmp提示:
/dev/sdb3 already mounted  or  /worktmp  is busy

于是我用fuser -km  /worktmp然后再mount,错误仍然在

最后我就用了 mount  -t  ext4  /dev/sdb3  /worktmp提示以下错误:
mount: wrong fs type, bad option, bad superblock on /dev/sdb3,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

怀疑是surpeblock损坏,于是dumpe2fs   /dev/sdb3  提示:
dumpe2fs 1.41.12 (17-May-2010)
dumpe2fs: Attempt to read block from filesystem resulted in short read while trying to open /dev/sdb3
Couldn't find valid filesystem superblock.

 想问下这种情况还有救吗,里面的数据对我非常重要,又没有备份(屋漏偏逢连夜雨。。),求各位大大支点招,先谢谢了

30
Linux 討論版 / Re: ~/.ssh/消失了
« 於: 2015-10-27 14:15 »
centos6.3  i686 这个版本不可以 ;D

頁: [1] 2 3