码迷,mamicode.com
首页 > 其他好文 > 详细

搭建LNMP

时间:2016-08-28 12:24:56      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:

下载软件包

百度云地址下载地址:http://pan.baidu.com/s/1eSfWNoY

一共有17个包

 [root@localhost lnmp]# ls /usr/local/src/lnmp
libgd-2.1.0.tar.gz      mysql-5.6.19.tar.gz    php-5.5.14.tar.gz cmake-2.8.11.2.tar.gz  
libmcrypt-2.5.8.tar.gz  1lib-5.1.2.tar.gz Discuz_X3.2_SC_GBK.zip    libpng-1.6.12.tar.gz   
nginx-1.6.0.tar.gz     tiff-4.0.3.tar.gz libvpx-v1.3.0.tar.bz2     yasm-1.2.0.tar.gz
openssl-1.0.1h.tar.gz freetype-2.5.3.tar.gz   zlib-1.2.8.tar.gz jpegsrc.v9a.tar.gz   pcre-8.35.tar.gz

 

安装编译工具及库文件

yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel  fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd 
libXrender gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libjpeg-turbo
libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp
libXau-devel libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl
php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel


安装配置mysql服务

1. 安装cmake编译工具

cd /usr/local/src/lnmp
tar xzvf cmake-2.8.11.2.tar.gz
cd cmake-2.8.11.2/
./configure
make
make install

2.创建用于执行mysql服务程序的帐号:

useradd mysql -s /sbin/nologin

3.创建数据库程序和文件的目录,并设置目录的所属与所组:

mkdir -p /usr/local/mysql/var
chown -Rf mysql:mysql /usr/local/mysql

4.安装Mysql服务程序

cd /usr/local/src/lnmp
tar xzvf mysql-5.6.19.tar.gz
cd mysql-5.6.19/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc
make
make install

5.删除系统默认的配置文件:

rm -rf /etc/my.cnf

6.生成系统数据库

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

7.创建配置文件的软连接文件my.cnf

ln -s my.cnf /etc/my.cnf 

8.将mysqld服务程序添加到开机启动项:

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig mysqld on

9.编辑启动项的配置文件:

vim /etc/init.d/mysqld

basedir=/usr/local/mysql
datadir=/usr/local/mysql/var

10.启动mysqld服务程序:

service mysqld start

11.把mysql服务程序命令目录添加到环境变量中

echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile

12.将mysqld服务程序的库文件链接到默认的位置:

mkdir /var/lib/mysql
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

13.初始化mysqld服务程序:

[root@lnmp mysql]# mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, well need the current
password for the root user.  If youve just installed MySQL, and
you havent set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y  
New password: 输入要为root用户设置的数据库密码。
Re-enter new password: 重复再输入一次密码。
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y(删除匿名帐号)
 ... Success!
Normally, root should only be allowed to connect from localhost.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y(禁止root用户从远程登陆)
 ... Success!
By default, MySQL comes with a database named test that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y(删除test数据库并取消对其的访问权限)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y(刷新授权表,让初始化后的设定立即生效)
 ... Success!
All done!  If youve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

 

安装nginx服务

1.安装PCRE(Perl兼容的正则表达式库)

cd /usr/local/src/lnmp/
mkdir /usr/local/pcre
tar xzvf pcre-8.35.tar.gz
cd pcre-8.35
./configure --prefix=/usr/local/pcre
make
make install

2.安装openssl服务程序

cd /usr/local/src/lnmp/
mkdir /usr/local/openssl
tar xzvf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
./config --prefix=/usr/local/openssl
make
make install

3.把openssl服务程序命令目录添加到环境变量中

vim /etc/profile
//将配置文件最下面的参数追加参数为:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
[root@localhost pcre-8.35]# source /etc/profile

4.安装zlib数据压缩函数库

cd /usr/local/src/lnmp/
tar xf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make
make install

5.创建用于执行nginx服务的用户www:

useradd www -s /sbin/nologin

6.安装nginx服务程序(openssl,zlib,pcre要写成源码解压路径!!!):

cd /usr/local/src/lnmp/
tar xf nginx-1.6.0.tar.gz
cd nginx-1.6.0
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/lnmp/openssl-1.0.1h --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-pcre=/usr/local/src/lnmp/pcre-8.35
make
make install
 

7.创建nginx程序脚本

vim /etc/rc.d/init.d/nginx

#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse # proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed s/[^*]*--user=\([^ ]*\).*/\1/g -`
        if [ -z "`grep $user /etc/passwd`" ]; then
                useradd -M -s /bin/nologin $user
        fi
options=`$nginx -V 2>&1 | grep configure arguments:`
for opt in $options; do
        if [ `echo $opt | grep .*-temp-path` ]; then
                value=`echo $opt | cut -d "=" -f 2`
                if [ ! -d "$value" ]; then
                        # echo "creating" $value
                        mkdir -p $value && chown -R $user $value
                fi
        fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
        rh_status_q && exit 0
        $1
        ;;
stop)
        rh_status_q || exit 0
        $1
        ;;
restart|configtest)
$1
;;
reload)
        rh_status_q || exit 7
        $1
        ;;
force-reload)
        force_reload
        ;;
status)
        rh_status
        ;;
condrestart|try-restart)
        rh_status_q || exit 0
        ;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

8.给脚本执行权限,并使它开机启动

chmod 755 /etc/rc.d/init.d/nginx
chkconfig nginx on

9.启动nginx服务,并访问

 service nginx start

技术分享

 

安装配置php服务

1.安装yasm汇编器

 

cd /usr/local/src/lnmp
tar zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install

 

2.安装libmcrypt加密算法扩展库

cd /usr/local/src/lnmp
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install

3.安装libvpx视频编码器

cd /usr/local/src/lnmp
tar xjvf libvpx-v1.3.0.tar.bz2
cd libvpx-v1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make
make install

4.安装Tiff标签图像文件格式

cd /usr/local/src/lnmp
tar zxvf tiff-4.0.3.tar.gz
cd tiff-4.0.3
./configure --prefix=/usr/local/tiff --enable-shared
make
make install

5.安装libpng图片(png格式)函数库

cd /usr/local/src/lnmp
tar zxvf libpng-1.6.12.tar.gz
cd libpng-1.6.12
./configure --prefix=/usr/local/libpng --enable-shared
make
make install

6.安装freetype字体引擎

cd /usr/local/src/lnmp
tar zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/freetype --enable-shared
make
make install

7.安装libgd图像处理程序

cd /usr/local/src/lnmp
tar zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
make
make install

8.安装t1lib图片生成函数库

cd /usr/local/src/lnmp
tar zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make
make install

9.将函数库文件放至合适的位置:

cd /usr/local/src/lnmp
ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
cp -frp /usr/lib64/libXpm.so* /usr/lib/

10.安装php服务程序

cd /usr/local/src/lnmp
tar -zvxf php-5.5.14.tar.gz
cd php-5.5.14
export LD_LIBRARY_PATH=/usr/local/libgd/lib
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype
make
make install

 

搭建LNMP

标签:

原文地址:http://www.cnblogs.com/zydev/p/5814657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!