2016년 2월 20일 토요일

Ubuntu

SSH server install

Intsall

sudo apt-get install openssh-server
sudo netstat -anp | grep LISTEN | grep sshd

Port Changing

sudo vim /etc/ssh/sshd_config 
# Port 22
Port 9022
sudo service ssh restart

참고 논문 및 사이트

1. [우분투] SSH Server 설치하기 - http://neoguru.tistory.com/57

2016년 2월 16일 화요일

RaspberryPi - 05

Printer Drive Setting

Change Samba Config

sudo vim /etc/samba/smb.conf
########## Printing ##########

# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
  load printers = yes

# lpr(ng) printing. You may wish to override the location of the
# printcap file
; printing = bsd
; printcap name = /etc/printcap

# CUPS printing. See also the cupsaddsmb(8) manpage in the
# cupsys-client package.
  printing = cups
  printcap name = cups

[프린터명]
  comment = 프린터명
  browseable = yes
  path = /tmp
  printable = yes
  guest ok = yes
  read only = no
  create mask = 0700

[print$]
  comment = Printer Drivers
  path = /var/lib/samba/printers
  browseable = yes
  read only = yes
  guest ok = yes
sudo /etc/init.d/samba restart

Cups Install

sudo apt-get install cups
sudo usermod -a -G lpadmin pi
sudo vim /etc/cups/cupsd.conf 
Listen *:631
WebInterface Yes #웹 인터페이스를 제공합니다.

#웹 설정 페이지의 메인화면 접속 관련 설정입니다.

  Order allow,deny
  Allow all


#설정 페이지 중 직접 설정을 바꿀 수 있는 관리자 페이지 관련 설정입니다.
#시스템 내의 유저 계정으로 접속할 수 있도록 합니다.
#서브넷 상의 pc만 접근할 수 있도록 합니다.

  Order deny,allow
  Allow all


  Order deny,allow
  Allow all
  AuthType Default
  Require user @SYSTEM


sudo /etc/init.d/cups restart

참고 논문 및 사이트

1.라즈비안(데비안) 서버에 usb 프린터 연결하기 - http://dovetail.tistory.com/29

2.라즈베리 파이에 프린터 설치하기 1 - http://flankerd.tistory.com/entry/%EB%9D%BC%EC%A6%88%EB%B2%A0%EB%A6%AC-%ED%8C%8C%EC%9D%B4%EC%97%90-%ED%94%84%EB%A6%B0%ED%84%B0-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0-1

RaspberryPi - 04

File Share Server

Samba?

RaspberryPi Server로 구동시켰던 가장 큰 이유는 프린터 서버를 위해서였다. 어떻게 하면 설치를 할 수 있을까 찾아보다보니 리눅스와 윈도우간 파일 공유를 위한 것이 있는 것을 알게되었다. 삼바는 SMB(Server Message Block)/CIFS(Common Internet File System)라는 프로토콜을 이용하고 있다. 해당 프로토콜이 리눅스와 윈도우간 파일 공유를 할 수 있도록 도와주고 있다.

Install Samba

sudo apt-get install samba samba-common samba-common-bin
sudo /etc/init.d/samba start
sudo /etc/init.d/samba stop
sudo /etc/init.d/samba restart

Add Share option at samba

sudo vim /etc/samba/smb.conf

Modify Home : read only no

Modify Home : create mask 777, directory mask 777

Add : External Folder Setting

#Modify
[homes]
...
read only = no

create mask = 0770

directory mask = 0770
...

# Add 
[External]
comment = External Hard Disk Driver Path
path = /local
read only = no
valid user = pi
browseable = yes
create mask = 0770
directory mask = 0770

Add samba user

sudo smbpasswd -a francis
New SMB password:
Retype new SMB password:
Added user francis.

리눅스에 등록하려고 하는 유저가 없다면 오류가 발생한다. Failed to add entry for user samba.

Linux Add User

계정확인

cat /etc/passwd | grep francis

계정생성

sudo useradd francis

비밀번호 변경

sudo passwd francis

참고 논문 및 사이트

1.라즈베리파이 삼바로 파일공유 설정 - http://dovetail.tistory.com/28

2.제목 : 삼바(SAMBA)서버 사용법 - https://www.linux.co.kr/home/lecture/?leccode=10644

3.리눅스 계정 생성 useradd - http://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_%EA%B3%84%EC%A0%95_%EC%83%9D%EC%84%B1_useradd

Nginx - 03

Setting Password

Apache Util

sudo apt-get install apache2-utils
sudo apt-get install apache2-utils

Create Password

mkdir /local/link/nginx/passwd

생성

sudo htpasswd -c /local/link/nginx/passwd/.htpasswd francis

New password: 
Re-type new password: 
Adding password for user francis

추가

sudo htpasswd /local/link/nginx/passwd/.htpasswd

Nginx Setting

auth_basic "Restricted";
auth_basic_user_file /local/link/nginx/passwd/.htpasswd;

참고 논문 및 사이트

1. NginX 웹페이지에 비밀번호 ( 보안 ) 설정하기 - http://www.tutorialbook.co.kr/entry/NginX-%EC%9B%B9%ED%8E%98%EC%9D%B4%EC%A7%80%EC%97%90-%EB%B9%84%EB%B0%80%EB%B2%88%ED%98%B8-%EB%B3%B4%EC%95%88-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0

2016년 2월 13일 토요일

Nginx - 02

Config Setting

Find nginx config

sudo find / -name nginx.conf

Linking Folder

 ln -s /usr/local/nginx /local/nginx

-s : 심볼릭링크를 생성. ( 없으면 하드링크 생성)

Config Description

- worker_process 1 : Process 개수가 한 개. (cf. CPU 코어 개수만큼 할당)

- worker_connections 1024 : Process가 동시 접속 처리가 1024개.

- keepalive_timeout 65 : 클라이언트 접속 유지시간

참고 논문 및 사이트

1. NGINX 환경설정 - https://opentutorials.org/module/384/4526

2. [LINUX] 심볼릭 링크 & 하드 링크 - http://egloos.zum.com/sunnmoon/v/1858692

3. Nginx HTTP Server - 3. 환경설정 - http://ohgyun.com/479

4. Nginx Report v1.1 - http://egloos.zum.com/edendev/v/3257937

Nginx - 01

Ngnix Install

Download

Nginx Download Homepage
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -xvzf nginx-1.8.1.tar.gz 
Prce Directory Homepage
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar -xvzf pcre-8.38.tar.gz
Open ssl
wget http://www.openssl.org/source/openssl-1.0.2f.tar.gz
tar -xzvf openssl-1.0.2f.tar.gz;
Zlib
wget http://zlib.net/zlib128.zip
unzip zlib128.zip

Install

sudo ./configure --with-zlib=../zlib-1.2.8 --with-pcre=../pcre-8.38 --with-openssl=../openssl-1.0.2f --with-http_ssl_module --with-debug --prefix=/usr/local/nginx --user=www-data --group=www-data
sudo make
sudo make install
sudo /usr/local/nginx/sbin/nginx
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx -s reload

Raspberry pi not working

sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx;
sudo chmod +x /etc/init.d/nginx;
sudo update-rc.d -f nginx defaults
service nginx start : 시작 
service nginx stop : 정지
service nginx restart : 재시작
service nginx reload : 설정파일을 재로드
service nginx status : 현재 상태 

참고 논문 및 사이트

1. NGINX 컴파일 - https://opentutorials.org/module/384/4511

RaspberryPi - 03

Root Storage

파티션 리스트 확인

SD Card 가 16G 임에도 4G만 잡혀있는것올 확인할 수 있다.

sudo fdisk -l

파티션 수정

sudo fdisk -u -c /dev/mmcblk0

파티션 리스트 확인

Command (m for help) : p
/dev/mmbcblk0p1
/dev/mmbcblk0p2 122880 
Command (m for help) : d
Partition number(1-4) : 2
Command (m for help) : n
Select (default p) : p
Partition number(1-4, default 2) : 2
First sector : 122880
Last sector : (etner)
Command (m for help) : w
sudo reboot -h now
sudo resize2fs /dev/mmcblk0p2
sudo df -h

참고 논문 및 사이트

1. 라즈베리파이 파티션 용량 늘리기 - http://zelits.tistory.com/65

Nodejs - 02 - torrent

Torrent-web

Install 실패

sudo npm install -g bower
sudo npm install -g torrent-web

nodetorrent-wrapper

Install 성공했으나 실행방법 제공 하지 않아서 패스

git clone https://github.com/kjellberg/nodetorrent.git
cd nodetorrent
npm install
node build.js

peerflix-server

Install 성공

sudo npm install -g peerflix-server
peerflix-server
sudo npm install -g forever
forever start /usr/local/bin/peerflix-server
vim ~/.config/peerflix-server/config.json

참고 논문 및 사이트

1. torrent-web - https://www.npmjs.com/package/torrent-web

2. nodetorrent-wrapper - https://www.npmjs.com/package/nodetorrent-wrapper

3. peerflix-server - https://github.com/asapach/peerflix-server

Nodejs - 01 - Npm Config

npm -g option

Nodejs 설치해서 사용하면 -g를 이용하여 npm install 을 하는 경우가 있는데 어디에 설치 되는지 경로를 지정할 수 없는지 궁금한 경우가 있다. 이 포스팅은 해당 내용을 어떻게 작동할 수 있는지 설명하고 있다.

설정 정보 경로 확인

아래의 명령어를 작동하면 해당 되는 파일들의 존재 경로를 확인할 수 있습니다.

npm config ls -l | grep 'config'
globalconfig = "/usr/local/etc/npmrc"
userconfig = "/home/pi/.npmrc"

Nodejs를 처음 설치하고 나서 해당 파일 경로를 확인해본 결과 아직 존재하지 않았다.

그리고 아래의 명령어를 확인하면 -g global option을 적용했을시 설치가 되는 경로를 확인할 수있다.

npm config get prefix
/usr/local

설정 정보 변경

위에서 확인했던것과 같이 처음 생성했다면 userconfig="/home/pi/.npmrc"가 존재하지 않을 수도 있다. 존재하지 않는다면 새로 작성해주고 아래의 부분을 추가 시킨다.

vim /home/pi/.npmrc
# prefix = {path}
prefix = /local/node
npm config get prefix

다시 명령어를 이용하여 확인하면 변경된것을 확인할 수 있다.

/local/node

참고 논문 및 사이트

1. How do I fix npm's global location? - http://stackoverflow.com/questions/6685892/how-do-i-fix-npms-global-location

2016년 2월 12일 금요일

RaspberryPi - 02

Linux Disk Format

Partition Confirm

sudo fdisk -l
Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        8192  131071  122880   60M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      131072 8060927 7929856  3.8G 83 Linux

Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x32b52955

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 625139711 625137664 298.1G  7 HPFS/NTFS/exFAT

/dev/sda Disk Format

sudo mkfs.ext3 /dev/sda1

USB Disk Mount

sudo mount /dev/sda1 /local
mke2fs 1.42.12 (29-Aug-2014)
/dev/sda1 contains a vfat file system
Proceed anyway? (y,n) y
Creating filesystem with 78142550 4k blocks and 19537920 inodes
Filesystem UUID: 9328da1d-013a-4613-b14f-d3d7b9f20dac
Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
 4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     

Mount Disk Confirm

sudo df -h
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        3837080 3552664     69788  99% /
devtmpfs          469752       0    469752   0% /dev
tmpfs             474068       0    474068   0% /dev/shm
tmpfs             474068    6356    467712   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             474068       0    474068   0% /sys/fs/cgroup
/dev/mmcblk0p1     61384   20296     41088  34% /boot
tmpfs              94816       0     94816   0% /run/user/1000
/dev/sda       312494912      32 312494880   1% /local

Unmount Partition

sudo umount /dev/sda
pi@raspberrypi:/ $ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
No partition is defined yet!
Could not delete partition 81229

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-625142447, default 2048): 625142447

Created a new partition 1 of type 'Linux' and of size 512 B.

Command (m for help): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 83
Changed type of partition 'Linux' to 'Linux'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Setting Reboot

sudo vim /etc/fstab
/dev/sda1 /local ext3 defaults 1 2

참고 논문 및 사이트

1. fstab(영구적마운트설정) - http://movenpick.tistory.com/34

RaspberryPi - 01

Setting

Locale


Timezone


Password

passwd

Vim Install

sudo apt-get install vim

Static Network Setting

vim /etc/network/interfaces

Before

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.confc

After

auto lo
iface lo inet loopback

# The primary network interface
# auto eth0
# iface eth0 inet dhcp

# menual
auto eth0     
iface eth0 inet static      
address 192.168.0.10     
netmask 255.255.255.0     
network 192.168.0.0      
broadcast 192.168.0.255
gateway 192.168.0.1
sudo /etc/init.d/networking restart

Raspberry Config

raspi-config

Ssh port change

현재 포트 확인

sudo netstat -anp | grep LISTEN | grep sshd

포트변경

cat /etc/ssh/sshd_config | egrep ^\#?Port
sudo vim /etc/ssh/sshd_config

Before

Port 22

After

#Port 22
Port 10022
sudo /etc/init.d/ssh restart
ssh -p 10022 pi@192.168.0.10