User Tools

Site Tools


protected:member:data

This is an old revision of the document!


Linux server

  • 增加使用者建議使用 adduser較useradd為佳 會自動設定目錄 密碼 以及shell(自動複製.bashrc)
  • vi /etc/passwd 改使用者剛進去的位置, ex:課堂上的使用者xx 把/home/xx 改成 /home/mlb/xx , 再把home底下的xx資料夾mv 到mlb底下
  • 在/home改權限, 讓其他使用者無法在妳的資料夾ls : chmod 711 xx
  • 刪除使用者建議使用 deluser 或 userdel -r 可依並刪除目錄
  • 將A使用者加入B Group: gpasswd -a A B
  • 新增使用者並設定UID GID (為了符合mount 硬碟內資料的權限)
sudo adduser --uid 1011 --gid 1000 --home /homeL/guy --shell /bin/bash
  • 新增apt source list
sudo vi /etc/apt/sources.list
  • 至NCHC網頁中間部分選擇ubuntu版本

複製(ex.)

deb http://free.nchc.org.tw/ubuntu/ lucid main 
deb-src http://free.nchc.org.tw/ubuntu/ lucid main 

貼上至sources.list最末行,即完成增加更新主機列表的動作

  • 改sudo權限的使用者
sudo vi /etc/sudoers

NIS+NFS

client

  • HDD / 30G swap 8G /local_home remain

使用者名稱mbi 密碼
-再編輯resolv.conf (應該不用,如果是從終端機就要再這邊設定)

  • (9.04)更新語言包 (左上角那邊找一下)
  • 更新套件 (進入終端機案crtl+alt+f1),ctrl+alt+f7可以切換回圖形介面
  • 設定網路

更新ubnuntu

  1. 先隨便連一個網路
  2. apt-get update
  3. apt-get upgrade
  4. 重新設定網路,
    • ip = 192.168.1.2(01+1)(後面的電腦 如果是merry01)
    • mask = 255.255.255.0
    • gateway = 192.168.1.1
    • dns = 140.116.72.14
  5. 連到接到merry的區網
  • 安裝NIS
  1. apt-get install portmap nis –> fail 一次裝好protmap(nis nfs的協定) nis
  2. sudo vi /etc/yp.confg 改ypserver 192.168.1.1
  3. ypserver merry(不知要步要 ㄏ)
  4. sudo domainname merry
  5. sudo make -C /var/yp
  6. sudo service portmap restart
  7. sudo /etc/init.d/nis restart (不成功也沒差)
  8. 重開機, 可以先確定一下vi順不順

-clinet 端 (設在後面的電腦)
以下步驟要確定vi很順,不然會無法重開機且失敗機率很高。如果真的不順就重開機或重灌吧。

  1. sudo vi /etc/passwd 加上+:::::: (指令'rpcinfo -p [hosts]':rpc 為協定,這個可以看rpc協定打開的port) (sudo vi,通常都是加在檔案的最下面)
  2. sudo vi /etc/group 加上+:::
  3. sudo vi /etc/shadow 加上+::::::::
  4. sudo vi /etc/nsswitch.conf (sudo vi)
    • passwd: compat nis
    • group: compat nis
    • shadow: compat nis
    • hosts: (….略) nis
  5. 在/etc/resolv.conf設nameserver(就是設定dns:140.116.72.14)
  6. /etc/init.d/portmap restart
  7. /etc/init.d/nis restart(如果成功很快就OK)
  8. ypwhich (測試nis是否成功,成功就會出現merry,rpcinfo -p 應該會有ypbind)
  9. sudo aptitude install openssh-server(裝這個才可以ssh)

-server 端 (設在merry,基本上應該已經設好了,除非電腦真的太多了,才有可能要新增)

vi /etc/ypserv.securenets\\
(加入)host 192.168.1.x (client ip)\\
-make -C /var/yp (如果今天有新增使用者,那個使用者馬上就想要到後面的電腦來用的話,有時候沒有辦法用的情形的話,那這個時候就要執行這個程式看看)\\
*安裝NFS (又跑回client端了!!)\\
apt-get install nfs-common\\
mount -t nfs 192.168.1.1:/home /home \\
*自動掛載/home目錄\\

sudo apt-get install autofs (如此一來重開機才可以看到home)
vi /etc/auto.master
最下面加
/home /etc/auto.home (home 代表home目錄)
vi /etc/auto.home
* 192.168.1.1:/home/& (新增此行)

  • clone 到其他台 (如果是複製硬碟之後才要改以下的東西)
  1. 改host名字
  2. vi /etc/hostname
  3. vi /etc/hosts

127.0.1.1 [hosts]

  1. vi /etc/udev/rules.d/70-persistent-net.rules 將PCI device底下的都刪除

重開 設定網路 (把IP 改成正確的)

  1. mount -t nfs 192.168.1.1:/home /home
  • 開機帳號因為沒有nfs的空間所以無法登入
  1. vi /etc/auto.master
  2. banner /home…..
  • ubuntu 沒有chkconfig

apt-get install sysv-rc-conf

Apache2

更改www-data使用者

先建立一新使用者www-user, 更改/etc/apache2/envvars, 改成

export APACHE_RUN_USER=www-user
export APACHE_RUN_GROUP=www-user

再重開apache2即可

Apache2 基本操作

啟動Apache server

sudo /etc/init.d/apache2 start

停止Apache server

sudo /etc/init.d/apache2 stop

重啟動Apache server

sudo /etc/init.d/apache2 restart

使系統上所有使用者都擁有自己的個人網頁

cd /etc/apache2/mod-enabled/
ln -s ../mods-available/userdir.conf userdir.conf
ln -s ../mods-available/userdir.load userdir.load

禁止瀏覽目錄

sudo vim /etc/apache2/sites-avaiable/default

將原指令

<Directory /var/www>
Options Indexes FollowSymLinks MultiViews

改成

<Directory /var/www>
Options -Indexes FollowSymLinks MultiViews

以及

sudo vim /etc/apache2/mods-available/userdir.conf
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
</Directory>
改成
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
AddHandler cgi-script .cgi .pl .php
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec +ExecCGI
</Directory>

限制瀏覽

在想要保護的目錄下, 寫一個.htaccess檔, 內容為

AuthName "Hi, there."
AuthUserFile [passwd path]/.passwd
AuthType Basic
require valid-user

創建具瀏覽權限的名單 .passwd

htpasswd -c [passwd path]/.passwd username (第一次建立.passwd)
htpasswd [passed path]/.passwd username (新增其它具有權限瀏覽的user)

使位於/home/xx/目錄下使用者可執行CGI

修改userdir.conf

sudo vim /etc/apache2/mods-available/userdir.conf
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
AddHandler cgi-script .cgi .pl .php
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec +ExecCGI
</Directory>
再增加以下區段
<Directory /home/xx/*/public_html>
AllowOverride FileInfo AuthConfig Limit
AddHandler cgi-script .cgi .pl .php
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec +ExecCGI
</Directory>

重開apache即可

sudo /etc/init.d/apache2 restart

Ubuntu 10.04LST PHP bug

修改/etc/apache2/mods-available/php5.conf 將以下部分以#號標記

#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_value engine On
#    </Directory>
#</IfModule>

自動轉向do

新增/etc/apache2/sites-available/serv

<Files ~ "^do$">
        SetHandler cgi-script
</Files>

Alias /bp/ "/home/dirty/wrk/BP2010/"
<DirectoryMatch ~ "^/home/dirty/wrk/">
        Options Indexes
        <Limit GET POST>
                Allow from all
        </Limit>
</DirectoryMatch>

在/etc/apache2/sites-enable/

ln -s /etc/apache2/sites-available/serv .

CPAN

execute cpan

sudo cpan

install perl module (ex. JSON)

cpan> install JSON

type “o conf” and list all configur

cpan> o conf

reset configuration of CPAN (You cna select “no” and configure manually)

cpan> o conf init 

write config in config file (don't need config again next time)

cpan> o conf commit

Reset mirror site of CPAN

search mirror site

cpan> o conf urllist shift
cpan> o conf urllist push http://ftp.cse.yzu.edu.tw/pub/CPAN/
cpan> o conf urllist
cpan> o conf commit

http://sial.org/howto/perl/life-with-cpan/
http://www.cpan.org/SITES.html

install GD module

sudo apt-get install libgd-gd2-perl

Setting vim template

  1. create a template (ex. ~/.vim_template/template.zz)
  2. edit .vimrc & add one line:
    autocmd BufNewFile *.pl 0r ~\.vim_template/template.zz

Vim Regular Expressions

shell script

Study

CD-HIT

~serv/cdhit/cdhit -i ndbp.fa -o ndbp.40 -c 0.4 -n 2 -T 0 

PISCES

建議先cp 至欲使用之目錄
更改捷徑 將bin/blastall blastpgp formatdb 連結至目前版本之執行檔

~serv/PISCES/bin/Cull_for_UserSEQ.pl -i ndbp.40 -p 25 -l 50-6000

(使用方式:README)
若出現 mv …錯誤訊息 不管他 再執行一次

Linux C

Perl

    left        terms and list operators (leftward)
    left        ->
    nonassoc    ++ --
    right       **
    right       ! ~ \ and unary + and -
    left        =~ !~
    left        * / % x
    left        + - .
    left        << >>
    nonassoc    named unary operators
    nonassoc    < > <= >= lt gt le ge
    nonassoc    == != <=> eq ne cmp
    left        &
    left        | ^
    left        &&
    left        ||
    nonassoc    ..  ...
    right       ?:
    right       = += -= *= etc.
    left        , =>
    nonassoc    list operators (rightward)
    right       not
    left        and
    left        or xor

未整理

cut -d ':' -f3,6 以分隔字元 :分欄(也可以用regexp) 將3 6欄擷取出
sed '/.+_.+/d' [file] 將file中有NP_xxooxx的行刪掉
my @sortbox =sort {$a→[0] ⇔$b→[0]} @box;
splice 要從array索引值大的開始刪
shell:read (讀取輸入)+ 變數 使用:$變數
sed -n '3p' [file] 從file中取出第三行
awk -f : 以:為分隔
:%s/.*/\U&/ 小寫轉大寫

  • merry的更新及cron.daily

sudo apt-get update
sudo apt-get -y dist-upgrade (如果上面尚未更新完全,可以用這個)
至cron.daily可以看如何讓這個更新自動化

sudo apt-get install openssh-server

Ubuntu

protected/member/data.1471845341.txt.gz · Last modified: by dirty