34233 发表于 2016-2-1 09:47:24

LNMP安装与启动脚本编写

1、安装mysql

1
cd /usr/local/src/




下载mysql:

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




解压:

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




更改命名:

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




设置mysql用户:

1
useradd -s /sbin/nologin mysql




创建目录与目录所属:

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




编译:

1
cd /usr/local/mysql





1
./scripts/mysql_install_db --user=mysql--datadir=/data/mysql




拷贝配置文件:

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




设置启动脚本:


1
cp support-files/mysql.server/etc/init.d/mysqld





1
chmod 755 /etc/init.d/mysqld





1
2
3
vim /etc/init.d/mysqld   #修改datadir
         {basedir=/usr/local/mysql
         {datadir=/data/mysql





1
2
3
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start





2、php安装
下载:

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




解压:

1
tar jxf php-5.4.37.tar.bz2




创建账户:

1
useradd -s /sbin/nologin php-fpm




编译:

1
cd php-5.4.37





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
./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





1
make && make install




拷贝配置文件:

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




配置启动项:

1
2
3
4
5
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配置文件:

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





3、安装nginx
下载:

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




解压:

1
tar zxvf nginx-1.6.3.tar.gz




编译:

1
2
3
4
cd nginx-1.6.3
./configure   --prefix=/usr/local/nginx   --with-pcre
make
make install




启动nginx:

1
/usr/local/nginx/sbin/nginx




编写nginx启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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





保存后:

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






页: [1]
查看完整版本: LNMP安装与启动脚本编写