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

lamp编译安装

时间:2016-10-15 22:47:00      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:编译安装amp

lamp编译安装

================================================================================

编译安装amp

 1.编译前环境准备及相关介绍

系统环境:CentOS 6, 7

  • CentOS 6:apr, apr-util 的版本为1.3.9,不适用于httpd-2.4的编译安装;

  • CentOS 7:apr, apr-util的版本为1.4+,

(apr:简言之是为apache各程序包运行时提供的环境,可以当做是httpd的虚拟机,所以httpd是高度依赖于apr的)

  • 在生产环境中,一般不建议去编译安装,只有当默认提供的程序包不足以满足我们的需求时,即我们用到的模块没有时,才去编译安装。当然为了方便我们也可以自己制作成rpm包。

开发环境:

  任何编译安装依据的都是开发环境

  • Development Tools, 

  • Server Platform Development

各程序版本

  • httpd: 2.2, 2.4

  • php:5.3.x 5.4.x, 5.6.x

  • mysql:5.1, 5.5, 5.6, 5.7, 5.8, 8.0

  • mariadb:5.x, 10.x

httpd+php结合方式

 php的编译选项:

  • Modules:--with-apxs

      httpd MPM:

         prefork:编译的是进程模型的模块

         worker, event:

             专用选项 --enable-maintainer-zts 编译的是线程模型的模块

  • ftm:--enable-fpm 


编译安装amp

编译的amp环境:

  • 在CentOS 7上编译 httpd-2.4, mariadb, php-5.4

安装次序:

  • httpd, mariadb, php 

   httpd和mariadb是无先后次序的,但是php是依赖于前面的所以要放到最后编译;


安装MariaDB:

  • 预制的包管理器格式的程序包:

      rpm包:

         os vendor:安装 mariadb-devel包,编译php时会基于此程序包 ;

         MariaDB官方

  • 通用二进制格式的程序包:展包即用,是别人已经编译好的;

  • 源码包编译:项目构建工具为cmake, 而非流行的make;



1.这里我们以CentOS 7采用通用二进制的格式编译安装mariadb,详细过程如下:


   1)首先获取mariadb的程序包,并下载到本地

[root@localhost ~]# lftp 10.1.0.1/pub
lftp 10.1.0.1:/pub/Sources/7.x86_64/mariadb> ls
-rwxr--r--    1 500      500      445617978 Nov 05  2015 mariadb-10.1.8-linux-glibc_214-x86_64.tar.gz
-rwxr--r--    1 500      500      222601284 Nov 05  2015 mariadb-5.5.46-linux-x86_64.tar.gz
lftp 10.1.0.1:/pub/Sources/7.x86_64/mariadb> pwd
ftp://10.1.0.1/pub/Sources/7.x86_64/mariadb
lftp 10.1.0.1:/pub/Sources/7.x86_64/mariadb> mget mariadb-5.5.46-linux-x86_64.tar.gz 
222601284 bytes transferred in 9 seconds (24.84M/s)                                        
lftp 10.1.0.1:/pub/Sources/7.x86_64/mariadb> bye
[root@localhost ~]# ls
anaconda-ks.cfg  mariadb-5.5.46-linux-x86_64.tar.gz # 下载的程序包 公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# ll -h mariadb-5.5.46-linux-x86_64.tar.gz 
-rw-r--r-- 1 root root 213M 11月  5 2015 mariadb-5.5.46-linux-x86_64.tar.gz

   2)采用通用二进制的格式编译安装要求安装在/usr/local/mysql下

# 展开至/usr/local
[root@localhost ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local
[root@localhost ~]# cd /usr/local
[root@localhost local]# ls
bin  games    lib    libexec                      sbin   src
etc  include  lib64  mariadb-5.5.46-linux-x86_64  share
# 为了方便以后的升级和管理我们这里创建一个软链接
[root@localhost local]# ln -sv mariadb-5.5.46-linux-x86_64/ mysql
"mysql" -> "mariadb-5.5.46-linux-x86_64/"
[root@localhost local]# ll
总用量 44
drwxr-xr-x.  2 root root 4096 8月  12 2015 bin
drwxr-xr-x.  2 root root 4096 8月  12 2015 etc
drwxr-xr-x.  2 root root 4096 8月  12 2015 games
drwxr-xr-x.  2 root root 4096 8月  12 2015 include
drwxr-xr-x.  2 root root 4096 8月  12 2015 lib
drwxr-xr-x.  2 root root 4096 8月  12 2015 lib64
drwxr-xr-x.  2 root root 4096 8月  12 2015 libexec
drwxr-xr-x  12 root root 4096 10月 15 15:21 mariadb-5.5.46-linux-x86_64
lrwxrwxrwx   1 root root   28 10月 15 15:26 mysql -> mariadb-5.5.46-linux-x86_64/
drwxr-xr-x.  2 root root 4096 8月  12 2015 sbin
drwxr-xr-x.  5 root root 4096 8月  22 09:16 share
drwxr-xr-x.  2 root root 4096 8月  12 2015 src

   3)因为我使用的这台CentOS 7已经安装过mariadb了,所以为了防止和系统中的起冲突,所以,我把原来系统中的移除

[root@localhost local]# rpm -q mariadb-server
mariadb-server-5.5.44-2.el7.centos.x86_64
[root@localhost local]# yum remove mariadb-server # 移除本机服务器端程序包
[root@localhost local]# rpm -q mariadb
mariadb-5.5.44-2.el7.centos.x86_64
[root@localhost local]# yum remove mariadb # 卸载客户端程序包

    4)通常我们运行mysql都需要一个普通用户,所以要创建一个叫mysql的系统用户,和系统组;并且我们要创建一个数据库目录,(实际生产环境中应该放在一个单独的存储设备并且有冗余的功能,如:RAID10),并且授权属主和属组为myaql

[root@localhost local]# id mysql # mysql 用户已经存在
uid=27(mysql) gid=27(mysql) 组=27(mysql)
[root@localhost local]# mkdir -pv /mydata/data # 创建数据库目录
mkdir: 已创建目录 "/mydata"
mkdir: 已创建目录 "/mydata/data"
[root@localhost local]# chown -R mysql.mysql /mydata/data # 授权属主属组为mysql
[root@localhost local]# ll -d /mydata/data
drwxr-xr-x 2 mysql mysql 4096 10月 15 15:54 /mydata/data

    5)接下来我们设定数据库服务器的相关文件,并且都应该以mysql的身份运行,但为了保证安全,不能让mysql有写权限,所以属主为root,属组为mysql仅有读权限。

[root@localhost local]# chown -R root.mysql ./*
[root@localhost local]# ll
总用量 44
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 bin
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 etc
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 games
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 include
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 lib
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 lib64
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 libexec
drwxr-xr-x  12 root mysql 4096 10月 15 15:21 mariadb-5.5.46-linux-x86_64
lrwxrwxrwx   1 root mysql   28 10月 15 15:26 mysql -> mariadb-5.5.46-linux-x86_64/
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 sbin
drwxr-xr-x.  5 root mysql 4096 8月  22 09:16 share
drwxr-xr-x.  2 root mysql 4096 8月  12 2015 src

  6)接下来我们要初始化mysql,即生成元数据数据库

[root@localhost local]# cd mysql/
[root@localhost mysql]# ls
bin  COPYING  COPYING.LESSER  data  EXCEPTIONS-CLIENT  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

# 使用scripts/mysql_install_db 生成元数据数据库
[root@localhost mysql]# ./scripts/mysql_install_db --help # 查看帮助
Usage: ./scripts/mysql_install_db [OPTIONS]
  --basedir=path       The path to the MariaDB installation directory.
  --builddir=path      If using --srcdir with out-of-directory builds, you
                       will need to set this to the location of the build
                       directory where built files reside.
  --cross-bootstrap    For internal use.  Used when building the MariaDB system
                       tables on a different host than the target.
  --datadir=path       The path to the MariaDB data directory.
  --defaults-extra-file=name
                       Read this file after the global files are read.
  --defaults-file=name Only read default options from the given file name.
  --force              Causes mysql_install_db to run even if DNS does not
                       work.  In that case, grant table entries that
                       normally use hostnames will use IP addresses.
  --help               Display this help and exit.                     
  --ldata=path         The path to the MariaDB data directory. Same as
                       --datadir.
  --no-defaults        Don‘t read default options from any option file.
  --defaults-file=path Read only this configuration file.
  --rpm                For internal use.  This option is used by RPM files
                       during the MariaDB installation process.
  --skip-name-resolve  Use IP addresses rather than hostnames when creating
                       grant table entries.  This option can be useful if
                       your DNS does not work.
  --srcdir=path        The path to the MariaDB source directory.  This option
                       uses the compiled binaries and support files within the
                       source tree, useful for if you don‘t want to install
                       MariaDB yet and just want to create the system tables.
  --user=user_name     The login username to use for running mysqld.  Files
                       and directories created by mysqld will be owned by this
                       user.  You must be root to use this option.  By default
                       mysqld runs using your current login name and files and
                       directories that it creates will be owned by you.

All other options are passed to the mysqld program

# 指明用户,位置,生成元数据库数据文件,
[root@localhost mysql]# ./scripts/mysql_install_db --datadir=/mydata/data --user=mysql --skip-name-resolve
[root@localhost mysql]# ls /mydata/data/  # 查看生成的文件如下
aria_log.00000001  aria_log_control  mysql  performance_schema  test

   7)如上mysql数据库就已经创建完成了,接下来我们要为数据库提供主配置文件,需要复制示例配置文件到/etc/my.cnf/目录下,修改即可;

[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# ls
bin             EXCEPTIONS-CLIENT  man         share
COPYING         include            mysql-test  sql-bench
COPYING.LESSER  INSTALL-BINARY     README      support-files 
data            lib                scripts
[root@localhost mysql]# ls support-files/ # 配置文件示例
binary-configure        my-large.cnf         mysql-log-rotate
magic                   my-medium.cnf        mysql.server
my-huge.cnf             my-small.cnf         SELinux
my-innodb-heavy-4G.cnf  mysqld_multi.server

# 复制示例配置文件到/etc/my.cnf.d下并命名为server.cnf(只要以.cnf结尾即可)
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf.d/server.cnf 
[root@localhost mysql]# vim /etc/my.cnf.d/server.cnf  # 编辑文件如下图

 技术分享


    8)为mysql提供sysv服务脚本

[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# ls support-files/
binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server # 脚本文件
magic             my-large.cnf            mysqld_multi.server  SELinux
my-huge.cnf       my-medium.cnf           mysql-log-rotate 

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #复制脚本
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld # 添加执行权限

#添加至服务列表
[root@localhost mysql]# chkconfig --add mysqld

    9)接下来我们就可以启动服务了

[root@localhost mysql]# service mysqld start
Starting MySQL... SUCCESS!  # 启动成功
[root@localhost mysql]# ss -tnl # 查看端口3306
State       Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN      0      128             127.0.0.1:9000                                *:*                  
LISTEN      0      50                      *:3306                                *:*                  
LISTEN      0      5           192.168.122.1:53                                  *:*                  
LISTEN      0      128                     *:22                                  *:*                  
LISTEN      0      128             127.0.0.1:631                                 *:*                  
LISTEN      0      100             127.0.0.1:25                                  *:*                  
LISTEN      0      128             127.0.0.1:6010                                *:*                  
LISTEN      0      128                    :::80                                 :::*                  
LISTEN      0      128                    :::22                                 :::*                  
LISTEN      0      128                   ::1:631                                :::*                  
LISTEN      0      100                   ::1:25                                 :::*                  
LISTEN      0      128                   ::1:6010                               :::*
# 客户端程序文件在/usr/local/mysql/bin/mysql,可以连接上去
[root@localhost mysql]# /usr/local/mysql/bin/mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.46-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]>

   10)为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下配置:


  输出mysql的man手册至man命令的查找路径:

      编辑/etc/man_db.conf添加如下图所示内容

技术分享

  • 出mysql的头文件至系统文件路径/usr/include

[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
"/usr/include/mysql" -> "/usr/local/mysql/include/"
  • 输出mysql的库文件给系统库查找路径:

       # echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf

     而后让系统重新载入系统库

       # ldconfig

  • 修改PATH环境变量,让系统可以直接使用mysql的相关命令。 

[root@localhost~]# cat << eof > /etc/profile.d/mysql.sh
> PATH=$PATH:/usr/local/mysql/bin
> eof
[root@localhost profile.d]# cat mysql.sh 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

 如上整个编译过程就已经完成了,直接运行命令即可。。。

 总结过程如下:

技术分享


2.httpd-2.4编译安装

技术分享


3.php5编译安装

技术分享







lamp编译安装

标签:编译安装amp

原文地址:http://1992tao.blog.51cto.com/11606804/1862247

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