Rootop 服务器运维与web架构

lnmp源码编译过程

| 暂无评论

主要安装包:(自行下载)
目前全部软件的最新版本:
mysql-5.6.16.tar.gz
nginx-1.4.5.tar.gz
php-5.5.9.tar.gz

系统环境:centos6.5 x64
附加包:(自行下载)
cmake-2.8.10.2.tar.gz
bison-2.5.tar.gz
pcre-8.12.tar.gz

1、安装mysql:

首先安装cmake和bison:

[root@localhost smb]# tar zxvf cmake-2.8.10.2.tar.gz
[root@localhost smb]# cd cmake-2.8.10.2
[root@localhost cmake-2.8.10.2]# ./configure
[root@localhost cmake-2.8.10.2]# gmake
[root@localhost cmake-2.8.10.2]# make install

[root@localhost smb]# tar zxvf bison-2.5.tar.gz
[root@localhost smb]# cd bison-2.5
[root@localhost bison-2.5]# ./configure
[root@localhost bison-2.5]# make
[root@localhost bison-2.5]# make install

[root@localhost ~]# cd mysql-5.6.16
[root@localhost mysql-5.6.16]# useradd mysql -s /sbin/nologin

[root@localhost mysql-5.6.16]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock\
> -DDEFAULT_CHARSET=utf8\
> -DDEFAULT_COLLATION=utf8_general_ci\
> -DWITH_EXTRA_CHARSETS=all\
> -DWITH_INNOBASE_STORAGE_ENGINE=1\
> -DWITH_MYISAM_STORAGE_ENGINE=1\
> -DWITH_MEMORY_STORAGE_ENGINE=1\
> -DWITH_READLINE=1\
> -DENABLED_LOCAL_INFILE=1\
> -DMYSQL_DATADIR=/usr/local/mysql/data\
> -DMYSQL_USER=mysql\
> -DMYSQL_TCP_PORT=3306

(前面的大于号不是手动敲上去的,是在每一句参数后面有个斜杠\,回车以后自动生成,完整的参数如下:

 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_USER=mysql

不要误认为大于号是编译参数)

[root@localhost mysql-5.6.16]# make && make install
[root@localhost mysql-5.6.16]# cp support-files/my-default.cnf /etc/my.cnf
(打开配置文件发现基本没参数,不知道高版本为何这样?还是我编译的问题?)
[root@localhost mysql-5.6.16]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.6.16]# chmod 755 /etc/init.d/mysqld

以上主要是添加启动脚本,添加 权限,方便用service + 服务名管理。

[root@localhost ~]# chown -R root.mysql /usr/local/mysql/
[root@localhost ~]# chown -R mysql /usr/local/mysql/data/


[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

[root@localhost ~]# service mysqld start
Starting MySQL.. [确定]

初始化mysql,mysql编译完成。

2、安装nginx:

首先安装pcre:

 [root@localhost smb]# tar zxvf pcre-8.12.tar.gz
 [root@localhost smb]# cd pcre-8.12
 [root@localhost pcre-8.12]# ./configure
 [root@localhost pcre-8.12]# make
 [root@localhost pcre-8.12]# make install
 [root@localhost pcre-8.12]# cd
 [root@localhost ~]# cd nginx-1.4.5
 [root@localhost nginx-1.4.5]# useradd www -s /sbin/nologin
 [root@localhost nginx-1.4.5]# yum install -y openssl-devel
 [root@localhost nginx-1.4.5]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
 [root@localhost nginx-1.4.5]# make && make install

添加启动脚本:
[root@localhost ~]# vi /etc/init.d/nginx

这个脚本从一键lnmp安装脚本中获取,写的不错。

#! /bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
 $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
 kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

do_reload() {
 kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}

case "$1" in
 start)
 echo -n "Starting $DESC: $NAME"
 do_start
 echo "."
 ;;
 stop)
 echo -n "Stopping $DESC: $NAME"
 do_stop
 echo "."
 ;;
 reload|graceful)
 echo -n "Reloading $DESC configuration..."
 do_reload
 echo "."
 ;;
 restart)
 echo -n "Restarting $DESC: $NAME"
 do_stop
 do_start
 echo "."
 ;;
 *)
 echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
 exit 3
 ;;
esac

exit 0

[root@localhost ~]# chmod 755 /etc/init.d/nginx
[root@localhost ~]# service nginx start
Starting nginx daemon: nginx.
[root@localhost ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 12351 root 6u IPv4 1197244 0t0 TCP *:http (LISTEN)
nginx 12352 www 6u IPv4 1197244 0t0 TCP *:http (LISTEN)

3、安装php:

先安装一些所需的库文件
[root@localhost ~]# yum install -y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel
安装 mhash-0.9.9.9 libmcrypt-2.5.8 mcrypt-2.6.8,直接./configure make make install即可,过程略过。

[root@localhost php-5.5.9]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo

[root@localhost php-5.5.9]# make && make install
模块被安装在/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/下。

[root@localhost php-5.5.9]# mkdir -p /usr/local/php/etc
[root@localhost php-5.5.9]# cp php.ini-production /usr/local/php/etc/php.ini //复制配置文件
[root@localhost php-5.5.9]# ln -s /usr/local/php/etc/php.ini /etc/php.ini //方便编辑

[root@localhost ~]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

pid = run/php-fpm.pid
user = www
group = www
listen = 127.0.0.1:9000

主要定义上面三行参数

拷贝启动文件,设置开机启动。
[root@localhost etc]# cd
[root@localhost ~]# cd tar_gz/php-5.5.9
[root@localhost php-5.5.9]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.5.9]# chmod 755 /etc/init.d/php-fpm
[root@localhost php-5.5.9]# chkconfig php-fpm on

启动php-fpm:
[root@localhost php-5.5.9]# service php-fpm start
Starting php-fpm done
[root@localhost php-5.5.9]# lsof -i:9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 3046 root 7u IPv4 267783 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 3047 www 0u IPv4 267783 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 3048 www 0u IPv4 267783 0t0 TCP localhost:cslistener (LISTEN)

4、测试:

配置nginx,支持php,并添加测试页面测试。
[root@localhost php-5.5.9]# vi /usr/local/nginx/conf/nginx.conf
在最后一个大括号上面添加一行:

include vhost_*.conf

因为一般情况下不再去修改主配置文件,通过include参数,在启动nginx的时候根据定义值去加载vhost开头的配置文件。
[root@localhost ~]# vi /usr/local/nginx/conf/vhost_rootop.conf

server
 {
 listen 80;
 server_name 192.168.1.105;
 index index.html index.htm index.php;
 root /mnt/data/web/rootop/;

 location ~ .*\.(php|php5)?$
 {
 try_files $uri =404;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 include fastcgi.conf;
 }

 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
 {
 expires 30d;
 }

 location ~ .*\.(js|css)?$
 {
 expires 12h;
 }

 access_log off;
 }

重启nginx,写一个phpinfo测试页测试。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/2164.html

赞赏

微信赞赏支付宝赞赏

作者:Venus

专注于 服务器运维与web架构 E-mail:venus#rootop.org

发表评论