2014年9月3日 星期三

Qt 经典出错信息之”Basic XLib functionality test failed!”(Z..z..)

sudo 指令使用說明

http://note.drx.tw/2008/01/linuxsudo.html

Linux Shell 文字取代、替換

語法: ${變數/預計替換的字串/替換後的字串}   s=${temp/_/ } 將temp變數的底線換成空格,再給變數s.

自定义树莓派的显示分辨率

这个是1080p。
hdmi_group=1 hdmi_mode=16   1080p 60Hz
hdmi_group=2  hdmimode=82,两者皆可
http://shumeipai.nxez.com/2013/08/31/custom-display-resolution-raspberry-pie.html#more-135

Qt编程技巧 Qt图片翻转
http://blog.csdn.net/killua_hzl/article/details/4731292

Qt is now configured for building. Just run 'make'.

Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/Trolltech/Qt-4.7.2

To reconfigure, run 'make confclean' and 'configure'.


自定义树莓派的显示分辨率

http://bbs.shumeipai.org/thread-117-1-1.html

http://blog.csdn.net/neu_sunlei/article/details/5524384

顯示內容中文亂碼的解決:在程序代碼的最開始增加如下代碼:
    QTextCodec *textc=QTextCodec::codecForName("utf8");
    QTextCodec::setCodecForTr(textc);
    QTextCodec::setCodecForCStrings(textc);


下面幾個步驟就可以關閉螢幕保護功能.
  • Install apt-get install x11-xserver-utils
  • Edit /etc/xdg/lxsession/LXDE/autostart
Append these lines:
@xset s noblank
@xset s off
@xset -dpms
Possibly also comment out the line that says @xscreensaver -no-splash, so the complete file should look something like this:
@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
# @xscreensaver -no-splash

@xset s noblank
@xset s off
@xset -dpms
Also edit /etc/kbd/config and make sure these values are set as follows (however I believe this is only for when the lightweight desktop (LXDE) is not running (i.e. the pi is still in text / terminal mode):
BLANK_TIME=0
BLANK_DPMS=off
POWERDOWN_TIME=0
http://blog.csdn.net/c80486/article/details/8460325
树莓派(raspberry pi)学习7: 自动登录、自动运行startx、自动运行程序
http://www.elinux.org/RPi_Debian_Auto_Login
Auto Login:In Terminal:
sudo nano /etc/inittab
Scroll down to:
1:2345:respawn:/sbin/getty 115200 tty1
and change to
#1:2345:respawn:/sbin/getty 115200 tty1
Under that line add:
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
原理:linux启动时,会读取inittab文件,执行其中的登录命令,以pi用户名自动登录
Auto StartX (Run LXDE)
sudo vi /etc/rc.local
su -l pi -c startx
在文件尾部(在exit 0前)加上一行 su pi -c startx
这个命令的意思是,以pi用户的身份,执行startx
(where pi is the username you want to run X as). Press Ctrl+X to exit, Y to save followed by Enter twice.
(Note: The previous method indicated that you should add startx to /etc/profile. The updated method is better, since it will cause startx to run only when necessary, and it will not launch the X server as root.)

窗口系统启动后,自动运行自定义的程序的实现方法
进入当前用户HOME目录下的.config目录(这是一个隐藏目录,需用ls -a显示出来)
cd ~/.config     
当前用户是pi, 其HOME目录是/home/pi, 上述命令相当于 cd /home/pi/.config
建立一个名为autostart的子目录,并进入该目录
mkdir autostart
cd autostart
生成一个*.desktop文件(比如:my.desktop),命令如下:
sudo nano my.desktop
输入以下文件内容:
[Desktop Entry]
Type=Application
Exec=midori
最后一句Exec的值就是要启动的程序名(最好是全路径的可执行文件名),此处是midori浏览器
按CTRL+X退出,记得按Y键存盘
OK了,重新 startx 即可

先用enca -L zh [filename] 偵測檔案編碼
在用enca -L zh -x [要轉換的格式 例如UTF-8] [要轉換的filename] [轉換後的filename]
find Samples -name "*.h" -exec enca -L zh -x UTF-8 {} \;

將 Samples 目錄下, 每一個 .cpp 檔案的 "big5" 揍成 "UTF-8"
find Samples -name "*.cpp" -exec sed -i "s/big5/UTF-8/g" {} \;

找出Samples 目錄下, 有含"big5"字串的 .cpp 檔案內容
find Samples -name "*.cpp" -exec grep "big5" {} \;

sed -i "s/old/new/g" `grep old -rl ./` 在當前文件夾下首先搜索所有含有old字符串的文件,然後再對每個文件執行sed替換命令。

cp /usr/share/zoneinfo/Asia/Taipei /etc/localtime

用rsync+ssh+crontab做主機自動同步備份

http://www.davidpai.tw/ubuntu/2011/rsync_backup/

pi@raspberrypi ~ $ rsync -av --delete -e ssh stephen@192.168.1.98:/home/stephen/img /home/pi

rsync -av --delete -e ssh stephen@www.hokag.com:/home/stephen/test_sync/ /home/pi/tmp/

資料備份同步工具簡介— rsync
http://newsletter.ascc.sinica.edu.tw/news/read_news.php?nid=1742

實用 crontab 寫法
@reboot: 在每次開機時執行。
@yearly: 等同 0 0 1 1 * 寫法,即每年一月一日零時零分。
@annually: 與 @yearly 相同。
@monthly: 在每月一號零時零分執行。
@weekly: 在星期天零時零分執行。 Run once a week, “0 0 * * 0″.
@daily: 每天零時零分。
@midnight: 與 @daily 相同。
@hourly: 每小時零分執行。

SETUP SYSLOG WITH LOGANALYZER ON UBUNTU SERVER

http://www.slsmk.com/setup-syslog-with-loganalyzer-on-ubuntu-server/

http://download.adiscon.com/loganalyzer/loganalyzer-3.6.6.tar.gz

mkdir /var/www/syslog

cp -r /home/stephen/Download/loganalyzer-3.6.6/src/* /var/www/syslog
cp -r /home/stephen/Download/loganalyzer-3.6.6/contrib/*.sh /var/www/syslog
chmod +x /var/www/syslog/*.sh
cd /var/www/syslog/
./configure.sh

usermod -G adm www-data



/var/www/syslog# ln -s /var/www/syslog /home/stephen/wordpress/SysLog_HoKag

bind9-提供Domain Name與IP對應的服務

http://wiki.weithenn.org/cgi-bin/wiki.pl?bind9-%E6%8F%90%E4%BE%9BDomain_Name%E8%88%87IP%E5%B0%8D%E6%87%89%E7%9A%84%E6%9C%8D%E5%8B%99


/usr/sbin/named-checkconf        //檢查 named.conf 語法是否有錯
                           -v     //顯示 named-checkconf 版本

#/usr/sbin/named-checkzone weithenn.org named.weithenn.org      //檢查語法是否有錯
 #/usr/sbin/named-checkzone -d weithenn.org named.weithenn.org   //開啟除錯功能
                            -v                                   //顯示 named-checkconf 版本

使用 Ubuntu 安裝 Bind9: Domain Name Service (DNS)

http://www.nowtaxes.com.tw/node/1114

http://www.chc.edu.tw/skill/dns.htm


Dig 常用參數 與 DNS 偵錯追蹤

http://blog.longwin.com.tw/2013/03/dig-dns-query-debug-2013

DNS 系統設定例--2.named.conf 的例子 (進階型)
http://fanqiang.chinaunix.net/a6/b5/20010521/150001173_b.html

ls -l /dev/disk/by-uuid/
vi /etc/fstab

Ubuntu 版本代碼
lsb_release -a 

CentOS 5 設置 DNS 服務 (CentOS 5 DNS Settings)

https://sites.google.com/site/wyvern2000/home/it/linux/centos-5-dns-settings
目前可以使用 DNS response rate limiting的軟體對 DNS 伺服器進行保護,但需為9.9.2的版本以上方支援,ubuntu 12.04 官方只到9.8.1,所以無此參數,不過,ubuntu有ppa套件,所以可以解決的
如果學校使用ubuntu12.04或miniserver,都可以依照以下方式進行升級bind與參數設定
vi /etc/apt/sources.list
加入這兩行
-------------------------------------------
deb http://ppa.launchpad.net/malcscott/bind9.9/ubuntu precise main

deb-src http://ppa.launchpad.net/malcscott/bind9.9/ubuntu precise main

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

安裝:
apt-get install python-software-properties
sudo add-apt-repository ppa:malcscott/bind9.9

apt-get update

apt-get install bind9

檢查:(升級為9.9.4)
dpkg -l | grep bind9
ii  bind9                                       1:9.9.4-retrosnub1                          Internet Domain Name Server
設定bind9
vi /etc/bind/namd.conf
--------------------------------------------------
options {
        directory "/etc/bind";
        rate-limit {
                responses-per-second 5;
        };
        listen-on-v6 { any; };
        version "Unknown";
};
--------------------------------------------------------------
重啟服務:
sudo service bind9 restart
測試:
while true; do dig @[你的dnsip] +noignore +short +tries=1 +time=1 www.tn.edu.tw A; done
163.26.1.2
163.26.1.2
163.26.1.2
163.26.1.2
163.26.1.2
;; connection timed out; no servers could be reached
163.26.1.2
163.26.1.2
163.26.1.2
;; connection timed out; no servers could be reached
有看到;; connection timed out; no servers could be reached就表示伺服器已建置限制使用量保護
在文字模式的linux server上執行jconsole進行jvm監控
http://cloudtu.blogspot.tw/2013/02/linux-serverjconsolejvm.html
Ubuntu Server 10.04 升級到 12.04 LTS版
http://blog.longwin.com.tw/2012/05/ubuntu-server-upgrade-1204-2012/
若要刪除多餘的網卡設備資訊,只要刪除 /etc/udev/rules.d/70-persistent-net.rules 設定檔並且在重開機之後 udev 就會在開機的過程重新抓到網卡,並給予一個全新且預設的 eth0  介面。
#vi /boot/grub/grub.cfg
set gfxmode=800x600
先編輯:/etc/default/grub
使用root或者sudo去編輯~~
執行 update-grub
使用root或者sudo去執行~~
重新開機即可~~
vi /etc/default/grub
文字模式如何調整字型大小
sudo dpkg-reconfigure console-setup
sudo nano /etc/default/console-setup
1
2
3
W: GPG error: http://ppa.launchpad.net maverick Release:
The following signatures couldn't be verified because the public key is not available:
NO_PUBKEY 1C1E55A728CBC482
網路上找到一篇 [Debian] Apt-get : NO_PUBKEY / GPG error,解決方式非常容易,上面錯誤訊息有告知 public key 是 1C1E55A728CBC482,透過底下兩個步驟就可以成功解決,請注意務必將 public number 換成上面錯誤訊息的號碼
1
2
gpg --keyserver pgpkeys.mit.edu --recv-key  1C1E55A728CBC482    
gpg -a --export 1C1E55A728CBC482 | sudo apt-key add -
1. swapoff /dev/sda3
2. mkswap /dev/sda3    // 產生可提供系統使用的 swap 區域
3. swapon /dev/sda3
4. blkid
5. vi /etc/fstab     // 修正/etc/fstab中的Swap分割區位置:
6. vi /etc/initramfs-tools/conf.d/resume    // 改變休眠回復的分割區UUID
7. update-initramfs -u        // 重建initrd檔

看一下/etc/dphys-swapfile
 cat /etc/dphys-swapfile
默认的大小是100M
CONF_SWAPFILE=100
修改之
 CONF_SWAPSIZE=500
或者更大        重启Raspberry Pi    
查看UUID:
blkid
改變UUID:
tune2fs /dev/sdb1 -U random

Manually resizing the SD card on Raspberry Pi

You can also resize the partitions of the SD card that your Pi is running on.
First you need to change the partition table with fdisk. You need to remove the existing partition entries and then create a single new partition than takes the whole free space of the disk. This will only change the partition table, not the partitions data on disk. The start of the new partition needs to be aligned with the old partition!
Start fdisk:
sudo fdisk -cu /dev/mmcblk0
Then delete partitions with d and create a new with n. You can view the existing table with p.
  • p to see the current start of the main partition
  • d3 to delete the swap partition
  • d2 to delete the main partition
  • n p 2 to create a new primary partition, next you need to enter the start of the old main partition and then the size (enter for complete SD card). The main partition on the Debian image from 2012-04-19 starts at 157696, but the start of your partition might be different. Check the p output!
  • w write the new partition table
Now you need to reboot:
 sudo shutdown -r now
After the reboot you need to resize the filesystem on the partition. The resize2fscommand will resize your filesystem to the new size from the changed partition table.
sudo resize2fs /dev/mmcblk0p2
This will take a few minutes, depending on the size and speed of your SD card.
When it is done, you can check the new size with:
df -h