2015년 11월 17일 화요일

ubuntu 14.04 mysql 설치 및 설정

1. 설치


$ sudo apt-get install mysql-server

2. 설정파일 수정


$ sudo nano /etc/mysql/my.cnf


  1. 로그 설정
[mysqld]
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1


log_slow_queries        = /var/log/mysql/mysql-slow.log
long_query_time = 2


  1. 케릭터 셋 설정
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8


[mysql]
default-character-set=utf8


  1. 외부접속 허용


[mysqld]
- 아래 부분 주석처리
# bind-address           = 127.0.0.1


  1. inno db 설정
innodb_file_per_table = 1


3. 사용자 추가 ( 외부에서 접속하기 위해 )


$ sudo mysql -u root -p


> use mysql;


> grant all privileges on *.* to 'root'@'%' identified by '비밀번호';


> flush privileges;

$ sudo service mysql restart

ubuntu 14.04 php-fpm 설치 및 설정

1. 소스 다운로드


~/src$ wget http://uk1.php.net/get/php-5.6.15.tar.gz/from/this/mirror -O php-5.6.15.tar.gz


~/src$ tar -xvzf php-5.6.15.tar.gz


~/src$ cd php-5.6.15




2. 의존성 모듈 설치


$ sudo apt-get install build-essential


$ sudo apt-get build-dep php5


$ sudo apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev


$ sudo ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a



3. configure 설정


~/src/php-5.6.15$ ./configure --with-zlib-dir --enable-mbstring --with-libxml-dir --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql --with-mysqli --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --enable-fpm  

4. 설치


~/src/php-5.6.15$ sudo make install


5. 설정




~/src/php-5.6.15$ sudo cp php.ini-development /usr/local/lib/php.ini
~/src/php-5.6.15$ sudo cp /usr/local/etc/php-fpm.conf.default /usr/local/php/php-fpm.conf
~/src/php-5.6.15$ sudo cp sapi/fpm/php-fpm /usr/local/bin/
~/src/php-5.6.15$ sudo cp sapi/fpm/php-fpm /usr/sbin/


설정파일 열어서
~/src/php-5.6.15$ sudo nano /usr/local/php/php.ini


아래처럼 수정


short_open_tag = On
upload_max_filesize = 10M
cgi.fix_pathinfo=0


설정파일 열어서
~/src/php-5.6.15$ sudo nano /usr/local/php/php-fpm.conf


아래처럼 수정


pid = /var/run/php-fpm.pid
listen = /var/run/php5-fpm.sock;
pm.max_children = 100
rlimit_files = 102400
listen.owner = www-data
listen.group = www-data
listen.mode = 0660


로그설정
error_log = /var/log/php/php-fpm.log
access.log = /var/log/php/$pool.access.log
slowlog = /var/log/php/$pool.log.slow
request_slowlog_timeout = 1
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 32M




6. php init script


http://starkey1984.blogspot.kr/2015/08/php-fpm.html


$ sudo nano /etc/init.d/php-fpm


php-fpm 안에 링크안의 내용을 붙여넣기


부팅시 자동시작하기 위해서 아래 명령어 실행


/etc/init.d$ sudo update-rc.d php-fpm defaults

2015년 11월 12일 목요일

ubuntu 14.04 nginx 설치 및 설정

1. 소스 다운로드




~/src$ tar -xvzf nginx-1.9.6.tar.gz


~/src$ cd nginx-1.9.6




2. 의존성 모듈 설치


$ sudo apt-get install gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev build-essential


3. echo 모듈 설치


~/src$ unzip master.zip

~/src$ mv echo-nginx-module-master echo-nginx-module



4. configure 설정


~/src/nginx-1.9.6$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --user=www-data --group=www-data --with-http_ssl_module --add-module=/home/ubuntu/src/echo-nginx-module   




4. 설치


~/src/nginx-1.9.6$ sudo make install

5. init 스크립트 만들기




6. 실행


$ sudo service nginx start






2015년 8월 19일 수요일

mysql table column collation 변경

alter table <some_table> convert to character set utf8 collate utf8_unicode_ci;
출처 - http://stackoverflow.com/questions/742205/how-to-change-the-default-collation-of-a-table

2015년 8월 18일 화요일

nginx 실행 스크립트

#!/bin/sh

### BEGIN INIT INFO
# Provides:  nginx
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx

# Include nginx defaults if available
if [ -r /etc/default/nginx ]; then
. /etc/default/nginx
fi

STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"

test -x $DAEMON || exit 0

. /lib/init/vars.sh
. /lib/lsb/init-functions

# Try to extract nginx pidfile
PID=$(cat /etc/nginx/nginx.conf | grep -Ev '^\s*#' | awk 'BEGIN { RS="[;{}]" } { if ($1 == "pid") print $2 }' | head -n1)
if [ -z "$PID" ]
then
PID=/run/nginx.pid
fi

# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi

#
# Function that starts the daemon/service
#
do_start()
{
# Return
#   0 if daemon has been started
#   1 if daemon was already running
#   2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON -- \
$DAEMON_OPTS 2>/dev/null \
|| return 2
}

test_nginx_config() {
$DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
#   0 if daemon has been stopped
#   1 if daemon was already stopped
#   2 if daemon could not be stopped
#   other if a failure occurred
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
RETVAL="$?"

sleep 1
return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID --name $NAME
return 0
}

#
# Rotate log files
#
do_rotate() {
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PID --name $NAME
return 0
}

#
# Online upgrade nginx executable
#
# "Upgrading Executable on the Fly"
# http://nginx.org/en/docs/control.html
#
do_upgrade() {
# Return
#   0 if nginx has been successfully upgraded
#   1 if nginx is not running
#   2 if the pid files were not created on time
#   3 if the old master could not be killed
if start-stop-daemon --stop --signal USR2 --quiet --pidfile $PID --name $NAME; then
# Wait for both old and new master to write their pid file
while [ ! -s "${PID}.oldbin" ] || [ ! -s "${PID}" ]; do
cnt=`expr $cnt + 1`
if [ $cnt -gt 10 ]; then
return 2
fi
sleep 1
done
# Everything is ready, gracefully stop the old master
if start-stop-daemon --stop --signal QUIT --quiet --pidfile "${PID}.oldbin" --name $NAME; then
return 0
else
return 3
fi
else
return 1
fi
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"

# Check configuration before stopping nginx
if ! test_nginx_config; then
log_end_msg 1 # Configuration error
exit 0
fi

do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC configuration" "$NAME"

# Check configuration before reload nginx
#
# This is not entirely correct since the on-disk nginx binary
# may differ from the in-memory one, but that's not common.
# We prefer to check the configuration and return an error
# to the administrator.
if ! test_nginx_config; then
log_end_msg 1 # Configuration error
exit 0
fi

do_reload
log_end_msg $?
;;
configtest|testconfig)
log_daemon_msg "Testing $DESC configuration"
test_nginx_config
log_end_msg $?
;;
status)
status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
;;
upgrade)
log_daemon_msg "Upgrading binary" "$NAME"
do_upgrade
log_end_msg 0
;;
rotate)
log_daemon_msg "Re-opening $DESC log files" "$NAME"
do_rotate
log_end_msg $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}" >&2
exit 3
;;
esac

:

php-fpm 실행 스크립트

#!/bin/sh
### BEGIN INIT INFO
# Provides:          php-fpm php5-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php5-fpm
# Description:       Starts PHP5 FastCGI Process Manager Daemon
### END INIT INFO

# Author: Ondrej Sury <ondrej@debian.org>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="PHP FastCGI Process Manager"
NAME=php-fpm
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--fpm-config /usr/local/php/php-fpm.conf -c /usr/local/php/php.ini"
PIDFILE=/var/run/php-fpm.pid
TIMEOUT=30
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function to check the correctness of the config file
#
do_check()
{
   [ "$1" != "no" ] && $DAEMON $DAEMON_ARGS -t 2>&1 | grep -v "\[ERROR\]"
   FPM_ERROR=$($DAEMON $DAEMON_ARGS -t 2>&1 | grep "\[ERROR\]")

   if [ -n "${FPM_ERROR}" ]; then
echo "Please fix your configuration file..."
$DAEMON $DAEMON_ARGS -t 2>&1 | grep "\[ERROR\]"
return 1
   fi
   return 0
}

#
# Function that starts the daemon/service
#
do_start()
{
# Return
#   0 if daemon has been started
#   1 if daemon was already running
#   2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS 2>/dev/null \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
# Return
#   0 if daemon has been stopped
#   1 if daemon was already stopped
#   2 if daemon could not be stopped
#   other if a failure occurred
start-stop-daemon --stop --quiet --retry=QUIT/$TIMEOUT/TERM/5/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently.  A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/TERM/5/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal USR2 --quiet --pidfile $PIDFILE --name $NAME
return 0
}

case "$1" in
   start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_check $VERBOSE
case "$?" in
   0)
do_start
case "$?" in
   0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
   2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
   1) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
   stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
   status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
   check)
       do_check yes
;;
   reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
   restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
 0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
 *)
  # Failed to stop
log_end_msg 1
;;
esac
;;
   *)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
exit 1
   ;;
esac

: