顯示具有 arch linux 標籤的文章。 顯示所有文章
顯示具有 arch linux 標籤的文章。 顯示所有文章

2015年3月18日 星期三

XFCE4 無法更改外觀

系統:Arch Linux
桌面:XFCE4

今天重開機進入XFCE4桌面後,發現按鈕變得很醜
發現
應用程式選單 => 設定值 => 外觀 ( Settings Manger -> Appearance ),也無法更改按鈕樣式

上網查了一下,原來是 .config/xfce4/xfconf/xfce4-perchannel-xml/display.xml 這檔案有問題,估計是使用 xrandr 設定雙螢幕解析度時,另外的螢幕抓不到解析度造成的

解法:
.config/xfce4/xfconf/xfce4-perchannel-xml/display.xml 移除掉重新登錄,
如果你移除掉 .config/xfce4/ 整個資料夾,XFCE4桌面會回復最原始設定的樣子

解決後正常的按鈕


參考資料:
https://bbs.archlinux.org/viewtopic.php?id=153432 [Solved] xfce appearance style, icons, and mouse don't change




2015年2月9日 星期一

arch linux安裝yaourt

編輯 /etc/pacman.conf 添加:
[archlinuxcn]
SigLevel = Optional TrustAll
#Server  = http://repo.archlinuxcn.org/$arch
Server = http://mirrors.ustc.edu.cn/archlinuxcn/$arch # 依你國家而異使用速度較快的鏡像,我使用中國的鏡像
同步
# pacman -Sy
安裝
# pacman -S yaourt

開新user
# groupadd bear
# useradd -r -g bear bear
# mkdir -p /home/bear
# chown bear:bear -R /home/bear
查詢group
# vi /etc/group
刪除新增錯誤的group
# groupdel beaer

PKGBUILD 安裝( 因makepkg 不能使用root執行,所以我先開了一個bear 的user )
$ curl -O https://aur.archlinux.org/packages/pa/package-query/package-query.tar.gz
$ tar zxvf package-query.tar.gz
$ cd package-query
$ makepkg -si 
==> ERROR: Cannot find the strip binary required for object file stripping.
( 解決方放: pacman -S binutils,但是仍然會報錯:
make: error while loading shared libraries: libunistring.so.2: cannot open shared object file: No such file or directory
==> ERROR: A failure occurred in build().
    Aborting...
看起來是docker的問題... https://github.com/runtimejs/runtime/issues/30
)
$ cd ..
$ curl -O https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
$ tar zxvf yaourt.tar.gz
$ cd yaourt
$ makepkg -si
$ cd ..


參考資料:
https://wiki.archlinux.org/index.php/Yaourt_(%E6%AD%A3%E9%AB%94%E4%B8%AD%E6%96%87) # Yaourt (正體中文)
https://archlinux.fr/yaourt-en #安裝方法
https://bbs.archlinux.org/viewtopic.php?id=140055 # ERROR: Cannot find the strip binary required for object file stripping 解決方式
https://github.com/archlinuxcn/mirrorlist-repo # Arch Linux CN Community repo mirrors list

2015年2月5日 星期四

Arch 安裝docker

安裝docker ( 必須是64位元電腦,用 file /bin/bash 檢查 )
# pacman -S docker

運行docker
# systemctl start docker

檢查運行狀態
# systemctl status docker

如果運行失敗,則將依賴的包,安裝更新成最新板
bridge-utils
device-mapper
iproute2
lxc
sqlite

設置網路環境
IPv4数据包转发在缺省值的情况下是禁用的,所以容器可能是不起作用的,
需要开启转发,作为root用户运行在主机系统上
# sysctl net.ipv4.ip_forward=1
允许IPv4修改主机的/etc/sysctl.d/docker.conf,需要重新启动:
net.ipv4.ip_forward=1

參考資料:
https://github.com/widuu/docker_course/blob/master/install/docker-arch.md

Arch swap心得

某天裝完docker後忽然發現我電腦沒有配置swap,所以來研究一下如何配置swap

查swap狀態:
$ swapon -s  # 因為swap不是 filesystem( 如ext3 ),因此不能用df -h查到他
$ free -mh

Swap partition

# mkswap /dev/sda2 16777216
mkswap: /dev/sda2: warning: wiping old swap signature.
Setting up swapspace version 1, size = 16777216 KiB
no label, UUID=81b2c757-50c8-4ef3-919f-ca9f94be77ba
警告:所有在/dev/sda2 partition的資料將會遺失

ps.
swap 大小要設多大?
通常是2倍的記憶體大小,或 [(2 x RAM) + 1 MB] = Swap File Size。
Red Hat建議的最小設定
物理内存交换分区(SWAP)
<= 4G至少2G
4~16G至少4G
16G~64G至少8G
64G~256G至少16G
ps 我的電腦RAM是8GB,所以swap 設16777216 是1024*1024*16( 16 GB)

UUID會自動產生,或 使用-U flag去指定UUID
# mkswap -U custom_UUID /dev/sda2
ex.
# mkswap -U 81b2c757-50c8-4ef3-919f-ca9f94be77ba /dev/sda2 16777216
啟用swap
# swapon /dev/sda2

啟用swap當開機後
1. 編輯 /etc/fstab
2. 在最後面加入這行
/dev/sda2 none swap defaults 0 0

Swap file creation

例:產生一個512MB的swap檔案
# fallocate -l 512M /swapfile

# dd if=/dev/zero of=/swapfile bs=1M count=512 #我用這個
設定正確的權限
# chmod 600 /swapfile
設成swap格式
# mkswap /swapfile
啟用swap檔案
# swapon /swapfile
啟用swap當開機後
1. 編輯 /etc/fstab
2. 在最後面加入這行
/swapfile none swap defaults 0 0
注意:
我原本參考鳥哥的方式把swapfile放到 /tmp/swapfile這 ,但是swapon時出現錯誤。
swapon: swapfile: swapon failed: Invalid argument
原因:
So "Invalid argument" should be read as "Your filesystem do not support swap file"
檢查:
# df -h -T  # -T, --print-type print file system type
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda1      ext4       30G   22G  6.5G  77% /
dev            devtmpfs  3.9G     0  3.9G   0% /dev
run            tmpfs     3.9G  960K  3.9G   1% /run
tmpfs          tmpfs     3.9G   49M  3.9G   2% /dev/shm
tmpfs          tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs          tmpfs     3.9G  136K  3.9G   1% /tmp
/dev/sda5      ext4       15G  3.0G   11G  22% /srv
/dev/sda7      ext4      200G   93G   97G  50% /home
tmpfs          tmpfs     789M  4.0K  789M   1% /run/user/1001
tmpfs大概不支持swap file ,所以把他放在根目錄的ext4下面

移除swap

關掉swap
# swapoff -a
移除swap 檔案
# rm -f /swapfile

liunx(btrfs,ext3,ext4,jfs,reiserfs,xfs)文件系统比较
結論:
linux中比较推荐的文件系统是ext4, xfs两种。大量文件存储用xfs小规模文件密集使用用ext4。在特定情况下,可以使用btrfs(它的特性非常全)或者jfs(小文件操作慢,但是随机读写快)。兼容考量下,可以用ext3。不推荐使用reiser4。

參考資料:
https://wiki.archlinux.org/index.php/swap
http://linux.vbird.org/linux_basic/0230filesystem.php#swap
http://superuser.com/questions/16280/swap-partition-size-for-4gb-ram #swap要設多大
http://www.cyberciti.biz/tips/linux-swap-space.html # Red Hat建議swap最小要設多大
http://superuser.com/questions/539287/swapon-failed-invalid-argument-on-a-linux-system-with-btrfs-filesystem # Invalid argument 錯誤解釋
http://wenku.baidu.com/view/4c18863543323968011c92f7.html # liunx(btrfs,ext3,ext4,jfs,reiserfs,xfs)文件系统比较

2015年1月30日 星期五

arch 安裝ejabberd

系統:
Arch Linux
ejabberd 14.12-1 #新的版本和舊的設定有所不同,設定檔是 ejabberd.yml

安裝:
# pacman -S ejabberd

手冊:
# ejabberdctl --help
設定檔目錄:    /etc/ejabberd
ejabberd設定檔:    /etc/ejabberd/ejabberd.yml
ejabberdctl設定檔: /etc/ejabberd/ejabberdctl.cfg
log目錄: /var/log/ejabberd
資料庫目錄: /var/lib/ejabberd
ejabberd node name: ejabberd@localhost

註冊帳號:
# ejabberdctl register bear test.localhost 123456 # 註冊 test.localhost 這個domain的帳號

設定ejabberd.yml(注意:需要兩格空白縮進),把bear在test.localhost帳號以管理者登錄:
88c88,89
-   - "localhost"
---
+ ##  - "localhost"
+   - "test.localhost"
390,393c391,394
-   ## admin:
-   ##   user:
-   ##     - "aleksey": "localhost"
-   ##     - "ermine": "example.org"
---
+   admin:
+     user:
+       - "aleksey": "localhost"
+       - "bear": "test.localhost"

重開機後啟動
# ejabberdctl --node bear@test.localhost start #要先啟動這個
# systemctl start ejabberd

bear@test.localhost這個node有沒有跑:
# ejabberdctl --node bear@test.localhost status

因為ejabberd 資料庫是用Mnesia,而這個系統儲存Erlang node name到備份檔。移除ejabberd後這些資料都還會在,更多erlang mnesiak的操作需另外研究

2015年1月12日 星期一

arch 安裝memcached和php-memcached、php-memcache

安裝系統memcached
$ sudo pacman -S memcached
開機時啟用memcached
# systemctl enable memcached.service
啟動memcached
# systemctl start memcached.service
檢查memcached有沒有跑
# ps aux | grep memcached

# netstat -tap | grep memcached (如果用netstat -ant的話就看預設的port 11211 有沒有開,但是port可以改)
檢查執行中的設定值
$ echo "stats settings" | nc localhost 11211
STAT maxbytes 67108864 #預設最小的64MB
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter 127.0.0.1
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 4 #預設4個threads
STAT num_threads_per_udp 4
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
END
更改memcache設定值:
# vim /etc/conf.d/memcached (注意:2013/5後,裝好memcache,arch不再有這個檔案,要自己建)
# user to run memcached as; also used for pid file ownership
MEMCACHED_USER="memcached"
# see 'memcached -h' for available options
MEMCACHED_ARGS="-m 1024 -l 127.0.0.1 -t 1"
-t 1 =>number of threads to use
-l 127.0.0.1 =>  listen to localhost
預設的port是11211( -p 11211 是禁止的)
-m 1024 => 1024MB RAM分給Memcached(-m 64是禁止的),64MB是最小值
編輯/usr/lib/systemd/system/memcached.service:
 [Unit]
 Description=Memcached Daemon
 After=network.target
 [Service]
-EnvironmentFile=/etc/conf.d/memcached
-ExecStart=/usr/bin/memcached -u $MEMCACHED_USER $MEMCACHED_ARGS
+User=memcached
+# Remove '-l 127.0.0.1' to listen on all addresses
+ExecStart=/usr/bin/memcached -l 127.0.0.1
+Restart=always

 [Install]
 WantedBy=multi-user.target
重啟memcached
# systemctl restart memcached
然後再度檢查執行中的設定值:
STAT maxbytes 1073741824 #更改為1024MB
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter 127.0.0.1
STAT verbosity 0
STAT oldest 0
STAT evictions on
STAT domain_socket NULL
STAT umask 700
STAT growth_factor 1.25
STAT chunk_size 48
STAT num_threads 1 #更改為1個threads
STAT num_threads_per_udp 1
STAT stat_key_prefix :
STAT detail_enabled no
STAT reqs_per_event 20
STAT cas_enabled yes
STAT tcp_backlog 1024
STAT binding_protocol auto-negotiate
STAT auth_enabled_sasl no
STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
END

安裝php memcached 擴展
我曾想用 pacman -S php-memcache 和 pacman -S php-memcached,來安裝,但是就算更改memcache.ini、memcached.ini後在phpinfo()裡面都沒看到memcached載入。

最後使用pecl來安裝
# pecl install memcache
# pecl install memcached
然後把/etc/php/conf.d 下的memcache.ini 、 memcached.ini 註解拿掉,
memcache.ini:
extension=memcache.so
memcached.ini:
extension=memcached.so

如果ubuntu使用apt-get安裝php5-memcache、php5-memcached
# apt-get install php5-memcache php5-memcached
且web server跑的是nginx
先去 /etc/php5/fpm/conf.d 檢查 memcached.ini  memcache.ini
重啟fpm(如果沒有重啟php5-fpm,phpinfo()是不會新增memcache和memcached的擴展的)
# service php5-fpm restart
重啟nginx
# service nginx restart

寫一段程式測試:
$mc = new Memcached();
$mc->addServer("127.0.0.1", 11211);
 
$result = $mc->get("test_key");
 
if($result) {
  echo $result;
} else {
  echo "No data on Cache. Please refresh page pressing F5";
  $mc->set("test_key", "test data pulled from Cache!") or die ("Failed to save data at Memcached server");
}
# php memcache.php
No data on Cache. Please refresh page pressing F5
# php memcache.php
test data pulled from Cache!

批量刪除key特定開頭的緩存

https://stackoverflow.com/a/25168042  memcache and wildcards
新增一個deleteKeysByIndex.php檔案

function deleteKeysByIndex($search) {
    $m = new Memcached();
    $m->addServer('127.0.0.1', 11211); // 127.0.0.1 緩存server IP
    $keys = $m->getAllKeys();
    foreach ($keys as $index => $key) {
        if (strpos($key,$search) !== false) {
            $m->delete($key);
        } else {
            unset($keys[$index]);
        }
    }

    // returns an array of keys which were deleted
    return $keys;
}

$keys = deleteKeysByIndex("CacheKey-User-"); // 刪除 CacheKey-User-開頭的緩存。如:CacheKey-User-1、CacheKey-User-2 ...
print_r($keys);  // 輸出被刪除的key
用法:
$ php deleteKeysByIndex.php

2015年1月6日 星期二

Arch啟用http存取svn和svn搬移log到另一個repos下

系統:
Arch Linux
svn, version 1.8.9+
Apache/2.4.10

目標:
1. 使用http存取svn
2. 搬移一個svn repos的log到另一個repos下

使用http存取svn
我們假設現有的svn倉庫放在這裡:
/home/svn/test
1. 編輯 /etc/httpd/conf/httpd.conf,要注意順序
LoadModule dav_module           modules/mod_dav.so # 取消註解
LoadModule dav_fs_module        modules/mod_dav_fs.so # 取消註解
LoadModule dav_svn_module       modules/mod_dav_svn.so # 新增這行
LoadModule authz_svn_module     modules/mod_authz_svn.so # 新增這行

使用SSL? => 不使用,所以後面設定檔設在vhost中

新建 /home/svn/.svn-policy-file:
[/]
* = r
[REPO_NAME:/]
USER_NAME = rw

新建 /home/svn/.svn-auth-file:
# htpasswd -cs /home/svn/.svn-auth-file USER_NAME #沒有檔案時,新建第一個user
# htpasswd -s /home/svn/.svn-auth-file OTHER_USER_NAME  #在檔案後面新建其他的user

設定權限:
# chown -R http:http /home/svn/test
編輯 /etc/httpd/conf/sites-available/svn.localhost.conf:
(注意:這邊我是設在vhost設定檔中、網路上有些設在httpd-ssl.conf、mod_dav_svn.conf中)
<VirtualHost *:80>
    DocumentRoot "/srv/http/" 必須設不同於svn repos的位置否則出現錯誤:{
Redirecting to URL 'http://svn.localhost/test':
Redirecting to URL 'http://svn.localhost/test':

svn: E195019: Redirect cycle detected for URL 'http://svn.localhost/test'
}
    ServerName svn.localhost
    ServerAdmin you@example.com
    ErrorLog "/var/log/httpd/svn.localhost-error_log"
    TransferLog "/var/log/httpd/svn.localhost-access_log"

    <Directory />
        Options +Indexes +FollowSymLinks +ExecCGI
        AllowOverride All
        Order deny,allow
        Allow from all
    Require all granted
    </Directory>
    <Location /test/>
       DAV svn
       #SVNParentPath /home/svn/test
       SVNPath /home/svn/test
       AuthzSVNAccessFile /home/svn/.svn-policy-file
       AuthName "SVN Repositories"
       AuthType Basic
       AuthUserFile /home/svn/.svn-auth-file
       Require valid-user
    </Location>
    # 如果有其他repos就複製上面粗體那段加在這後面
</VirtualHost>

設定完就加入網址
# a2ensite svn.localhost
重啟apache
# systemctl restart httpd
沒設dns的話記得要設hosts

接著打開瀏覽器 http://svn.localhost/test/ 就能看到svn了,便可使用svn checkout http://svn.localhost/test/trunk/ 來下載svn
注意:
必須使用svn checkout http://svn.localhost/test/trunk/ ,否則會出現錯誤:
$ svn checkout http://svn.localhost/test/
svn: E175002: Unexpected HTTP status 405 'Method Not Allowed' on '/test'

svn: E175002: Additional errors:
svn: E175002: PROPFIND request on '/test' failed: 405 Method Not Allowed

若想要checkout出 svn.localhost/test/ 下所有東西(含branches、tags、trunk),則必須打開SSL用https去存取
打開SSL:
# cd /etc/httpd/conf/
# openssl req -new -x509 -keyout server.key -out server.crt -days 365 -nodes
(會在這資料夾下產生server.key和server.crt)
編輯 /etc/httpd/conf/extra/httpd-ssl.conf:
#SSLSessionCache        "shmcb:/run/httpd/ssl_scache(512000)" #註解掉,我不確定為什麼在這邊要註解掉,因為用 journalctl -xn 查到這行有syntax error,所以註解掉
#SSLSessionCacheTimeout  300 #註解掉
在</VirtualHost> 前加入:
<Location /svn>
   DAV svn
   SVNParentPath /home/svn/
   AuthzSVNAccessFile /home/svn/.svn-policy-file
   AuthName "SVN Repositories"
   AuthType Basic
   AuthUserFile /home/svn/.svn-auth-file
   Require valid-user
</Location>
編輯 /etc/httpd/conf/httpd.conf :
LoadModule ssl_module modules/mod_ssl.so #取消註解
Include conf/extra/httpd-ssl.conf #取消註解

重啟apache後就能用 svn checkout https://svn.localhost/svn/test (因為沒吃到vhost,所以 https://localhost/svn/test 也可以)下載含有trunk、branches、tags的svn資料了,只是他第一次連會要你接受他的憑證

如果要移除svn 在console的某個網址(http)的登錄設定:
$ rm ~/.subversion/auth/svn.simple/xxx #用grep查網址再刪除他

搬移一個svn repos的log到另一個repos下
有兩個repos
svn checkout file:///home/svn/test:
test
├── branches
├── tags
└── trunk
    └── hello.txt
svn checkout file:///home/svn/test2:
test2
├── branches
├── tags
└── trunk
    └── media
        └── cloud
            └── web
                └── internet
欲把test的trunck下的code(hello.txt)搬到test2的trunk/media/cloud/web/internet 下面:
$ sudo svnadmin dump /home/svn/test > test.dump 
$ cat test.dump | svndumpfilter include "trunk" --drop-empty-revs --renumber-revs > test_trunk.dump #只留trunk的資料
用vim移除trunk的資料夾,若沒做這步,之後檔案會移到 trunk/media/cloud/web/internet/trunk 下面
$ vim test_trunk.dump
:1,$s/trunk\///g
或用bash+perl 取代,注意:find到的檔案(test_trunk.dump)和>>儲存的檔案(test_trunk_new.dump)不能為同一隻檔案,否則會造成無窮迴圈,必須另外儲存
$ find . -name test_trunk.dump | xargs perl -ne 'open NEW, ">>test_trunk_new.dump"; s/trunk\///g; print NEW'
將dump檔load進test2 repos
sudo svnadmin load /home/svn/test2 --parent-dir trunk/media/cloud/web/internet --ignore-uuid < test_trunk_new.dump
檢查:
$ svn checkout file:///home/svn/test2/ test2_new
$ tree test2_new
test2_new
├── branches
├── tags
└── trunk
    └── media
        └── cloud
            └── web
                └── internet
                    ├── hello.txt
                    └── trunk
查log有沒有搬移進去:
$ cd test2_new/ ; svn log
------------------------------------------------------------------------
r2 | bear | 2015-01-06 16:33:57 +0800 (二, 06  1月 2015) | 1 line

hello test
------------------------------------------------------------------------
r1 | bear | 2015-01-07 09:29:23 +0800 (三, 07  1月 2015) | 1 line

hello test2
------------------------------------------------------------------------
最後再手動移除 trunk/media/cloud/web/internet 下的trunk資料夾,即成功

參考資料:
https://wiki.archlinux.org/index.php/Subversion_Setup
https://blog.tinned-software.net/merge-two-svn-repositories/ # Merge two SVN repositories
http://stackoverflow.com/questions/1948318/how-to-configure-svn-web-access-for-different-write-permissions # 注意:用SVNPath時要用 <Location /svn/> 而非 <Location /svn>
http://stackoverflow.com/questions/11240581/subversion-405-method-not-allowed # 405 Method Not Allowed 可改用https解決
http://stackoverflow.com/questions/10524646/tortoise-svn-giving-me-redirect-cycle-detected-for-url-domain-svn # DocumentRoot 和 SVNPath 不能設一樣
http://stackoverflow.com/questions/9234852/how-to-replace-strings-in-a-file-and-save-it-as-another-file # bash+perl 取代檔案並另存新檔

2014年12月24日 星期三

Arch 開機自動登錄開啟全屏firefox

系統:Arch Linux
桌面:enlightenment
註:enlightenment 關閉程式熱鍵是ctrl+alt+x 不是alt+f4

需求:
開機自動登錄,然後開啟全屏firefox

開機自動登錄(無須輸入密碼):
https://wiki.archlinux.org/index.php/SLiM_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
修改 /etc/slim.conf:
# default_user simone => default_user username
取消该行的注释,然后将“simone”改为需要自动登录的用户名。
# auto_login no
取消该行的注释,然后将‘no’改为‘yes’
自动登录功能就被启用了。

登錄後自動開啟firefox:
$ cp /etc/skel/.xinitrc ~
編輯.xinitrc:
firefox -new-window localhost/welcome/exhibition(你要打開的網址) &
exec enlightenment_start
這邊似乎可以用 openbox做 https://wiki.archlinux.org/index.php/openbox ,沒試過
https://wiki.archlinux.org/index.php/Xinitrc
注意:
確保取消註釋只有一行exec,因為這將是.xinitrc script的最後一個運行命令; 以下所有命令只會被忽略。
如果只執行exec firefox ,不登錄桌面。會有解析度問題

Firefox打開全屏:
安裝 Real Kiosk 套件 https://addons.mozilla.org/zh-tw/firefox/addon/r-kiosk/

2014年12月19日 星期五

arch 開機執行程式

前言:
每次重開機後,主機與serial port的stty設定都會跑掉,所以想在開機時去設定(重新插拔USB接口設定不會跑掉)

https://raymii.org/s/tutorials/rc.local_support_on_Arch_Linux_and_systemd.html
1. 編輯 /etc/rc.local (如果沒有就自己建一個)
2. 把 /etc/rc.local 權限設成 755,注意:因為是bash,最前面要寫 #!/usr/bin/bash,例:
#!/usr/bin/bash
touch /tmp/1
stty -F /dev/ttyUSB1 raw speed 9600 -crtscts cs8 -parenb -cstopb

3. 編輯 /usr/lib/systemd/system/rc-local.service:
[Unit]
Description=/etc/rc.local compatibility

[Service]
Type=oneshot
ExecStart=/etc/rc.local
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

4. 執行 下面這個指令,他會產生一個symlink 到 /etc/systemd/system/multi-user.target.wants/ 下面
# systemctl enable rc-local.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /usr/lib/systemd/system/rc-local.service.

5. 手動檢測:
# systemctl start rc-local.service

實測結果:
重開機後
touch /tmp/1 會正常執行(執行身份是root),但stty 把他印到/tmp/1 (  stty >> /tmp/1 )則是一片空白,這可能要看開機message... 這挺複雜的....
這位網友遇到同樣的問題: http://www.gobsd.org/viewtopic.php?f=4&t=3239
最後暫時用每次呼叫web api時都設定stty,這會讓使用者每次多等0.3s
之後可以嘗試用cronjob看看

參考資料:
http://stackoverflow.com/questions/18903512/set-up-serial-on-start-up-raspberry-pi # Raspberry Pi 在rc.local設定stty的答案被採納

2014年11月19日 星期三

arch 看syslog

什麼是syslog?
是 system log, 會紀錄誰執行了哪些東西, 有哪些 CRON 或者哪些動作正在被執行等紀錄.

在debian中看syslog:
# tail -f /var/log/syslog
在arch linux看syslog:
# journalctl -f

參考資料:
http://blog.longwin.com.tw/2011/11/linux-data-syslog-logger-2011/

2014年11月10日 星期一

Arch fcitx無法打英文

某天升級fcitx重開機後,發現無法輸入英文,且在fcitx設定裡面也找不到英文輸入法可以加入

嘗試:
重新安裝fctix,在自動安裝fcitx-gtk2和fcitx-gtk3時會報錯
解法:
升級glib2 (但不是真正解決此問題方法)
# pacman -S glib2

查問題:
1. 關閉fctix
2. 在命令列輸入下面這指令看出什麼錯誤
$ fcitx &
...
(ERROR-1136 /build/fcitx/src/fcitx-4.2.8.5/src/lib/fcitx/ime.c:303) IM: open /usr/lib/fcitx/fcitx-keyboard.so fail libicuuc.so.54: cannot open shared object file: No such file or directory
$ locate libicuuc.so
/usr/lib/libicuuc.so
/usr/lib/libicuuc.so.53
/usr/lib/libicuuc.so.53.1
/usr/lib32/libicuuc.so
/usr/lib32/libicuuc.so.53
/usr/lib32/libicuuc.so.53.1
原來是libicuuc.so.53這檔案沒升級
解法:
升級下面這兩個套件
# pacman -S lib32-icu
# pacman -S icu

即可正常使用fcitx

後記:
做了上面的升級後firefox打不開
$ firefox &
[1] 9803
bear@lmannb:~$ XPCOMGlueLoad error for file /usr/lib/firefox/libxul.so:
libicui18n.so.53: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
解法:
升級firefox
# pacman -S firefox

總結:
1. pacman -Syu是個危險的命令
2. linux is free if your time is no value

參考資料:
http://kelvinh.github.io/blog/2013/03/29/fix-fcitx-on-archlinux/ ( 非用這邊解法s )


2014年11月7日 星期五

Arch Linux 的Firefox使用VLC播放rtsp串流

維護頁面時發現該頁面<embed>使用vlc( type="application/x-vlc-plugin" )播放影片(*.avi)和串流(rtsp://)
 
or
  

s
而我的Arch Linux用firefox開出現下面這個錯誤畫面:
解法:
安裝npapi-vlc-git (需先裝vlc,pacman有套件)
$ yaourt -Ss npapi-vlc-git #注意pacman找不到npapi-vlc-git這套件
aur/npapi-vlc-git 2.1.3.100.g417d246-1 (148)
    The modern VLC Mozilla plugin
yaourt太慢的話就用proxychains4 翻牆去下載安裝
# proxychains4 yaourt -S npapi-vlc-git

裝完後重開firefox,<embed>會出現這畫面:
點擊啟用VLC Web.後就能正常看影片

VLC更進階的應用(Firefox plugin API):
http://www.videolan.org/doc/play-howto/en/ch04.html



2014年11月4日 星期二

使用tty7( ctrl+alt+F7 )登錄桌面slim出現錯誤:failed to execute login command

環境:Arch linux
桌面:enlightenment

使用tty7( ctrl+alt+F7 )登錄桌面slim出現錯誤:
failed to execute login command
http://wiki.alpinelinux.org/wiki/SLiM
https://wiki.archlinux.org/index.php/enlightenment
解法:
編輯
~/.xinitrc
加入
exec enlightenment_start  # 這台電腦的桌面是 enlightenment
必須使用tty7登錄桌面後才能遠端或透過web api 播mplayer
不然遠端console用 DISPLAY=:0 mplayer 4.mp4 會出現錯誤:
Xlib: Invalid MIT-MAGIC-COOKIE-1 key vo: couldn't open the X11 display (:0)!

2014年11月3日 星期一

Arch linux start不能開啟桌面

狀況:電腦在外接samsung的LCD螢幕(Model: S24B370H)時無法啟動桌面

http://unix.stackexchange.com/questions/33825/startx-error-when-setting-up-x-server-on-archlinux

在startx出現類似下面的錯誤:
$ startx
...
Loading extension GLX
ile at "var/log/Xorg.0.log" for addigional information.  (EE) Server terminated with error
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error

查log:
/var/log/Xorg.0.log 或 #以root執行startx
/home/user/.local/share/xorg/Xorg.0.log #以user執行startx
依錯誤提示而異
注意:
每次執行startx後Xorg.0.log是整隻檔案重寫,所以不能像apache error log用tail -f 去看他變化,只能重新打開或:edit去看新的log寫什麼

原因:沒裝主機板上顯卡驅動和設定,無須安裝samsung LCD的驅動

查主機板顯卡:
$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
得知主機板是intel的顯卡

安裝intel顯卡driver:
extra/libva-intel-driver 1.4.1-1 [installed]
    VA-API implementation for Intel G45 and HD Graphics family
# pacman -S libva-intel-driver
安裝成功後
$ ls /usr/lib/xorg/modules/drivers
會多出 intel_drv.so*這檔案。同理,安裝nvidia driver後會這邊多出nvidia_drv.so*這檔案

啟動startx出現錯誤:
(EE) No devices detected.
Fatal server error:
no screens found

解法:
設定/etc/X11/xorg.conf
Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection

Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod"  "uxa"
EndSection
注意:
設定在 /etc/X11/xorg.conf.d/20-intel.conf ( 這個路徑是 pacman -S xf86-video-intel 裝完後給我的提示) 上無效

最後
$ startx 即可開啟桌面

調整登錄畫面的解析度
編輯 /etc/X11/xorg.conf  ,在 Section "Monitor" 裡面加入這行
Section "Monitor"
  Option      "PreferredMode" "1920x1080" #你要的解析度
EndSection



Arch linux pacman 安裝軟體出現錯誤

如這篇 使用mplayer播放影片 在安裝mplayer時發生錯誤

# pacman -S mplayer
error: failed retrieving file 'lirc-utils-1:0.9.1.a-3-x86_64.pkg.tar.xz' from mirrors.ustc.edu.cn : The requested URL returned error: 404 Not Found

解法:
# pacman -Syu mplayer #更新package清單和升級所有package然後安裝mplayer
先更新pacman的database,再安裝mplayer(使用pacman -Syu會更新所有安裝的程式)
# pacman -Sy
# pacman -S mplayer

遇到錯誤:
:: Import PGP key 2048R/, "Zuyi Hu <hzy068808@gmail.com>", created: 2014-03-31? [Y/n] Y
error: key "Zuyi Hu <hzy068808@gmail.com>" could not be imported
error: required key missing from keyring
error: failed to commit transaction (unexpected error)
Errors occurred, no packages were upgraded.
解法:
https://wiki.archlinux.org/index.php/Pacman-key#Cannot_import_keys
編輯/etc/pacman.conf
SigLevel = Never # 將SigLevel設定改成Never

注意:
這步會讓pacman安裝不可信任的packages

升級chromium ( chrome的測試板 )後無法執行
$ chromium
/usr/lib/chromium/chromium: /usr/lib/libpci.so.3: version `LIBPCI_3.3' not found (required by /usr/lib/chromium/chromium)
查原因:
$ pacman -Qo /usr/lib/libpci.so.3
/usr/lib/libpci.so.3 屬於 pciutils 3.2.1-1
# pacman -Ss pciutils
core/pciutils 3.3.0-1 (base) [installed: 3.2.1-1]
    PCI bus configuration space access library and tools
原來是pciutils 版本太舊,升級....
# pacman -S pciutils
解決,正常使用。
參考資料:
https://forum.manjaro.org/index.php?topic=19875.0

Arch Internet sharing(透過另一台電腦上網)

環境:
我的電腦有連兩個網路、內網(接有線eth0 or enp0s25)和外網(收無線網路wlan0 or wls1) 有個內網的設備想透過我電腦上外網去更新程式。 內網不能對外,外網可以。
我的電腦enp0s25和內網設備enp2s0(用ifconfig查該點腦是用哪個網路)連同一個無線ap,在同一個LAN

原本要外接usb無線網卡用wpa_supplicant(需另外安裝)連無線網路去更新,但是更新一下網卡就過熱段掉了。才改採用internet sharing的方法
# wpa_supplicant -i wlan0 -c <(wpa_passphrase your_SSID your_key)

參考:https://wiki.archlinux.org/index.php/Internet_sharing
我的電腦:
1. 設定固定IP - 這步我將mac網址寫在無線ap的設定上面去設定固定ip
2. 啟用封包轉發( Enable packet forwarding )
查packet forwarding 設定:
# sysctl -a | grep forward
暫時啟用packet forwarding:
# sysctl net.ipv4.ip_forward=1
如果保留這些設定在重開機後:
編輯/etc/sysctl.d/30-ipforward.conf:
net.ipv4.ip_forward=1
net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1
3. 啟用NAT
# iptables -t nat -A POSTROUTING -o internet0(能上外網的網路) -j MASQUERADE
# iptables -A FORWARD -i net0(內網的網路) -o internet0(能上外網的網路) -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
例:
# iptables -t nat -A POSTROUTING -o wls1 -j MASQUERADE
# iptables -A FORWARD -i enp0s25 -o wls1 -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

設備:
1. 設定固定ip - 將mac網址寫在無線ap的設定上面去設定固定ip
2. 設定route方向
# ip route add default via 192.168.123.100 dev eth0
例:
# ip route add default via 192.168.0.101 dev enp2s0
出現錯誤:
RTNETLINK answers: File exists
解法:
重啟網路
# ifconfig enp2s0 down
# ifconfig enp2s0 up
3. 檢查ping不ping得出去
# ping 114.114.114.114
4. ping得出去後設定DNS
/etc/resolv.conf:
nameserver 114.114.114.114

內網設備即可透過我電腦去更新程式
如:
# pacman -Syu mplayer

shan:此方法適用於linux-like的系統

更快速的方法:proxychains
假設server IP(能上外網那台):192.168.92.2
client IP(只能上內網那台):192.168.92.138
[bear@192.168.92.138 proxychains]$ ssh -NfD 9050 bear@192.168.92.2
[bear@192.168.92.138 ~]proxychains4 curl http://baidu.com
註:
server無須做任何設定,9050 port是client上proxychains.conf預設走的port
socks4     127.0.0.1 9050

client透過server上的shadowsocks上牆外網站
把server(非shadowsocks的server,是internet sharing中的server)的ss跑在0.0.0.0上
然后把client的代理配置到server的IP上
server shadowsocks的config.json配置新增:
"local_address": "0.0.0.0",
client proxychains.conf配置:
socks5  192.168.92.2 8080
最後用這些指令透過ss上網
[bear@192.168.92.138 ~] proxychains4 curl http://facebook.com
[bear@192.168.92.138 ~] proxychains4 pacman -S subversion
特別改謝shell指導

2014/11/27
上述"client透過server上的shadowsocks上牆外網站"情況在使用pacman -Sy更新時會報錯:
error: failed retrieving file 'core.db' from mirrors.163.com : Resolving timed out after 10519 milliseconds
使用iptables方法則正常

參考資料:
http://heylinux.com/archives/2933.html



2014年10月27日 星期一

arch linux xfce擷取螢幕

使用xfce4-screenshooter
https://wiki.archlinux.org/index.php/Taking_a_screenshot#Xfce_Screenshooter
1. 安裝xfce4-screenshooter
2. 開啟"設定值管理員" (Xfce4 ... )
3. 點擊"鍵盤"
4. 點擊"應用程式捷徑"
5. 加入(他會瀏覽/usr/bin 下面的指令)
6. 新增xfce4-screenshooter,榜定熱鍵PrtScn
- xfce4-screenshooter 可以設定幾秒後擷取螢幕,有助於擷取非即時的畫面
存檔位置:擷取後才選擇存哪裡

使用Shutter
存檔位置:預設存在你的家目錄下。ex. /home/david/

Arch使用MySQL原始碼安裝MySQL

因為 http://carlislebear.blogspot.jp/2014/10/install-schema-sync.html 這篇的關係,所以打算把MariaDB移除,手動安裝MySQL

參考連結:
http://shaurong.blogspot.jp/2014/08/mysql-5620targz-centos-70-x8664.html
http://blog.sina.com.cn/s/blog_606a23dd0101g1wr.html

0. 安裝cmake ( 自mysql5.5及以上的源程序包,不再包括configure文件,因此不能直接安装,需要使用cmake来进行安装 )
用pacman 直接安裝或上網找 cmake-xxx.pkg.tar.xz 下來再用pacman裝

1. 到MySQL官網下載MySQL Community Server 
Select Platform: 選擇Source Code

下載最下面的壓縮檔,mysql-5.6.21.tar.gz,並放到/usr/local/src下解壓縮,解壓縮出來要有 CMakeCache.txt 檔才對,INSTALL-SOURCE 4823行左右也有安裝教學

# Preconfiguration setup
shell> groupadd mysql
shell> useradd -r -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz #我解壓縮到/usr/local/src
shell> cd mysql-VERSION
shell> cmake .
shell> make #這步會很久,所花時間是用pacman、apt-get等管理工具不能比的
shell> make install #也很久
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

mysql指令找不到
# which mysql
which: no mysql in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl)
解法1:
將/usr/local/mysql/bin/mysql 用ln -fs 到/usr/local/bin 去
# cd /usr/local/bin
# ln -fs /usr/local/mysql/bin/mysql
# ln -fs /usr/local/mysql/bin/mysqldump
# ln -fs /usr/local/mysql/bin/mysqladmin
解法2:
設定環境變數(未測試)

安裝後用mysql -u root -p 登錄出現錯誤:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解法:
指定登錄位置
mysql -u root -p -h 127.0.0.1

啟用mysql 服務
# /usr/local/mysql/bin/mysqld_safe &
查mysql啟動時的錯誤
# tail -f /usr/local/mysql/data/your_pc_name.err
出現錯誤:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
解法:
(中間下過這些指令,不確定要不要做:
# chmod 777 /usr/local/mysql/support-files/mysql.server
# chown -R mysql:mysql /usr/local/mysql/
)
# /usr/local/mysql/scripts/mysql_install_db --user=mysql
可能當初在裝mysql時,沒有停用原本的MariaDB再裝,造成這句沒有執行成功,執行成功的畫面:
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h lmannb password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.  

在此之前試過 # ./mysql_upgrade -u root -p => 無效

檢查mysql有沒有跑起來:
# ps aux | grep mysql
mysql     4649  3.5  5.6 967604 456952 pts/3   Sl   19:58   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/lmannb.err --pid-file=/usr/local/mysql/data/lmannb.pid