'php'에 해당되는 글 2건

  1. 2012.05.09 FreeBSD 8.2 APM 설치
  2. 2012.05.09 FreeBSD + APM + cacti 설치
FreeBSD2012. 5. 9. 10:48

출처 : http://toybsd.tistory.com/900

 

FreeBSD 8.2에서 APM환경을 구축해보자!

이번에 CentOS에서 FreeBSD로 넘어오면서 Apache + PHP + MySQL환경을 구축을 새로하게 되었다. 내가 마지막으로 사용하던 FreeBSD버전은 8.0이였는데 지난 2월달에 8.2버전이 새로 나와서 설치를 하게 되었다.

이번 글에선 FreeBSD에서 APM환경 구축하기이다. 원래는 MySQL말고 PostgreSQL을 설치를 하고 싶었지만, 지금 사용하고 있는 워드프레스에선 MySQL만 지원을 하기 때문에 어쩔수 없이 MySQL을 설치를 하게 되었다.(플러그인을 사용하면 PostgreSQL도 사용이 가능하지만, MySQL을 사용하는 플러그인도 있기때문에 어쩔수 없이 MySQL을 구축했다. PostgreSQL하고 MySQL하고 포트가 달라서 둘다 설치해도 되지만 서버 스펙이..)

난 포트로 구축을 했다. 설치 순서는 MySQL->Apache22->PHP->PHP-Extension 순이다.

1. MySQL 설치 및 설정

[root@localhost ~]# cd /usr/ports/databases/mysql51-server && make install clean

설치가 끝난뒤 mysql을 활성화 시켜줘야 한다. /etc/rc.conf에 mysql_enable=”YES”를 추가를 해준다.
[root@localhost ~]# echo ‘mysql_enable=”YES”‘ >> /etc/rc.conf

그다음은 mysqld를 올린다.
[root@localhost ~]# /usr/local/etc/rc.d/mysqld start

그런뒤 root패스워드를 지정을 해준다. %%%%부분에 사용할 패스워드를 입력해주면 된다.
[root@localhost ~]# mysqladmin -u root password ‘%%%%%’

이것으로 MySQL은 손쉽게 설치가 되었다. 난 my.cnf는 디폴트로 사용하기로 했다. (나중에 튜닝할 예정)

2. Apache 설치 및 설정

[root@localhost ~]# cd /usr/ports/www/apache22 && make install clean

위 와같이 설치를 하면 도중에 어떤 모듈도 설치할건지가 나오는데, 자기가 필요한 모듈을 선택하고 진행하면 된다. 이후 설치가 끝나면 httpd.conf파일을 조금 수정을 해야할 필요가 있다.

[root@localhost ~]# vim /usr/local/etc/apache22/httpd.conf

149번째줄에 있는 ServerName부분을 주석을 해제 시키고 다음과 같이 수정을 한다.
ServerName 127.0.0.1:80

설정이 간단하게 끝났다. httpd.conf는 자신의 입맛에 맞게 설정을 해주면 된다.

마지막으로 apache22를 활성화를 해준다.

[root@localhost ~]# echo ‘apache22_enable=”YES”‘ >> /etc/rc.conf

3. PHP 설치 및 설정

[root@localhost ~]# cd /usr/ports/lang/php5 && make install clean

위의 명령어를 치면 어떤 모듈을 설치할것인지 나오는데, ‘APACHE’부분을 꼭! 체크하고 설치를 해준다.

설치가 끝나면 extension을 설치를 한다.
[root@localhost ~]# cd /usr/ports/lang/php5-extensions && make install clean

여기서 자신이 필요한 모듈을 설치를 해준다. 필수적으로 해주어야 할것은 ‘MySQL’부분이다. MySQL 모듈을 설치를 해주어야지만 MySQL에 연결을 할수가 있다. xpressengine같은것을 사용하려면 gd 라이브러리도 필요하므로 ‘gd’정도도 체크하면 된다. 나머지는 사용자가 필요에 따라 선택한다.

php 설치가 끝나면 이제 apache에 mime type을 추가를 해주어야 한다.
[root@localhost ~]# echo ‘application/x-httpd-php php’ >> /usr/local/etc/apache22/mime.types

DirectoryIndex에서 php도 추가를 해주어야 한다.
[root@localhost ~]# vim /usr/local/etc/apache22/httpd.conf
httpd.conf에서 217번째 줄에서 다음과 같이 수정한다.
DirectoryIndex index.html index.htm index.php

그리고 apache 데몬을 올린다.
[root@localhost ~]# /usr/local/etc/rc.d/apache22 start

이제 웹브라우저로 접속을 해서 잘 접속이 되는지 확인을 하고  phpinfo()도 넣어서 잘 연동이 되는지도 확인을 해보면 된다.

Posted by 배움나눔
FreeBSD2012. 5. 9. 10:44

출처 : http://visualnet.tistory.com/334

 

FreeBSD + APM + cacti 설치

#vi .cshrc 수정


setenv  LANG ko_KR.UTF-8
setenv  LC_ALL ko_KR.UTF-8
(로케이션 한글 설정)
set prompt = "%B`whoami`%b@`hostname`[%~]#"

#source .cshrc


port 업데이트

cvsup -g -L 2 -h cvsup.jp.freebsd.org /usr/share/examples/cvsup/ports-supfile


1.apache22 설치

whereis apache22

cd /usr/ports/www/apache22
make WITH_MPM=worker install clean (2코어 활성)

선택 옵션에서 mysql 선택하고 탭ok 누르면 된다.

apache22 셋팅은 mysql55-server 와.. php5 를 설치 하고나서 한번에 셋팅 한다..


2. mysql55-server 설치

cd /usr/ports/databases/mysql55-server

#make WITH_CHARSET=utf8 WITH_COLLATION=utf8_general_ci install clean
* EUC-KR을 사용하기 위한 옵션 설치
 # > make WITH_CHARSET=euckr WITH_COLLATION=euckr_korean_ci install clean

utf8로 설치 한다..

#make WITH_CHARSET=utf8 WITH_COLLATION=utf8_general_ci install clean

 특별히 설정할껀 없다.

 

 * mysql 설정파일 복사
 # > cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf


3. php5 설치

apache22 와 연동하기 위하여..

cd /usr/ports/lang/php5 && make config

설정 화면에서 Build Apache module 선택후.. ok 버튼으로 넘김

cd /usr/ports/lang/php5-extensions

make config install 로 설치

설치 옵션에서 FTP GD MYSQL SOCKETS SNMP 선택후 OK 눌러 설치

설치중 나오는 옵션은 전부 탭눌러서 넘긴다.
설정


1. apache22 설정

cd /usr/local/etc/apache22

vi httpd.conf

AddType 로 검색하여 적당한 곳에..
AddType application/x-httpd-php .php .inc .html
AddType application/x-httpd-php-source .phps


추가한다.


    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php .inc .html
    AddType application/x-httpd-source .phps
이런식으로 적어 주면 된다.

DirectoryIndex 를 검색하여.

DirectoryIndex index.html index.php  추가해준다.


# Virtual hosts
Include etc/apache22/extra/httpd-vhosts.conf

Include 앞에 주석 해제 위와 같이 변경
vi /etc/rc.conf
apache22_enable="YES"


2. mysql 설정

cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
vi /etc/rc.conf
mysql_enable="YES" 추가후 리붓

 

3.php 설정
cd /usr/local/etc

cp  php.ini-development php.ini 로 카피 한다.

리붓후
sockstat -4 로 mysql 과 httpd 작동을 확인 한다..

root     sshd       1174  4  tcp4   *:22                  *:*
root     httpd      1147  3  tcp4 6 *:80                  *:*
root     httpd      1147  4  tcp4   *:*                   *:*
mysql    mysqld     1081  11 tcp4 6 *:3306                *:*

4. mysql 나머지 설정..

* 기본 사용자가 mysql로 사용하는 기본 관리 DB 설치
/usr/local/bin/mysql_install_db --user=mysql

---------------------------------------------------------------------------------------

FATAL ERROR: Could not find ./bin/my_print_defaults

 


If you compiled from source, you need to run 'make install' to

copy the software into the correct location ready for operation.

 


If you are using a binary release, you must either be at the top

level of the extracted archive, or pass the --basedir option

pointing to that location.

---------------------------------------------------------------------------------------

위와 같은 오류때문에.. mysql_install_db 가 설치가 안된다고 하면 아래 방법으로 설치

/usr/local/bin/mysql_install_db --user=mysql --basedir=/usr/local

* 관리자 비밀번호 지정 하기
/usr/local/bin/mysqladmin -u root password '패스워드' (패스워드 앞에 '은 엔터옆에 '임)

* 캐릭터셋 점검
 # > mysql -u root -p
      Enter password:
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 9 to server version: 5.1.34-log

      Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

      mysql> use test;
      Database changed
      mysql> show variables like 'c%';
      +--------------------------+----------------------------------+
      | Variable_name            | Value                            |
      +--------------------------+----------------------------------+
      | character_set_client     | utf8                            |
      | character_set_connection | utf8                            |
      | character_set_database   | utf8                            |
      | character_set_results    | utf8                            |
      | character_set_server     | utf8                            |
      | character_set_system     | utf8                            |
      | character_sets_dir       | /usr/local/share/mysql/charsets/ |
      | collation_connection     | utf8_general_ci                  |
      | collation_database       | utf8_general_ci                  |
      | collation_server         | utf8_general_ci                  |
      | concurrent_insert        | ON                              |
      | connect_timeout          | 5                                |
      +--------------------------+----------------------------------+
      12 rows in set (0.00 sec)
     
      mysql >

mysql > quit
- 서버설정에 타라 위의 내용이 다를 수 있습니다.
quit 로 빠져 나온다..

 

mysql utf8 적용

vi /etc/my.cnf


[client]
default-character-set=utf8

 

[mysqld]
character-set-server=utf8

 

[mysql]
dafault-character-set=utf8


mysql> use test;
Database changed
mysql> show variables like 'c%';
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8                             |
| character_set_connection | utf8                             |
| character_set_database   | utf8                             |
| character_set_filesystem | binary                           |
| character_set_results    | utf8                             |
| character_set_server     | utf8                             |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/share/mysql/charsets/ |
| collation_connection     | utf8_general_ci                  |
| collation_database       | utf8_general_ci                  |
| collation_server         | utf8_general_ci                  |
| completion_type          | NO_CHAIN                         |
| concurrent_insert        | AUTO                             |
| connect_timeout          | 10                               |
+--------------------------+----------------------------------+
14 rows in set (0.01 sec)

mysql>


apm 설치및 셋팅이 끝났다..

 

mysql> status

--------------

mysql  Ver 14.14 Distrib 5.1.60, for portbld-freebsd8.2 (amd64) using  5.2


Connection id: 1048

Current database:

Current user: root@localhost

SSL: Not in use

Current pager: more

Using outfile: ''

Using delimiter: ;

Server version: 5.1.60-log FreeBSD port: mysql-server-5.1.60

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db     characterset: utf8

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /tmp/mysql.sock

Uptime: 1 day 16 hours 37 min 20 sec


Threads: 1  Questions: 109705  Slow queries: 0  Opens: 1107  Flush tables: 1  Open tables: 54  Queries per second avg: 0.750

--------------


cacti 를 설치 합니다.

기본적으로 apm 이 설치 되어 있어야 한다. php 설치 옵션중 snmp

test# whereis cacti
cacti: /usr/ports/net-mgmt/cacti


cacti: /usr/ports/net-mgmt/cacti
test# cd /usr/ports/net-mgmt/cacti && make install clean

 

mysql 의 db와 계정을 셋팅한다.

# mysql -u root -p

Enter password: **********

---------------------------------------------------


mysql> create database cacti;

mysql> use mysql;

mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'password';

mysql> FLUSH privileges;

mysql> quit


mysql -u root -p cacti < /usr/local/share/cacti/cacti.sql

php.ini timezone 수정

vi /usr/local/etc/php.ini

date.timezone = Asia/Seoul

로 수정

# vi /usr/local/share/cacti/include/config.php
--------------->modify<------------------

#database_type = "mysql";

#database_default = "cacti";

$database_hostname = "127.0.0.1";

$database_hostname = "localhost";

$database_username = "cacti";

$database_password = "password";

$database_port = "3306";

------------------------------------------


vi /etc/rc.conf

snmpd_enable="YES"
snmptrapd_enable="YES"
linux_enable="YES"

cd /usr/local/share/snmp/

cp snmpd.conf.example snmpd.conf

vi snmpd.conf

#trap2sink    localhost public

#rocommunity public  localhost

주석 제거 해 준다.

vi /etc/crontab

*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1

추가 해 준다.

리눅스 에뮬레이터 설치
메모리 부분 스크립트가 linux 전용으로 되어 있기 때문에 linux에뮬레이터를 설치 해야 정상적으로 작동한다.
위에 rc.conf 수정에서 linux_enable="YES" 로 한후 리붓을 해야 정상적으로 설치가 가능하다.

rc.conf 를 수정 하지 않고 설치 했을경우

root@cacti.test.com[/usr/ports/emulators/linux_base-f10]#make install clean
===>  linux_base-f10-10_4 linuxulator is not (kld)loaded.
*** Error code 1

Stop in /usr/ports/emulators/linux_base-f10.

와 같은 오류 메시지를 볼수 있다
리눅스 에뮬레이터 사용시 시작스크립트인 rc.conf 에서 리눅스 모듈? 을 불러와야 정상적으로 설치가 된다.

리붓후 다시 설치 하도록 한다.

root@test.crois.net[~]#cd /usr/ports/emulators/linux_base-f10/
root@test.crois.net[~]#make install clean

cacti 메모리 부분 스크립트 변경
리눅스 용으로 작성이 되어 있기때문에 freebsd 에서 구동시키면 정상 작동이 되질 않습니다.
 test# cd /usr/local/share/cacti/scripts/
 test# vi linux_memory.pl

#!/usr/bin/perl

$mem = `cat /compat/linux/proc/meminfo | grep -w "$ARGV[0]"`;
$mem =~ s/($ARGV[0].*\s)(.*[0-9])( kB)//;

print $2;


-------------------------------------------------

linux 에뮬레이터 사용을 위해.
fstab 부분에 설정을 합니다.

 vi /etc/fstab
 linproc   /compat/linux/proc linprocfs rw 0 0

 

vi /etc/crontab

*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1


---------------------------------------

root@cacti.test.com[/usr/local/share/cacti/scripts]#cd /usr/local/etc/apache22/
vi httpd.conf

apache 설정

Alias /cacti /usr/local/share/cacti
<Directory "/usr/local/share/cacti">
    AllowOverride None
    Order Allow,deny
    Allow from all
</Directory>

 


root@cacti.test.com[~]#/etc/rc.d/cron restart


--------------------------------------------------------


01/09/2012 10:35:02 AM - PCOMMAND: Poller[0] Host[1] WARNING: Recache Event Detected for Host

오류가 뜨면
php -q /usr/local/share/cacti/cli/poller_reindex_hosts.php -id=2 -d

php -q /usr/local/share/cacti/cli/poller_reindex_hosts.php -id=All

삭제 해 줘야 한다.
오류 관련 설정 페이지

http://docs.cacti.net/manual:087:6_reference.4_cli_script.2_reindex_hosts


정상적으로 snmpd 가 작동 하는걸 보기 위해.. 아래 명령어를 실행해 본다.

snmpwalk -v 2c -c public localhost


-----------------------------------------------------------

cacti 설정


admin:admin 으로 로그인 하고 로그인 후에 비번을 만들어 주면 된다.



 

Devices 부분


Host Template 부분을 ucd/net SNMP Host 로 바꿔 준다.

SNMP Version 을 Version 2 로 바꿔준다.

Associated Graph Templates 에서

2) ucd/net - CPU Usage  Not Being Graphed   
3) ucd/net - Load Average  Not Being Graphed   
4) ucd/net - Memory Usage  Not Being Graphed 


위와 같이 추가를 해준다.

Associated Data Queries 부분에서

1) SNMP - Interface Statistics 추가


그리고 저장.

Management 부분에서

Graph Management

기본으로 되어 있던 설정을 전부 삭제 한다.


다시
Create
New Graphs  부분에서 그래프를 만들어 준다.

 

Collection Methods
Data Queries

부분에서 SNMP - Interface Statistics 를 추가

전부 설치 하고 나면 5분 후 아래와 같은 그래프를 볼수 있다.




----------------------------------------------
설명이 너무 부실하여 도움이 될지는 모르겠지만..
차후좀더 수정 보완하겠습니다.
어설픈글 읽어 주셔서 감사합니다 _(__)_

Posted by 배움나눔