LNAMP 环境配置小结

前段时间配置 LNAMP(Linux + Nginx + Apache + MySQL + PHP)环境,遇到过一些小问题,今天有空做个小结,正好也复习一下。

VPS 为 RamHost 的 Standard Plan,系统为 CentOS 5.5。

系统优化的不错,开机只占用 5M 内存,不过他家的 Debian 系统优化得更厉害,开机仅占用 3M,但同时也带来一些小问题:

1. Apache 启动故障:

直接在 /etc/rc.local 中添加 /usr/local/apache/bin/apachectl start 无法开机自启动,原因未知。解决方法:重建启动脚本,添加到系统服务,脚本如下:

#!/bin/bash
# v 0.0.1
# create by gesion<gesion@163.com>
# httpd - This shell script takes care of starting and stopping httpd.
#
# chkconfig: 35 70 30
# description: httpd - Apache2 is powerful http web/proxy server
# processname: httpd
bin="/usr/sbin/httpd"
pid="/var/run/httpd.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
[ -x $bin ] || exit 0
RETVAL=0
prog="httpd"
# Start
start() {
        if [ -e $pid -a ! -z $pid ]; then
                status $prog
                exit 1
        else
                echo -n $"Starting $prog: "
                $bin start && success || failure
                RETVAL=$?
                echo
        fi
        return $RETVAL
}
# Stop
stop() {
        if [ -e $pid -a ! -z $pid ]; then
                echo -n $"Stopping $prog: "
                $bin stop && success || failure
                RETVAL=$?
                echo
        else
                status $prog
                exit 1
        fi
        return $RETVAL
}
# Restart
restart() {
        if [ -e $pid -a ! -z $pid ]; then
                echo -n $"Restarting $prog: "
                $bin restart && success || failure
                RETVAL=$?
                echo
        else
                status $prog
                exit 1
        fi
        return $RETVAL
}
# Reload
reload() {
        if [ -e $pid -a ! -z $pid ]; then
                echo -n $"Reloading $prog: "
                kill -HUP `cat $pid` && success || failure
                RETVAL=$?
                echo
        else
                status $prog
                exit 1
        fi
        return $RETVAL
}
# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        reload)
                reload
                ;;
        status)
                status $prog
                RETVAL=$?
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart|reload|status}"
                exit 1
esac

exit $RETVAL

新启动脚本依赖于原来脚本,并添加一个 reload 方法,方便修改配置后无缝重启
* 注:pid 文件路径请自行修改。

2. 安装 mutt 时 MySQL 依赖:

因为 RamHost 的系统都是经过优化,启动进程并没有 sendmail,所以安装 mutt 时会依赖安装 exim,而 exim 又会依赖安装 MySQL。经过排查,发现是因为 exim 依赖 libmysqlclient_r.so.15 库,但是我安装的 MySQL 所带的库版本已经是 16。解决办法:

rpm -ivh http://mysql.he.net/Downloads/MySQL-5.1/MySQL-shared-compat-5.1.55-1.rhel5.i386.rpm
# Or
yum install sendmail

yum install mutt

《LNAMP 环境配置小结》有3个想法

  1. 你好
    我装了lnamp总是配置不好
    nginx 404 Not Found
    apache
    Forbidden
    You don’t have permission to access /localhost on this server.

    [root@localhost ~]# netstat -lnpt
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4501/php-fpm.conf)
    tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4798/mysqld
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3729/nginx.conf
    tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3765/cupsd
    tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3922/sendmail: acce
    tcp 0 0 :::8080 :::* LISTEN 3743/httpd
    tcp 0 0 :::8081 :::* LISTEN 3743/httpd
    tcp 0 0 :::22 :::* LISTEN 3756/sshd
    [root@localhost ~]#
    能把配置文件发给我参考吧
    多谢
    microsunny@163.com
    qq 344622568

发表评论

电子邮件地址不会被公开。 必填项已用*标注