2009년 4월 30일 목요일
Linux에서 Virtual IP 구성 방법
==================================================================
/sbin/ifconfig eth0:0 192.168.100.51
==================================================================
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=192.168.100.51
NETMASK=255.255.255.255
NETWORK=192.168.100.0
BROADCAST=192.168.100.255
ONBOOT=yes
==================================================================
service network restart
ifconfig
제거
==================================================================
rm /etc/sysconfig/network-scripts/ifcfg-eth0:0
service network restart
2008년 8월 1일 금요일
Unix Domain Socket
port 기반의 Inernet Domain Socket에 비해서 로컬 시스템의 파일시스템을
이용해서 내부프로세스간의 통신을 위해 사용한다는 점이 다르다고 할수 있다.
ls 를 이용해서 통신을 위해서 만들어진 파일을 보면 다음과 같은 모습을
보인다.
[yundream@localhost tmp]$ ls -al
srwx------ 1 root nobody 0 12월 14 21:16 .fam_socket
보면 파일타입에 "s" 가 붙어 있는걸 알수 있으며, 파일사이즈가 0으로 되어 있는
걸 알수 있다. 왜냐하면 FIFO와 마찬가지로 메시지가 파일로 쌓이지 않고
커널로 전달되어서 커널에서 처리하기 때문이다.
파일을 통해서 통신을 하며, 커널내부에서 메시지를 관리한다는 점에서
FIFO와 매우 유사한면을 보여주지만, FIFO와는 달리 양방향 통신이 가능하다는
특징을 가지고 있다. 그러므로 다중의 클라이언트를 받아들이는 서버/클라이언트
모델을 만들기가 매우 쉽다.
또한 Inet 소켓을 통한 외부통신에 비해서 2배 이상의 효율을 보여준다라는
장점을 가지고 있다.
많은 경우 약간 복잡한 내부프로세스간 통신을 해야된다고 했을때 UDS을 많이
사용한다. INET 계층에서의 통신이 TCP/IP 4계층을 모두 거치는것과는
다르게, UDS 은 어플리케이션 계층에서 TCP 계층까지만 메시지가 전달되고,
다시 곧바로 어플리케이션 계층으로 메시지가 올라가게 된다. TCP/IP 계층에 대한
자세한 내용은 TCP/IP 개요(2)를 참고 하기 바란다.
위에서 INET 소켓보다 2배이상의 효율을 가진다고 했는데,
4계층의 레이어를 모두 거쳐야하는 INET 소켓에 비해서 단지 2개의 레이어만
사용한다는 점도 그 이유중 하나로 작용한다.
쏘쓰 코드는 다중연결서버 만들기(1)의 zipcode_multi.c 와
셈플로 알아보는 소켓프로그래밍(1)의 zipcode_cli.c 를 사용하도록할것이다.
예제: zipcode_local.c
1.
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
int server_sockfd, client_sockfd;
int state, client_len;
pid_t pid;
FILE *fp;
struct sockaddr_un clientaddr, serveraddr;
char buf[255];
char line[255];
if (argc != 2)
{
printf("Usage : ./zipcode [file_name]\n");
printf("예 : ./zipcode /tmp/mysocket\n");
exit(0);
}
memset(line, '0', 255);
state = 0;
if (access(argv[1], F_OK) == 0)
{
unlink(argv[1]);
}
// 주소 파일을 읽어들인다.
client_len = sizeof(clientaddr);
if((fp = fopen("zipcode.txt", "r")) == NULL)
{
perror("file open error : ");
exit(0);
}
// internet 기반의 스트림 소켓을 만들도록 한다.
if ((server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
perror("socket error : ");
exit(0);
}
bzero(&serveraddr, sizeof(serveraddr));
serveraddr.sun_family = AF_UNIX;
strcpy(serveraddr.sun_path, argv[1]);
state = bind(server_sockfd , (struct sockaddr *)&serveraddr,
sizeof(serveraddr));
if (state == -1)
{
perror("bind error : ");
exit(0);
}
state = listen(server_sockfd, 5);
if (state == -1)
{
perror("listen error : ");
exit(0);
}
printf("accept : \n");
while(1)
{
client_sockfd = accept(server_sockfd, (struct sockaddr *)&clientaddr,
&client_len);
printf("test test\n");
pid = fork();
if (pid == 0)
{
if (client_sockfd == -1)
{
perror("Accept error : ");
exit(0);
}
while(1)
{
memset(buf, '0', 255);
if (read(client_sockfd, buf, 255) <= 0)
{
close(client_sockfd);
fclose(fp);
exit(0);
}
if (strncmp(buf, "quit",4) == 0)
{
write(client_sockfd, "bye bye\n", 8);
close(client_sockfd);
fclose(fp);
break;
}
while(fgets(line,255,fp) != NULL)
{
if (strstr(line, buf) != NULL)
write(client_sockfd, line, 255);
memset(line, '0', 255);
}
write(client_sockfd, "end", 255);
printf("send end\n");
rewind(fp);
}
}
}
close(client_sockfd);
}
}
다음은 클라이언트 프로그램이다.
예제: zipcode_cli_local.c
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
int client_len;
int client_sockfd;
FILE *fp_in;
char buf_in[255];
char buf_get[255];
struct sockaddr_un clientaddr;
if (argc != 2)
{
printf("Usage : ./zipcode_cl [file_name]\n");
printf("예 : ./zipcode_cl /tmp/mysocket\n");
exit(0);
}
client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (client_sockfd == -1)
{
perror("error : ");
exit(0);
}
bzero(&clientaddr, sizeof(clientaddr));
clientaddr.sun_family = AF_UNIX;
strcpy(clientaddr.sun_path, argv[1]);
client_len = sizeof(clientaddr);
if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0)
{
perror("Connect error: ");
exit(0);
}
while(1)
{
printf("지역이름 입력 : ");
fgets(buf_in, 255,stdin);
buf_in[strlen(buf_in) - 1] = '0';
write(client_sockfd, buf_in, 255);
if (strncmp(buf_in, "quit", 4) == 0)
{
close(client_sockfd);
exit(0);
}
while(1)
{
read(client_sockfd, buf_get, 255);
if (strncmp(buf_get, "end", 3) == 0)
break;
printf("%s", buf_get);
}
}
close(client_sockfd);
exit(0);
}
기존의 INET 버젼의 프로그램과 비교해 보면 고작 3줄 정도만 수정되었음을
알수 있을것이다. 단지 소켓 구조체가 sockaddr_un 으로 바뀌고,
AF_INET 대신 AF_UNIX 를 그리고 port 번호대신에 파일명을 사용했음을
알수 있다.
나머지의 모든 코드는 INET 코드와 완전히 같다. 그러므로
Unix Domain Socket 를 사용하면 Inet Domain Socket 와 코드 일관성을
유지할수 있으며, 동일한 기술을 사용해서 프로그래밍을 할수 있다.
또한 다른 대부분의 IPC 설비들이, 범용적으로 사용하기에는 부족한 여러가지
단점들을 가진반면(단방향 이거나, 읽기만 가능하다거나, 제어하기가 어려운)
UDS는 매우 범용적인 IPC 로써 사용가능하다라는 장점을 가지고 있다.
실제로 X 서버 같은경우에 외부에서의 접근시에는 INET 연결을 내부에서의
연결을 위해서는 UDS 를 사용한다. 이밖에도 mysql, pgsql, KDE, Gnome 과 같은
대부분의 서버프로그램이 내부통신을 위해서 UDS 를 사용한다.
2008년 5월 18일 일요일
[스크랩] VNC Server 설정 방법
우선 vnc를 구성하기 위한 rpm 두개가 필요하다
하나는 서버, 하나는 클라이언트.
vnc-server.rpm
vnc.rpm
rpm명령을 이용하여 위 두개의 파일을 설치하고 vnc서버를 시작하자
#service vncserver restart
서버 상태를 확인하자
#service vncserver status
vnc설정 파일
/etc/sysconfig/vncservers
VNCSERVERS="1:root"
VNCSERVERS[1]="-geometry 800x600"
설정파일 내용
위의 1:root 부분에서 1은 디스플레이 번호를 의미하며 root는 계정명을 나타낸다.
VNCSERVERS[1]="-geometry 800x600"은 1번 디스플레이 번호에 대한 해상도를 설정하는 것이다. 사용자가 많아서 디스플레이 번호가 2, 3, 4식으로 증가하면 ‘[‘와 ‘]‘사이의 숫자를 변경하여 설정하면 된다.
처음에 vnc서버를 시작하면 서버가 작동이 안되는데 그 이유는 vnc서버 사용자 root가 암호를 필요로 하기 때문이다.
암호를 만들기 위해서 다음의 과정을 따라하자
#cd ~
#mkdir .vnc
#cd .vnc
#vncpasswd ‘패스워드입력’
이제 다시 vnc서비스를 재시작하자
그러면 /root/.vnc 디렉토리 밑에 xstartup파일이 생성될 것이다
[tip1] 이제 밑의 vnc 클라이언트를 이용하여 vnc서버에 접속을 하면은 xwindow를 사용하여 자신만의 윈도우 매니저를 사용한다면 해당하는 윈도우 매니저가 안나오고 기본적인 twm이 시작할 것이다. 자신이 사용하고자 하는 윈도우 매니저가 나타나기를 원할 경우에는 $HOME/.vnc/xstartup 파일에서
#unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
부분의 ‘#’을 지워서 주석을 제거해준다.
[tip2] 루트는 vnc사용자에게 사용할 수 있도록 /etc/sysconfig/vncserver 파일을 설정하고 사용자는 자신의 홈디렉토리에 .vnc디렉토리를 만들고 vncpasswd 명령으로 passwd파일을 만들어야 한다.
ex) /etc/sysconfig/vncserver
VNCSERVERS="1:root 2:test 3:test2"
VNCSERVERS[1]="-geometry 800x600"
VNCSERVERS[2]="-geometry 800x600"
VNCSERVERS[3]="-geometry 800x600"
ex)일반 사용자들의 홈디렉토리에서 패스워드 설정하는 방법
$cd ~
$mkdir .vnc
$cd .vnc
$vncpasswd
Password: 패스워드 입력(6자 이상)
Verify: 패스워드 입력 확인
위의 과정에서 $HOME/.vnc 디렉토리에 passwd파일이 만들어진다.
$ls $HOME/.vnc/
passwd
2. VNC 클라이언트 사용하기
#vncviewer ip-address:디스플레이번호
#vncviewer 211.250.1.2:1
윈도우용 vnc서버, 클라이언트는 www.tightvnc.com에 가면 다운로드 메뉴에서 찾을 수 있다.
윈도우 explorer에서 vncserver에 접속하는 방법
http://ip-address:5800+display-number
ex)http://191.111.1.1:5801 <-1번 디스플레이번호를 쓰는 루트의 접속
※ 출처 : written by o-gyun jeong 595912@hanmail.net
2008년 5월 13일 화요일
[스크랩] VirtualBox에서 Guest Windows XP USB 인식 문제 해결 방법
virtualbox 설치시 주의해야 할 것
1. 설치 후 <시스템 - 사용자와 그룹>에서 자신의 계정 그룹관리에 들어가면 제일 밑에 vboxusers라는 그룹이있다. 속성에서 자신의 계정을 추가 시켜준다.
2. vbox 모듈 setup
/etc/init.d/vboxdrv setup
3. usb 인식 문제 해결법
sudo gedit /etc/init.d/mountdevsubfs.sh
다음 4개부분의 주석을 지워줍니다... # 이걸 삭제
# Magic to make /proc/bus/usb work
#
#mkdir -p /dev/bus/usb/.usbfs
#domount usbfs "" /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
#n -s .usbfs/devices /dev/bus/usb/devices
#mount --rbind /dev/bus/usb /proc/bus/usb
다음으로 터미널 창에
sudo gedit /etc/udev/rules.d/40-permissions.rules
입력 후
# USB devices (usbfs replacement)
SUBSYSTEM=="usb_device", MODE="0664"
위의 부분을 밑에 처럼 바꿔 주면된다.. 664를 665로
# USB devices (usbfs replacement)
SUBSYSTEM=="usb_device", MODE="0666"
아래는 -------------------------------------- http://kldp.org/node/87542 발췌
이런 메세지가 뜨면
1. 터미널 창을 열어 아래 명령어를 친다
2. 편집창이 열리면 글 제일 아래에 다음의 글귀를 추가합니다.
none /proc/bus/usb usbfs devgid=46,devmode=664 0 0
3. 재부팅 하고 VirtualBox를 실행 시킨 후 자신이 원하는 USB를 선택하면 인식이 올바르게 됩니다
재부팅까지 했으면 virtualbox에서 usb장치를 설정할 수 있다. 이때 usb키보드는 연결안하는 것이 좋다. 자동으로 인식
가상머신 설정에 가면 usb장치메뉴가 있는데 거기서 사용하려는 장치를 추가시킨 후에
가상머신을 시작하면된다.
2008년 5월 2일 금요일
[스크랩] Linux에서 ISO Image Mount하는 방법
You can mount ISO images via the loop device. It is possible to specify transfer functions (for encryption/decryption or other purposes) using loop device.
But how to mount ISO image under Linux? You need to use mount command as follows:
Procedure to mount ISO images under Linux
1) You must login as a root user, if not root user then switch to root user using following command:
$ su -
2) Create the directory aka mount point:
# mkdir -p /mnt/disk
3) Use mount command as follows (assumes that your ISO file name is disk1.iso):
# mount -o loop disk1.iso /mnt/disk
4) Change directory to list it:
# cd /mnt/disk
# ls -l
See also:
* Allow normal user to mount linux partitions, usb stick/pen device
* Allow non-root user to write CDs
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.
2008년 5월 1일 목요일
[스크랩] Run Windows Apps Seamlessly Inside Linux
원본 URL:
Run Windows Apps Seamlessly Inside Linux
You love working inside your Linux desktop, but at the most inconvenient times you've got to reboot into Windows—whether to open a tricky Office file, try out a Windows application, or even just play a quick game. However, with some free tools and a Windows installation disk, you can have Windows apps running right on your Linux desktop and sharing the same desktop files. It's relatively painless, it takes only a little bit longer than a Windows XP install, and it works just like virtualizing Windows on a Mac with Parallels Coherence—except it's free. Here's how to set up Windows inside VirtualBox, and then get Windows apps running seamlessly inside your desktop.
Before getting started, make sure you have enough space on a hard drive for a Windows XP installation (meaning at least 5 GB) and enough memory to make two systems worthwhile.You can follow most of these steps if you want to try running Vista inside Linux, but your mileage might vary, of course (and check out this tip on making Vista's networking work).
If you're curious what the end result might look like, here's a screenshot from my quick installation. I would've loved to have gotten iTunes running, but I didn't have time to wait for all the post-XP-installation patches/upgrades to install to show you. (Click for larger image)
First off, we'll install VirtualBox. For most, that just involves heading to their package manager and installing all the virtualbox pacakges from the repositories; in Ubuntu 7.10 ("Gutsy Gibbon"), for example, you can use this terminal command
sudo aptitude install virtualbox-ose virtualbox-ose-modules-generic
If you don't see VirtualBox in your installation program, the app's downloads page has packages for just about every major distribution. After installing, give your username permissions to run VirtualBox (substituting "su" on some systems):
sudo usermod -G vboxusers -a [your username]
Restart your system for good measure, and now you should see "InnoTek VirtualBox" in your application menu—it was in "System Tools' in Gutsy. Get your XP CD ready and fire up VirtualBox. Choose "New" from the button menu, and then give your virtual system a name (WIndows XP usually works for me) and choose "Windows XP" from the bottom menu, then hit "Next." Decide how much RAM you'll dedicate to it in the next window, hit "Next," then, assuming you haven't done this before, hit "New" and follow the prompts to set up hard drive space for your virtual XP system. Make sure that partition is selected, hit "Next," then hit "Finish" to set up your new XP space.
Back at VirtualBox's main screen, see if the "CD/DVD-ROM" menu is highlighted. If not, click it, and then check "Mount CD/DVD Drive," "Host CD/DVD Drive" (and make sure it points to your system's CD drive), and check yes for "Enable Passthrough." Hit OK, select your XP image from the left-hand column and hit "Start." You'll launch into the hopefully familiar XP installation routine; follow it through until you're at your Windows desktop.
Now you've got a working Windows inside a resizable box, but let's take this further. Remove your XP CD from the drive, head up to the "Devices" menu and choose "Unmount CD/DVD-ROM." In the same menu, choose "Install Guest Additions." VirtualBox should prompt you to download the Guest Additions ISO file, then select it to be mounted. This creates a virtual CD drive in XP, which you can get to through Start Menu->My Computer (it might take a moment to show up). Double-click the "CD drive" and follow the prompts to install the extra tools. Reboot once you're done for good measure, and restart the XP machine.
Once that's finished, you've got a "Seamless" option available in the "Machine" menu, or by holding down the "Host" key (Right Control by default) and hitting "L." Either way you run it, it drops the big window and deposits Windows' bottom taskbar on your Linux desktop. You can also ditch the main VirtualBox window at this point, if you'd prefer.
The Start panel's default bottom position can be a problem for GNOME-based systems, since you've already got an app-switching bar there. I recommend either moving your Start or GNOME menus to the left or right-hand sides, or setting your Start menu to double-height, which puts the Start button just above the GNOME bar. Either way, make sure you un-check the "Keep the taskbar on top of other windows" option on the Windows toolbar, or you might see a few graphical glitches. Otherwise, pretty neat, huh?
Now for the final piece: Synchronizing your Windows and Linux desktops. If you're running in Seamless mode, hold down the "Host" key and hit "Home" to bring back the virtual XP desktop. Select the "Device" menu and choose "Shared Folders." You'll be prompted to choose a folder from your Linux system; select your Desktop folder (usually found at /home/your username/Desktop). Head back to Windows, launch a command prompt (enter "cmd" into the "Run" dialog), and enter the following:
-
net use x: \\vboxsvr\Desktop
If it worked, you should see an X: network drive mounted in your "My Computer" window.
Now for the final touch: Synchronizing the two desktops. In XP, hit the "Run" dialog and type in "regedit." Make a backup first (File->Export), and then navigate to HKEY_CURRENT_USER -> Software -> Microsoft -> Windows -> CurrentVersion -> Explorer -> User Shell Folders. Double-click to open the properties on the "Desktop" key you'll find there, and enter a new value of (without the quotes) "x:". You should see the change immediately—everything you put on your Linux desktop is shown in Windows and vice versa—handy for storing downloads grabbed in Windows.
If you'd rather do without the Start menu/panel integration and just want a few custom apps to open in their own windows, check out a helpful guide at Linux.com to getting this set up with some free tools and VMWare Server, which, while not quite as user-friendly as VirtualBox, is still a pretty nice package.
Got your own Windows-inside-Linux set-ups (besides Wine, which is another thing entirely) you feel like sharing? Have any suggestions/tweaks to this step-by-step? Share it in the comments and help two disparate operating systems find some harmony.
Kevin Purdy, associate editor at Lifehacker.com, is looking for ways to spend the precious minutes he'll save every day by sticking (mostly) to one OS. His weekly feature, Open Sourcery, appears every Friday on Lifehacker.

