程序安装的方式有两种:yum安装和源码包安装
为什么要源码安装?
1.平台通用性。yum安装是用的二进制rpm包来安装,然而并不是所有linux平台都接受rpm包。如果有多台不同系统服务器,为了版本号统一,采用源码安装
2.yum安装的应用,安装位置混乱,不方便运维统一管理。源码安装通过--prefix参数指定安装目录,实现应用的统一管理。
3.yum安装默认安装rpm里的所有module(安装后可以设置不加载),源码包安装可自由指定所需要的module。
lamp的软件包:
https://pan.baidu.com/s/1B_iZhaJ4XTR8kcMvHMVotg
apache:2.4.16
mysql:5.6.26
php:5.6.13
1.安装编译环境
如果系统是最小化安装需要先安装开发工具包
yum groupinstall "Development Tools" "Development Libraries" -y
安装编译的依赖环境
yum install -y gcc gcc-c++ openssl-devel
2.上传lamp软件包
[root@slavedb sourceapp]# ls
apr-1.5.2.tar.gz apr-util-1.5.4.tar.bz2 httpd-2.4.16.tar.bz2 mysql-5.6.26.tar.gz pcre-8.37.tar.bz2 php-5.6.13.tar.bz2
3.开始安装
3.1 apache2.4安装
编译参数写错了,或编译失败,用make clean清除,在重新编译
apache依赖安装
[root@slavedb sourceapp]# tar xf apr-1.5.2.tar.gz -C /usr/local/src/
[root@slavedb ~]# cd /usr/local/src/apr-1.5.2/
[root@slavedb apr-1.5.2]# ./configure --prefix=/usr/local/apr && make && make install
[root@slavedb sourceapp]# tar xf apr-util-1.5.4.tar.bz2 -C /usr/local/src/
[root@slavedb apr-util-1.5.4]# cd /usr/local/src/apr-util-1.5.4/ && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make -j 4 && make install #- j n n为cpu核心数
[root@slavedb sourceapp]# tar xf pcre-8.37.tar.bz2 -C /usr/local/src/
[root@slavedb pcre-8.37]# cd pcre-8.37/ && ./configure --prefix=/usr/local/pcre && make -j 4 && make install
apache2.4安装
[root@slavedb sourceapp]# tar xf httpd-2.4.16.tar.bz2 -C /usr/local/src/
[root@slavedb src]# cd httpd-2.4.16/
[root@slavedb httpd-2.4.16]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-ssl --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event && make -j 4 && make install
[root@slavedb ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@slavedb ~]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/httpd/bin:$PATH
[root@slavedb ~]# source /etc/profile.d/httpd.sh
[root@slavedb ~]# id apache
uid=48(apache) gid=48(apache) 组=48(apache)
[root@slavedb ~]# userdel -r apache
userdel: apache 邮件池 (/var/spool/mail/apache) 未找到
userdel:未找到 apache 的主目录“/usr/share/httpd”
[root@slavedb ~]# useradd apache -M -s /sbin/nologin
[root@slavedb local]# chown -R apache.apache /usr/local/httpd
[root@slavedb sourceapp]# head /etc/init.d/httpd
#!/bin/sh
# chkconfig:2345 64 36 #添加
# description:Apache2.4.16 start script #添加
[root@slavedb ~]# httpd -k start
AH00557: httpd: apr_sockaddr_info_get() failed for slavedb
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
[root@slavedb ~]# netstat -tnlp | grep httpd
tcp6 0 0 :::80 :::* LISTEN 39601/httpd
[root@slavedb usr]# vim /usr/local/httpd/conf/httpd.conf
User apache
Group apache
ServerName 10.10.10.21:80
[root@slavedb ~]# httpd -k restart
[root@slavedb usr]# ps aux |grep httpd
root 39601 0.0 0.1 76776 2812 ? Ss 10:58 0:00 httpd -k start
apache 39843 0.0 0.1 367824 4216 ? Sl 11:06 0:00 httpd -k start
apache 39844 0.0 0.1 367824 4216 ? Sl 11:06 0:00 httpd -k start
apache 39845 0.0 0.1 367824 4220 ? Sl 11:06 0:00 httpd -k start
root 39930 0.0 0.0 112660 992 pts/1 R+ 11:06 0:00 grep --color=auto httpd
运行用户变为apache了
3.2安装mysql
mysql5.6.16版本以前依然是./configure make make install 编译安装
5.16版本用cmake编译
安装cmake和依赖
[root@slavedb ~]# yum install cmake ncurses-devel -y
[root@slavedb sourceapp]# tar xf mysql-5.6.26.tar.gz -C /usr/local/src/
[root@slavedb mysql-5.6.26]# 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_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_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@slavedb mysql-5.6.26]# make -j 4 && make install
等5分钟左右
[root@slavedb local]# chown mysql.mysql -R mysql
[root@slavedb mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@slavedb mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@slavedb mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@slavedb mysql]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql #出现2个ok就初始化data成功了
[root@slavedb mysql]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@slavedb mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
mysql> grant all privileges on *.* to root@localhost identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3.3安装php
安装依赖
[root@slavedb local]# yum install -y libxml2-devel
[root@slavedb sourceapp]# tar xf php-5.6.13.tar.bz2 -C /usr/local/src/
[root@slavedb src]# cd php-5.6.13/
[root@slavedb php-5.6.13]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php && make && make install
[root@slavedb php-5.6.13]# cp php.ini-production /usr/local/php/php.ini;
检查编译结果
[root@slavedb php-5.6.13]# ls /usr/local/httpd/modules/httpd.exp
/usr/local/httpd/modules/httpd.exp
[root@slavedb php-5.6.13]# ls /usr/local/httpd/modules/libphp5.so
/usr/local/httpd/modules/libphp5.so
[root@slavedb php-5.6.13]# vim /usr/local/httpd/conf/httpd.conf
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
源码安装的httpd的app家目录为/usr/local/httpd/htdocs/
创建php测试页
[root@slavedb php-5.6.13]# cat /usr/local/httpd/htdocs/index.php
[root@slavedb sourceapp]# httpd -k restart
访问 10.10.10.21/index.php 成功