设为首页 收藏本站
查看: 1093|回复: 0

LNMP的编译安装与xcache、memcached的安装配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-10-20 08:30:24 | 显示全部楼层 |阅读模式
大纲:
一、前言
二、系统环境与软件版本
三、编译环境的准备
四、编译安装nginx及其配置
五、编译安装、配置mysql
六、编译安装PHP
七、整合nginx与PHP
八、安装配置PHP加速器xcache
九、安装配置memcached
十、安装memcached的PHP扩展

一、前言
    由于公司的服务器采用的是LNMP的架构,平时接触相对较多,今天会系统的把LNMP的安装配置过程写成博文,有关nginx的其他高级功能的配置,mysql的相关知识,会在后面的时间里陆续写成博客。


二、系统环境与软件版本
    操作系统:CentOS 5.8    内核版本号:2.6.18-308.el5
    平台    :x86_64

   软件版本
    nginx-1.6.1.tar.gz
    mysql-5.6.20.tar.gz   
    php-5.4.32.tar.bz2
    xcache-3.2.0.tar.gz   
    memcached-1.4.20.tar.gz

三、编译环境的准备
    1、使用yum安装开发包

1
[iyunv@vm_101 ~]# yum -y groupinstall "Development Tools" "Development Libraries"



    2、安装nginx的依赖包

1
[iyunv@vm_101 ~]# yum -y install pcre pcre-devel zlib zlib-devel




四、编译安装nginx及其配置
    1、解压包

1
2
[iyunv@vm_101 ~]# tar xf nginx-1.6.1.tar.gz -C /opt/
[iyunv@vm_101 ~]# cd /opt/nginx-1.6.1/



    2、为nginx创建用户与用户组

1
2
[iyunv@vm_101 nginx-1.6.1]# groupadd -r nginx
[iyunv@vm_101 nginx-1.6.1]# useradd -r -g nginx -s /sbin/nologin nginx



    3、创建nginx的安装目录

1
[iyunv@vm_101 nginx-1.6.1]# mkdir /usr/local/nginx



    4、编译安装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
[iyunv@vm_101 nginx-1.6.1]# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid  \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--with-pcre
…………
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/tmp/nginx/client/"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
  nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
  nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi"
  nginx http scgi temporary files: "scgi_temp"
        ###如果出现报错的话,应该是由于软件包的依赖关系所导致的,自行安装相应的软件包即可
[iyunv@vm_101 nginx-1.6.1]# make && make install



5、为nginx提供启动脚本
    在nginx的官网上提供了相应的启动脚本(http://wiki.nginx.org/InitScripts),结合刚才的配置参数做出相应的修改即可:
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
[iyunv@vm_101 nginx-1.6.1]# vim /etc/init.d/nginx
#!/bin/sh
#
# 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:      /etc/sysconfig/nginx
# pidfile:     /var/run/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/sbin/nginx"
prog=$(basename $nginx)
  
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  
lockfile=/var/lock/nginx.lock
  
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



    6、为启动脚本添加执行权限

1
[iyunv@vm_101 nginx-1.6.1]# chmod +x /etc/init.d/nginx



    7、启动nginx

1
2
[iyunv@vm_101 nginx-1.6.1]# /etc/init.d/nginx start
Starting nginx:                                            [  OK  ]



    8、将nginx添加进服务列表,并设置为开机自启

1
2
3
4
[iyunv@vm_101 nginx-1.6.1]# chkconfig --add nginx
[iyunv@vm_101 nginx-1.6.1]# chkconfig nginx on
[iyunv@vm_101 nginx-1.6.1]# chkconfig nginx --list
nginx          0:off1:off2:on3:on4:on5:on6:off



    9、查看端口号

1
2
3
4
5
6
[iyunv@vm_101 nginx-1.6.1]# lsof -i :80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   17211  root    6u  IPv4 124804      0t0  TCP *:http (LISTEN)
nginx   17212 nginx    6u  IPv4 124804      0t0  TCP *:http (LISTEN)
[iyunv@vm_101 nginx-1.6.1]# netstat -tunlp | grep 80
tcp    0      0 0.0.0.0:80          0.0.0.0:*             LISTEN      17211/nginx



  10、测试一下(根据服务器的IP地址进行访问)
    注:由于做测试的主机是公司内网的测试机,博主现在周末在家休息时写的博客,所以这个测试就在本地使用curl工具给大家演示一下了。

1
[iyunv@vm_101 nginx-1.6.1]# curl http://192.168.0.101/



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>



可以发现网页访问正常。
    注:如果使用其他主机请求,导致无法访问,请检查iptables的配置信息,或者直接关闭iptables

11、配置nginx
    1、编辑nginx的主配置文件

1
2
3
4
5
[iyunv@vm_101 ~]# vim /etc/nginx/nginx.conf        ##在HTTP段添加一条配置项:
http {
    include       mime.types;
    include       server.conf;        ###添加这一行
    default_type  application/octet-stream;



    2、在/etc/nginx/目录下创建server.conf文件
1
2
3
4
5
6
7
8
9
10
11
[iyunv@vm_101 ~]# vim /etc/nginx/server.conf
server {
        listen       80;
        server_name  www.test.com;
location / {
            root   /home/html;
            index  index.html;
        }
}
[iyunv@vm_101 ~]# vim /home/html/index.html
<h1>test file</h1>



    3、本地绑定hosts

win7的路径为:C:\Windows\System32\drivers\etc\hosts
Linux的路径为: /etc/hosts
在上述文件中加入:
192.168.0.101    www.test.com
1
2
3
4
5
6
[iyunv@vm_101 ~]# /etc/init.d/nginx reload
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reloading nginx:                                           [  OK  ]
[iyunv@vm_101 ~]# curl http://www.test.com
<h1>test file</h1>



正常访问。


五、编译安装、配置mysql
    1、创建用户与相应的目录

1
2
3
4
5
[iyunv@vm_101 ~]# groupadd -r mysql
[iyunv@vm_101 ~]# useradd -r -g mysql -s /sbin/nologin mysql
[iyunv@vm_101 ~]# mkdir /home/mysql         #mysql的数据目录
[iyunv@vm_101 ~]# chown -R mysql:mysql /home/mysql/
[iyunv@vm_101 ~]# mkdir /usr/local/mysql    #mysql的安装目录



    2、解压缩

1
2
[iyunv@vm_101 ~]# tar zxvf mysql-5.6.20.tar.gz -C /opt/
[iyunv@vm_101 ~]# cd /opt/mysql-5.6.20/



    3、编译安装

    从MySQL5.5开始就要用cmake安装了,已不能用./configure编译安装,我们查看一下mysql5.6.12的安装目录,从下面的安装目录我们可以看到,里面根本没有configure文件,下面我们来说说cmake,
cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。
    cmake指定编译选项的方式不同于make,其实现方式对比如下
./configure 对应的是 cmake .        #注意:Linux命令行下cmake后面是需要带一个"."的
./configure --help 对应的是 cmake . -LH 或者是 ccmake
编译安装前,请确保自己的服务器已经安装过cmake
如果没有请执行:yum -y install cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@vm_101 mysql-5.6.20]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/home/mysql \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DENABLE_DOWNLOADS=1 \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci



出现报错:
1
2
3
4
5
6
7
8
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Download failed, error: 7;"couldn't connect to server"
-- To enable google test, please download http://googlemock.googlecode.com/files/gmock-1.6.0.zip to the directory /opt/mysql-5.6.20/source_downloads
-- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/mysql-5.6.20



自己手动下载(可能需要翻墙)该文件,上传至相应的目录,并删除CMakeCache.txt文件,重新执行cmake命令,又出现报错:
1
2
CMake Error: Problem with tar_extract_all(): Invalid argument
CMake Error: Problem extracting tar: /usr/local/src/mysql-5.6.13/source_downloads/gmock-1.6.0.zip



谷歌了一下,需要个手动解压该文件:

1
2
3
4
5
6
[iyunv@vm_101 mysql-5.6.20]# cd source_downloads/
[iyunv@vm_101 source_downloads]# unzip gmock-1.6.0.zip
[iyunv@vm_101 source_downloads]# cd gmock-1.6.0
[iyunv@vm_101 source_downloads]# cd gmock-1.6.0
[iyunv@vm_101 gmock-1.6.0]# ./configure
[iyunv@vm_101 gmock-1.6.0]# make






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-26223-1-1.html 上篇帖子: linux下源码包编译安装LAMP环境 下篇帖子: LAMT+memcached实现session绑定
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表