LNMP安装与启动脚本编写

1、安装mysql

cd /usr/local/src/

下载mysql:

wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz

解压:

tar zxvf/usr/local/src/mysql-5.1.72-linux-x86_64-glibc23.tar.gz

更改命名:

mv mysql-5.1.72-linux-x86_64-glibc23  /usr/local/mysql

设置mysql用户:

useradd -s /sbin/nologin mysql

创建目录与目录所属:

mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql

编译:

cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql  --datadir=/data/mysql

拷贝配置文件:

cp support-files/my-large.cnf /etc/my.cnf

设置启动脚本:

cp support-files/mysql.server  /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld   #修改datadir
         {basedir=/usr/local/mysql
         {datadir=/data/mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start

 

2、php安装

下载:

wget http://cn2.php.net/distributions/php-5.4.37.tar.bz2

解压:

tar jxf php-5.4.37.tar.bz2

创建账户:

useradd -s /sbin/nologin php-fpm

编译:

cd php-5.4.37
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir --with-gd \
--with-jpeg-dir --with-png-dir \
--with-freetype-dir --with-iconv-dir \
--with-zlib-dir --with-mcrypt \
--enable-soap --enable-gd-native-ttf \
--enable-ftp --enable-mbstring \
--enable-exif --disable-ipv6 --with-curl
make && make install

拷贝配置文件:

cp php.ini-production/usr/local/php  /etc/php.ini

配置启动项:

cp /usr/local/src/php-5.4.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
service php-fpm start
chkconfig php-fpm on


配置php-fpm配置文件:

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 

3、安装nginx

下载:

wget http://nginx.org/download/nginx-1.6.3.tar.gz

解压:

tar zxvf nginx-1.6.3.tar.gz

编译:

cd nginx-1.6.3
./configure   --prefix=/usr/local/nginx   --with-pcre
make
make install

启动nginx: 

/usr/local/nginx/sbin/nginx

编写nginx启动脚本

vim/etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
 
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
 
start() {
       echo -n $"Starting $prog: "
       mkdir -p /dev/shm/nginx_temp
       daemon $NGINX_SBIN -c $NGINX_CONF
       RETVAL=$?
       echo
       return $RETVAL
}
 
stop() {
       echo -n $"Stopping $prog: "
       killproc -p $NGINX_PID $NGINX_SBIN -TERM
       rm -rf /dev/shm/nginx_temp
       RETVAL=$?
       echo
       return $RETVAL
}
 
reload(){
       echo -n $"Reloading $prog: "
       killproc -p $NGINX_PID $NGINX_SBIN -HUP
       RETVAL=$?
       echo
       return $RETVAL
}
 
restart(){
       stop
       start
}
 
configtest(){
   $NGINX_SBIN -c $NGINX_CONF -t
   return 0
}
 
case "$1" in
 start)
       start
       ;;
 stop)
       stop
       ;;
 reload)
       reload
       ;;
 restart)
       restart
       ;;
 configtest)
       configtest
       ;;
  *)
       echo $"Usage: $0 {start|stop|reload|restart|configtest}"
       RETVAL=1
esac
 
exit $RETVAL

 

保存后:

chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on


你可能感兴趣的:(LNMP,启动脚本)