Raspberry Pi调优及开机IP上报功能配置

前一阵到wy上兑换了一个树莓派,拿到手了很开心,于是购买了一个sony C10的SD卡。

然后就是一顿搞。。

装上系统之后发现系统很卡,于是对其进行了一些系统参数配置。

tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0
tmpfs /var/run tmpfs defaults,noatime,nosuid,mode=0755,size=2m 0 0
tmpfs /var/spool/mqueue tmpfs defaults,noatime,nosuid,mode=0700,gid=12,size=30m 0 0

对一些读写较多的地方做了改进,使其不直接读写SD卡;

上面是配置方法,只要将内容加入到/etc/fstab重启即可。

安装chkconfig

sudo apt-get install chkconfig

开机IP上报功能

#!/bin/bash

# check network availability
while true
do
 TIMEOUT=5
 SITE_TO_CHECK="www.sinaapp.com"
 RET_CODE=`curl -I -s --connect-timeout $TIMEOUT $SITE_TO_CHECK -w %{http_code} | tail -n1`
 if [ "x$RET_CODE" = "x200" ]; then
 echo "Network OK, will POST ip..."
 break
 else
 echo "Network not ready, wait..."
 sleep 1s
 fi
done

# get the IP address of eth0, e.g. "192.168.16.5"
ETH0_IP_ADDR=`ifconfig eth0 | sed -n "2,2p" | awk '{print substr($2,1)}'`

# send the Email
#echo "Current time: `date '+%F %T'`. Enjoy it" | mutt -s "IP Address of Raspberry Pi: $ETH0_IP_ADDR" xxx@gmail.com

# POST ip

while true
do
TIMEOUT=5
SITE_TO_POST="xxxx.sinaapp.com/ip.php"
RET_CODE=`curl -s --connect-timeout $TIMEOUT "$SITE_TO_POST" -w %{http_code} -d "ip=$ETH0_IP_ADDR"| tail -n1`
echo "-------------------------------------------";
echo $ETH0_IP_ADDR
echo $RET_CODE
date
echo "-------------------------------------------";
 if [ "$RET_CODE" = "200" ]; then
 echo "POST OK"
 break
 else
 echo "SOMETHING WRONG"
 sleep 1s
 fi
done

服务端

<?php

echo "";

if(!empty($_POST['ip'])&&empty($_GET['get'])){
	$ip=serialize($_POST['ip']);
    $mmc=memcache_init();
    if($mmc==false)
        echo "mc init failed\n";
    else
    {
        memcache_set($mmc,"Rasp_ip",$ip);
        
    }
}else if(!empty($_GET['get'])){
    $mmc=memcache_init();
    if($mmc==false)
        echo "mc init failed\n";
    else{
		$ip= memcache_get($mmc,"Rasp_ip");
        //var_dump($ip);
        echo unserialize($ip);
    }
}