* w * who **generate password** pwgen 15 3 **use wget sync web size** **package install** 查詢套件 sudo apt-cache search gitlab 檢查可升級或安裝版本 sudo apt-cache policy gitlab-ce 安裝特定版本 sudo apt-get install gitlab-ce=10.4.3-ce.0 升級特定版本 sudo apt-get install --only-upgrade gitlab-ce=10.8.5-ce.0
2016年10月28日 星期五
Linux commands note
2016年7月12日 星期二
Nginx Reverse proxy from VirtualHost to VirtualHost
www.demo.com DNS is go to Server1. /and Reverse proxy to Server2 by server2.demo.com . But Server2 need to known www.demo.com. So we need set header by proxy_set_header.
**Server1**
```
server {
listen 80;
server_name www.demo.com;
location / {
proxy_set_header Host $host;
proxy_pass http://server2.demo.com/;
}
}
```
**Server2 server2.demo.com**
```
server {
listen 80;
server_name www.demo.comt;
root /opt/www/;
index index.html index.htm;
}
```
**Server1**
```
server {
listen 80;
server_name www.demo.com;
location / {
proxy_set_header Host $host;
proxy_pass http://server2.demo.com/;
}
}
```
**Server2 server2.demo.com**
```
server {
listen 80;
server_name www.demo.comt;
root /opt/www/;
index index.html index.htm;
}
```
2015年5月4日 星期一
ffmpeg create thumbnail from local or remote video. with Ruby on Rails example.
ffmpeg create thumbnail from local or remote video.
Important point is -ss is before input file. If you place after input file And remote video. create thumbnail will very slow.
Important point is -ss is before input file. If you place after input file And remote video. create thumbnail will very slow.
local video
$ ffmpeg -ss 5.3 -i "/home/ubuntu/video.mpg" -vframes 1 -f image2 "/home/ubuntu/thumbnail.jpg"
remote video
$ ffmpeg -ss 5.3 -i "http://example.com/video.mpg" -vframes 1 -f image2 "/home/ubuntu/thumbnail.jpg"
Ruby on Rails example
hr = %x[ffmpeg -loglevel error -ss #{m[:time_of]} -i \"#{input_file}\" -y -vframes 1 -vf scale='min(#{size}\\, iw):-1' -f image2 \"#{output_file}\" 2>&1]
- -loglevel error: when error show message.
- -ss: time offset. need before input file
- -i: input file
- -y: force overwrite output file
- -vframe: Set the number of video frames to output. This is an alias for -frames:v
- -vf scale='min(#{size}\\, iw):-1': set thumbnail output size.
- -f image2: For extracting images from a video
- "output_file": thumbnail output file
- 2>&1: return error message
2013年9月3日 星期二
Exim4設定smtp伺服器與檢測
Debian 預設使用Exim4,當伺服器IP為外部IP時,預設值即可使用localhost的smtp來發送信件。但若為內部IP機器時,需進行設定如下,才可正確發信。
發信的成功失敗,可查看/var/log/exim4/maillog。
以下轉貼自【安裝筆記】Exim4 郵件伺服簡單設定與檢測
Debian Etch 套件預設是使用 Exim4,在安裝 base system 套件後即自動啟動,但無法寄出到 Internet,察看 /var/log/exim4/mainlog 訊息後:
** xxx@gmail.com R=nonlocal: Mailing to remote domains not supported
1.編輯並修改 /etc/exim4/update-exim4.conf.conf 下列兩行:
dc_eximconfig_configtype=’internet’ #預設為 local
dc_smarthost=’msxx.hinet.com’ #遠端的SMTP主機,利用它來發送郵件
2.修改 /etc/mailname ,改成你所在寄送郵件的領域(domain)。
3.執行 exim4 -bV 可測試 exim4 的配置有否出錯。
4.重新啟動 exim4:
# /etc/init.d/exim4 restart
5.外部郵件發送測試
# exim4 -bt kenming.wang@gmail.com
以下轉貼自【安裝筆記】Exim4 郵件伺服簡單設定與檢測
Debian Etch 套件預設是使用 Exim4,在安裝 base system 套件後即自動啟動,但無法寄出到 Internet,察看 /var/log/exim4/mainlog 訊息後:
** xxx@gmail.com R=nonlocal: Mailing to remote domains not supported
1.編輯並修改 /etc/exim4/update-exim4.conf.conf 下列兩行:
dc_eximconfig_configtype=’internet’ #預設為 local
dc_smarthost=’msxx.hinet.com’ #遠端的SMTP主機,利用它來發送郵件
2.修改 /etc/mailname ,改成你所在寄送郵件的領域(domain)。
3.執行 exim4 -bV 可測試 exim4 的配置有否出錯。
4.重新啟動 exim4:
# /etc/init.d/exim4 restart
5.外部郵件發送測試
# exim4 -bt kenming.wang@gmail.com
使用rsync建立長時間且不佔硬碟空間的備份
這裏不說明太多rsync其它的使用方式,只重點在“使用rsync建立長時間且不佔硬碟空間的備份”。
測試時可加上-n, --dry-run參數,就不會實際同步大量資料
rsync -n
重點指令為:
rsync -a -e ssh --link-dest=/backup/2013-09-02 x.x.x.x:/path/to/backup /backup/2013-09-03
這個方式會備份IP:x.x.x.x 的資料path/to/backup,備份到本機的/backup/2013-09-03,並參考前一天/backup/2013-09-02的資料,如此已存在的資料就用hard link的方式,從2013-09-02建立到2013-09-03中,就不會實際佔用空間,只有新檔案才會佔用空間。
第一次同步時,2013-09-02不在在,只會出現提示訊息,如
--link-dest arg does not exist: /backup/2013-09-02
往後只要前一天存在就不會重覆佔用空間。
而為了避免意外,如中間可能因故漏了幾天沒備份,因此設定--link-dest的路徑時,可往前查找幾天,如2013-09-02不存在,就再往前找2013-09-01,如此才不會因--link-dest設定路徑不存在,又重覆佔用了一次空間。
而確認是否為hard link,可使用ls -i (檢查檔案的inode number),比對兩個日期中的同一檔案,若相同則代表為hard link,實體為同一個,不會多佔硬碟空間。
若要保留一個月的備份資料,只要刪除2013-08-02之前的資料夾即可。
stderr and stdout to file (sh / bash / csh / tcsh)
stderr and stdout to file
sh: (time date) > wa.txt 2>&1
bash: (time date) >& wa.txt or (time date) &> wa.txt or (time date) > wa.txt 2>&1
csh/tcsh: (time date) >& wa.txt
There are 3 file descriptors, stdin(0), stdout(1) and stderr(2) (std=standard).
2013年4月26日 星期五
Copy a file to multiple directory.
Copy a file to multiple folder. Can use find command and type directory (-type d).
Then use -exec run cp command copy to target {}.
e.g.
find . -name "folder_name" -type d -exec cp /xxx/filename.txt {} \;
e.g.
find . -name "folder_name" -type d -exec cp /xxx/filename.txt {} \;
2013年3月29日 星期五
Set user shell using ssh script to linux base system and sudo problem.
I using ruby ssh library to linux server. then run sudo command.
like "sudo usermod -s /sbin/nologin Chien-Ming-Wang".
centos:
Set user shell: sudo chsh -s /sbin/nologin [login name]
When error: "sudo: sorry, you must have a tty to run sudo"
vi /etc/sudoers
mark line: "Defaults requiretty"
Debian & Ubuntu:
Set user shell: usermod -s /usr/sbin/nologin [login name]
When error: "sudo: no tty present and no askpass program specified"
vi /etc/sudoers
Add line: [login name] ALL=(ALL) NOPASSWD: ALL
FreeBSD:
Set user shell: sudo pw usermod [login name] -s /usr/sbin/nologin
When error: "sudo: no tty present and no askpass program specified"
vi /usr/local/etc/sudoers
Add line: [login name] ALL=(ALL) NOPASSWD: ALL
like "sudo usermod -s /sbin/nologin Chien-Ming-Wang".
centos:
Set user shell: sudo chsh -s /sbin/nologin [login name]
When error: "sudo: sorry, you must have a tty to run sudo"
vi /etc/sudoers
mark line: "Defaults requiretty"
Debian & Ubuntu:
Set user shell: usermod -s /usr/sbin/nologin [login name]
When error: "sudo: no tty present and no askpass program specified"
vi /etc/sudoers
Add line: [login name] ALL=(ALL) NOPASSWD: ALL
FreeBSD:
Set user shell: sudo pw usermod [login name] -s /usr/sbin/nologin
When error: "sudo: no tty present and no askpass program specified"
vi /usr/local/etc/sudoers
Add line: [login name] ALL=(ALL) NOPASSWD: ALL
2013年3月18日 星期一
用ssh tunnel來突破公司的防火牆
用ssh tunnel來突破公司的防火牆
外部電腦能連至Server,但Server不能連至公司內電腦,但公司內電腦能連至Server,此時運用反向Tunnel。
外部電腦不能連至公司內電腦,但內部電腦能連至外部電腦,此時運用反向Tunnel。
外部電腦能連至Server,但Server不能連至公司內電腦,但公司內電腦能連至Server,此時運用反向Tunnel。
- 公司內電腦建立反向Tunnel連至Server: ssh -NfR 2222:127.0.0.1:22 server_ip_or_domain
- 外部電腦建tunnel連至Server: ssh -NfL 4444:localhost:2222 server_ip_or_domain
- 外部電腦 即可連至公司內電腦: ssh -p4444 localhost
外部電腦不能連至公司內電腦,但內部電腦能連至外部電腦,此時運用反向Tunnel。
- 公司內電腦建立反向Tunnel連至外部電腦 ssh -NfR 2222:127.0.0.1:22 external_ip_or_domain
- 外部電腦 即可連至公司內電腦: ssh -p2222 localhost
參數說明
- -L [bind_address:]port:host:hostport
- Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
- -R [bind_address:]port:host:hostport
- Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.
- -N Do not execute a remote command.
- -f Requests ssh to go to background just before command execution.
訂閱:
文章 (Atom)