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 编译的是线程模型的模块
◆fpm:--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/publftp 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.gzlftp 10.1.0.1:/pub/Sources/7.x86_64/mariadb> pwdftp://10.1.0.1/pub/Sources/7.x86_64/mariadblftp 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 ~]# lsanaconda-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]# lsbin games lib libexec sbin srcetc 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总用量 44drwxr-xr-x. 2 root root 4096 8月 12 2015 bindrwxr-xr-x. 2 root root 4096 8月 12 2015 etcdrwxr-xr-x. 2 root root 4096 8月 12 2015 gamesdrwxr-xr-x. 2 root root 4096 8月 12 2015 includedrwxr-xr-x. 2 root root 4096 8月 12 2015 libdrwxr-xr-x. 2 root root 4096 8月 12 2015 lib64drwxr-xr-x. 2 root root 4096 8月 12 2015 libexecdrwxr-xr-x 12 root root 4096 10月 15 15:21 mariadb-5.5.46-linux-x86_64lrwxrwxrwx 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 sbindrwxr-xr-x. 5 root root 4096 8月 22 09:16 sharedrwxr-xr-x. 2 root root 4096 8月 12 2015 src
3)因为我使用的这台CentOS 7已经安装过mariadb了,所以为了防止和系统中的起冲突,所以,我把原来系统中的移除
[root@localhost local]# rpm -q mariadb-servermariadb-server-5.5.44-2.el7.centos.x86_64[root@localhost local]# yum remove mariadb-server # 移除本机服务器端程序包[root@localhost local]# rpm -q mariadbmariadb-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/datadrwxr-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总用量 44drwxr-xr-x. 2 root mysql 4096 8月 12 2015 bindrwxr-xr-x. 2 root mysql 4096 8月 12 2015 etcdrwxr-xr-x. 2 root mysql 4096 8月 12 2015 gamesdrwxr-xr-x. 2 root mysql 4096 8月 12 2015 includedrwxr-xr-x. 2 root mysql 4096 8月 12 2015 libdrwxr-xr-x. 2 root mysql 4096 8月 12 2015 lib64drwxr-xr-x. 2 root mysql 4096 8月 12 2015 libexecdrwxr-xr-x 12 root mysql 4096 10月 15 15:21 mariadb-5.5.46-linux-x86_64lrwxrwxrwx 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 sbindrwxr-xr-x. 5 root mysql 4096 8月 22 09:16 sharedrwxr-xr-x. 2 root mysql 4096 8月 12 2015 src
6)接下来我们要初始化mysql,即生成元数据数据库
[root@localhost local]# cd mysql/[root@localhost mysql]# lsbin 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]# lsbin EXCEPTIONS-CLIENT man shareCOPYING include mysql-test sql-benchCOPYING.LESSER INSTALL-BINARY README support-files data lib scripts[root@localhost mysql]# ls support-files/ # 配置文件示例binary-configure my-large.cnf mysql-log-rotatemagic my-medium.cnf mysql.servermy-huge.cnf my-small.cnf SELinuxmy-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 SELinuxmy-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 startStarting MySQL... SUCCESS! # 启动成功[root@localhost mysql]# ss -tnl # 查看端口3306State 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/mysqlWelcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 2Server version: 5.5.46-MariaDB-log MariaDB ServerCopyright (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)]>
如上整个编译过程就已经完成了,直接运行命令即可。。。
总结过程如下:
2.httpd-2.4编译安装
3.php5编译安装
4.php-fpm编译安装