우분투 CPU 클럭 조정기로 전기세 절약하기

Linux 2015.04.01 17:05 Posted by 김한별 behonestar

1. 현재 cpu 클럭 확인

$ grep "MHz" /proc/cpuinfo

cpu MHz         : 800.421

cpu MHz         : 800.121


2. 현재 cpu freq scaling 정책 확인

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

performance


3. 사용 가능한 cpu freq scaling 정책

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

performance powersave


4. powersave 모드로 변경

$ echo powersave | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

$ echo powersave | sudo tee /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor


5. 부팅 시 자동으로 powersave 모드로 적용하고 싶다면 rc.local에 등록

$ sudo vi /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

echo powersave | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo powersave | sudo tee /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

exit 0


참고

  1. http://www.xpenology.nl/control-cpu-power-state/
  2. http://askubuntu.com/questions/20271/how-do-i-set-the-cpu-frequency-scaling-governor-for-all-cores-at-once




USB로 Ubuntu Server를 설치했더니 USB를 첫번째 하드 드라이브(/dev/sda)로 인식하여 GRUB 부트로더를 USB에 설치해버렸다. 이로인해 USB가 없으면 Ubuntu로 부팅을 할 수가 없게 되었다. 이것을 해결하기 위해서는 부팅 후 하드 드라이브에 GRUB 부트로더를 재설치해주면 된다.


$ sudo grub-install /dev/sda

$ sudo update-grub


TAG grub, mbr, ubuntu

우분투 torrent 서버 구축 - ftp, rtorrent

Linux 2015.03.22 14:12 Posted by 김한별 behonestar

FTP Server 설정



1. vsftpd 설치

sudo apt-get install vsftpd


2. vsftpd 환경 설정

$ sudo vi /etc/vsftpd.conf

...

# Allow anonymous FTP? (Disabled by default)

anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
...
# You may restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.

chroot_local_user=YES
allow_writeable_chroot=YES

...


3. vsftpd 재실행

$ sudo restart vsftpd



rtorrent 설정



1. rtorrent 설치

sudo apt-get install rtorrent


2. rtorrent 설정

$ cd ~

$ vi .rtorrent.rc

# This is an example resource file for rTorrent. Copy to

# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
#max_uploads = 15

# Global upload and download rate in KiB. "0" for unlimited.
#download_rate = 0
upload_rate = 50

# Default directory to save the downloaded torrents.
directory = ./torrent

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = ./.session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
#port_range = 6890-6999

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whether the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
# dht = auto

# UDP port to use for DHT.
#
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes


3. 외장하드 자동 마운트 설정

$ sudo mkdir /media/verbatim

$ sudo blkid

/dev/sda1: UUID="2de63ca9-e8db-4393-a378-266603ba016e" TYPE="ext4"
/dev/sda5: UUID="ed7d07fa-6e5a-4ded-933f-87133ee4de37" TYPE="swap"
/dev/sdb1: LABEL="VERBATIM HD" UUID="4CA2-F71B" TYPE="vfat"


$ cat /etc/passwd

...

khb:x:1000:1000:khb,,,:/home/khb:/bin/bash


$ sudo vi /etc/fstab

...

# mount device with rw access to specific user

UUID=4CA2-F71B  /media/verbatim vfat    umask=0022,uid=1000,gid=1000      0       0


# allowing ftp access to files outside the home directory chroot
/media/verbatim/torrent /home/khb/torrent       none    bind


4. 필요한 디렉토리 생성

$ cd ~

$ sudo mkdir ./.session

$ sudo mkdir ./watch

$ sudo mkdir ./torrent


5. 자동 마운트 확인하기 위하여 재부팅

$ sudo reboot


6. rtorrnet 실행

$ rtorrent

   *** rTorrent 0.9.2/0.13.2 - ubuntu:866 ***
[View: main]

[Throttle 200/off KB] [Rate   0.0/  0.0 KB] [Port: 6999] [U 0/50] [D 0/0]


방향키 : 목록에서 토렌트 선택

ctrl+d : 선택된 토렌트 정지 / 정지된 토렌트 삭제

ctrl+s : 정지된 토렌트 시작


7. 이제 watch 디렉토리에 torrent 파일을 업로드하면 자동으로 다운로드를 시작한다.



부팅 시 rtorrent 자동 실행



1. screen 설치

sudo apt-get install screen


2. 데몬 스크립트 작성 (create-simple-daemon)

DAEMON_ARGS의 rtorrent 옵션을 생략하면 watch 디렉토리의 torrent 파일을 감지하지 못하는 증상이 발생해서 rtorrent 옵션을 직접 입력하였다. -n 옵션을 사용하면 .rtorrent.rc 파일은 무시된다.

$ sudo cp /etc/init.d/skeleton /etc/init.d/rtorrentd

$ sudo chmod 775 /etc/init.d/rtorrentd

$ sudo vi /etc/init.d/rtorrentd

...
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="screen with rtorrent"
NAME=screen
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="-dmS rtorrent /usr/bin/rtorrent -n -d /home/khb/torrent -s /home/khb/.session -o upload_rate=50 -O schedule=watch_directory,5,5,load_start=/home/khb/watch/*.torrent"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
...


2. 데몬 활성화

$ sudo update-rc.d rtorrentd defaults 97 03


3. 만약 비활성화 하고 싶다면 아래 명령어를 입력

$ sudo update-rc.d -f rtorrentd remove


4. 재부팅 후 screen을 통해 rtorrent가 실행된 것을 확인

$ sudo screen -list

There is a screen on:
        862.rtorrent    (03/25/2015 12:28:19 AM)        (Detached)
1 Socket in /var/run/screen/S-root.


5. detached된 screen으로 접속(attach)

$ sudo screen -r

                   *** rTorrent 0.9.2/0.13.2 - ubuntu:866 ***
[View: main]

[Throttle 200/off KB] [Rate   0.0/  0.0 KB] [Port: 6999] [U 0/50] [D 0/0]


ctrl + a d : screen detach

ctrl + a q : screen quit


참고

  1. schedule 인자값의 의미
  2. magnet 사용하기
  3. rtorrent 문서