'user directory'에 해당되는 글 1건

  1. 2015.04.06 [36] Apache_VirtualHosts, user directory, mysql(1)

[36] Apache_VirtualHosts, user directory, mysql(1)

|


- 2014.12.26




1. Apache


1) Section 3 : Virtual Hosts


한 시스템에서 여러 개의 도메인과 호스트 이름을 구분하여 웹 서비스 가능. 이름 기반의 버추얼 호스팅

도메인 앞에 cafe 등의 호스트를 붙여 쓰는 것



[/etc/httpd/conf/httpd.conf] 설정


# vi /etc/httpd/conf/httpd.conf

    975 ### Section 3: Virtual Hosts

    992 #NameVirtualHost *:80

    993 NameVirtualHost 192.168.1.24:80



1006 줄 아래로 7줄을 복사 및 수정해서 아래와 같이 버츄얼 호스트 설정

   1014 <VirtualHost 192.168.1.24:80>

   1015     DocumentRoot /export/home/main/public_html

   1016     ServerName www.hatms.com

   1017 </VirtualHost>

   1018

   1019 <VirtualHost 192.168.1.24:80>

   1020     DocumentRoot /export/home/main/public_html

   1021     ServerName hatms.com

   1022 </VirtualHost>

   1023

   1024 <VirtualHost 192.168.1.24:80>

   1025     DocumentRoot /subhost

   1026     ServerName sub.hatms.com

   1027 </VirtualHost>


# mkdir /subhost/

# cat > /subhost/index.html

<center><H1>Sub Page</H1></center>

# /etc/rc.d/init.d/httpd restart


하지만 sub.hatms.com 페이지가 작동하지 않는다. => DNS 설정 필요.


# vi /var/named/ha.z

     12 sub     IN      A       192.168.1.24

# vi /var/named/ha.r

     12 24      IN      PTR     sub.hatms.com.

# /etc/rc.d/init.d/named restart




[주의]


헌데 버츄얼 호스트를 사용하면 2 section 이 무시되고 바로 버츄얼 호스트가 먹힌다.

따라서 기존의 hostname(www, 없는것) 도 버츄얼호스트 맨 밑에 추가하자.





2. Apache_user directory


user directory 사용하기 (ex www.abc.com/~user)

    367     #UserDir disabled

    368     UserDir enabled


# service httpd restart

httpd 를 정지 중:                                    [  OK  ]

httpd (을)를 시작 중: Syntax error on line 368 of /etc/httpd/conf/httpd.conf:

UserDir "enable" keyword requires a list of usernames

                                                     [실패]


enable 은 아니다. 사용자 명으로 진행


    368     UserDir samadal


# service httpd restart


재시작은 성공했지만 www.hatms.com/~samadal 은 안됨.

index.html 페이지를 생성 안했다.


# cd ~samadal

# cat > ./index.html

<center><H1>samadal main</H1></center>

    375     UserDir public_html

# service httpd restart


여전히 되지 않는다? 아마 public_html 디렉터리에 만들어야 하는듯.

# pwd

/home/samadal

# mkdir ./public_html/

# cat > ./public_html/index.html

<center><H1>samadal public page</H1></center>


이제서야 페이지가 들어가진다. 즉 public_html 디렉터리 안에 해야하는 것이다.

public_html 말고 자기 자신 홈 디렉터리를 사용하려면 아래처럼 사용하면 된다.


    375     # UserDir public_html

    376     UserDir /export/home

     => samadal 홈 디렉터리 앞쪽에 있는 경로까지 절대경로로 지정


좀더 나은 보안을 위해 다른 계정은 막지만 samadal만 허용하는 스크립트 기재.

    367     UserDir disabled

    368     UserDir samadal


root만 막는 것은 아래처럼 하면 된다

    367     UserDir disabled root





3. Mysql


[구조]


database        table           field           value

Linux반         지웅            인간성          Good

                                    학습력          Good



Mysql 은 R-DBMS(Relationed DabaBase Manage System) 이다.



[DB server 종류]


MySQL : 무료, 오픈소스, 중소형 급

Oracle, MSSQL : 엔터프라이즈급의 대형 DB 서버. 유료



[실습]


cd 안에 있는 mysql* PKG 설치

- mysql-connector-java 는 --nodeps 로 진행

- 이전 mysql 설치했던 것 참조, test 도 nodeps 로 지우고 설치




# /etc/rc.d/init.d/mysqld restart

mysqld 를 정지 중:                                         [  OK  ]

MySQL 데이타베이스 초기화 중:  WARNING: The host 'samadal.madalgyo' could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h samadal.madalgyo password 'new-password'

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]

mysqld (을)를 시작 중:                                     [  OK  ]




[Tip]


mysql 은 서버와 맞물려있기 때문에 완전히 못지운다.

자동 줄바꿈 사용하지 않는 것이 좋으며 줄이 넘어갈것 같으면 엔터 치고 진행. 행의 마지막은 ; 로 종료.

엔터와 스페이스는 같다. 단어를 엔터로 나누지 말아라.


Mysql 명령어 사용 가능 표


                D/B     Table

creat           O        O

drop            O       O

select          X        O

update         X        O

insert           X        O

delete          X        O

show           O        O

desc           X         O

use            O          X

alter            X         O



# mysql -u root -p mysql

            user          ----- db 명

(/etc/passwd user와 mysql user는 다르다.)


초기 password 는 없다. 엔터치면 됨


만들어진 database 목록 보기


mysql> show databases;

+----------------------------+

| Database                   |

+----------------------------+

| information_schema  |

| mysql                        |

| test                           |

+---------------------------+

3 rows in set (0.00 sec)


mysql database 로 이동.

use 명령어는 cd 명령어라고 이해하면 된다.


mysql> use mysql;

Database changed


mysql database 안에 있는 table 들 목록 확인


mysql> show tables;

+-------------------------------------+

| Tables_in_mysql                  |

+------------------------------------+

| columns_priv                       |

| db                                        |  => 사용자와 db를 연결시켜주는 table

| event                                    |

                . . .                           

| time_zone_transition           |

| time_zone_transition_type  |

| user                                     |  => 사용자

+------------------------------------+

23 rows in set (0.00 sec)


table 내의 user 항목으로 이동하려 했으나 실패!

즉 use 명령어가 cd 랑 비슷한 역할이라고 한다면 database 는 directory, table 은 file 이라 생각하면 될듯.

file 은 당연히 cd 로 볼 수 없으니까.


mysql> use user;

ERROR 1049 (42000): Unknown database 'user'


따라서 테이블 내의 항목(필드 & 타입)을 확인하는 명령어인 desc 사용.


mysql> desc user;

+-------------------------------+----------------------------+--------+--------+-----------+---------+

| Field                              | Type                          | Null    | Key   | Default  | Extra   |

+-------------------------------+-----------------------------+-------+--------+-----------+---------+

| Host                               | char(60)                    | NO     | PRI  |               |           |

| User                               | char(16)                    | NO     | PRI  |               |           |

| Password                       | char(41)                    | NO     |        |               |           |

                                                       .    .    .                                                           

| max_connections           | int(11) unsigned       | NO     |        | 0            |           |

| max_user_connections  | int(11) unsigned       | NO     |        | 0           |            |

+-----------------------+------------------------------------+--------+-------+----------+---------+

39 rows in set (0.00 sec)



dbsamadal 이라는 새로운 database를 생성해보자.


mysql> create database dbsamadal;

Query OK, 1 row affected (0.00 sec)


mysql> show databases;

+----------------------------+

| Database                   |

+----------------------------+

| information_schema  |

| dbsamadal                 |

| mysql                         |

| test                            |

+----------------------------+

4 rows in set (0.01 sec)


새로 만든 dbsamadal database로 이동


mysql> use dbsamadal;

Database changed


mysql> show tables;

Empty set (0.00 sec)


새로 만들었으니 당연히 table도 비어있다. tbsamadal 이라는 table 생성


mysql> create table tbsamadal;

ERROR 1113 (42000): A table must have at least 1 column


하지만 생성에 오류가 떴다. 적어도 1개 이상의 field & type 이 있어야 한다.

정수형의 num, 문자형의 name 항목 생성. 괄호 안에 있는 것은 인수 개수를 뜻함.


mysql> create table tbsamadal(num int(2), name char(10));

Query OK, 0 rows affected (0.01 sec)


잘 만들어진 것 확인할 수 있다.


mysql> show tables;

+-------------------------------+

| Tables_in_dbsamadal   |

+-------------------------------+

| tbsamadal                     |

+-------------------------------+

1 row in set (0.00 sec)


tbsamadal 테이블에 제대로 num과 name이 있는지 확인.


mysql> desc tbsamadal;

+--------+----------+-------+------+-----------+-------+

| Field  | Type    | Null   | Key | Default  | Extra|

+-------+-----------+-------+------+-----------+-------+

| num  | int(2)     | YES |        | NULL     |          |

| name| char(10)| YES |        | NULL     |          |

+-------+-----------+-------+-----+------------+-------+

2 rows in set (0.01 sec)


헌데 이 테이블에 전화번호도 추가했으면 좋겠다. 정수형으로 16개를 받자.


mysql> alter table tbsamadal add tel int(16);

Query OK, 0 rows affected (0.01 sec)

Records: 0  Duplicates: 0  Warnings: 0


잘 추가 되었는지 확인.


mysql> desc tbsamadal;


헌데 이름이 char형 10개면 한글로는 5글자이다. 20으로 늘려 10글자 한글 이름도 가능하게 변경


mysql> alter table tbsamadal modify name char(20);

                                         ------- type 변경 시 사용

Query OK, 0 rows affected (0.01 sec)

Records: 0  Duplicates: 0  Warnings: 0


확인은 필수.


mysql> desc tbsamadal;


num 대신 id 라는 것으로 바꾸면서 type도 char 형으로 변경


mysql> alter table tbsamadal change num id char(10);

                                     ------ field & type 변경

Query OK, 0 rows affected (0.01 sec)

Records: 0  Duplicates: 0  Warnings: 0


역시나 확인.


mysql> desc tbsamadal;


전화번호에 대한 내용을 삭제해보자.


mysql> alter table tbsamadal drop tel;


Query OK, 0 rows affected (0.01 sec)

Records: 0  Duplicates: 0  Warnings: 0

mysql> desc tbsamadal;


table 자체를 삭제해보자.


mysql> show tables;

mysql> drop table tbsamadal;


mysql> show tables;

Empty set (0.00 sec)


작업할 db를 mysql로 변경


mysql> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;

mysql> desc user;


테이블의 내용 중 내가 보고 싶은 것들만 골라서 보기


mysql> select host, user, password from user;


password라는 함수를 통해 암호화 하는데 user의 root 에게 주겠다.


mysql> update user set password=password('samadal') where user='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

mysql> select host, user, password from user;


user 테이블에서 user 항목이 빈칸으로 되어 있는 것들을 지우라는 명령어


mysql> delete from user where user='';

mysql> select host, user, password from user;


테이블에 내가 원하는 값을 입력. password는 password라는 함수를 이용하여 암호화 한 값을 저장


mysql> insert into user(host, user, password) values('localhost', 'usersamadal', password('samadal'));

mysql> select host, user, password from user;




이제 사용자와 database 를 연결시켜줘야한다.


mysql> desc db;

mysql> select host, db, user from db;

+-------+-----------+-------+

| host   | db         | user |

+-------+-----------+-------+

| %       | test       |         |

| %       | test_% |         |

+--------+----------+-------+

2 rows in set (0.00 sec)


쓰레기 값이 들어가있다. db 테이블 중 host 에 %가 들어가 있는 것 삭제


mysql> delete from db where host='%';


mysql> select host, db, user from db;

Empty set (0.00 sec)


이제 사용자와 db를 연결시켜주기 위해 host, db명, user명 및 user가 갖게 될 권한에 y 를 준다.


mysql> insert into db values('localhost', 'dbsamadal', 'usersamadal',

    -> 'y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y');



확인.


mysql> select host, db, user from db;

+------------+----------------+-----------------+

| host         | db              | user               |

+------------+----------------+-----------------+

| localhost | dbsamadal | usersamadal |

+------------+----------------+-----------------+

1 row in set (0.00 sec)

mysql> Bye


# /etc/rc.d/init.d/mysqld restart


새로 만든 계정과 db가 연동되는지 확인


# mysql -u usersamadal -p dbsamadal

                                   --------- 뒤에 db명을 적어주지 않아도 되지만

                                                  작업위해 어차피 use db명으로 이동해야 함

Enter password:


mysql> show databases;

+---------------------------+

| Database                  |

+---------------------------+

| information_schema |

| dbsamadal                |

+---------------------------+




And


prev | 1 | next