Cent OS 6.5 LAMP(Apache+php+mysql+Xcache) 编译安装
详细编译安装LAMP环境
安装OS及软件版本
OS:Cent OS 6.5
apache:httpd-2.4.10.tar.gz
php:php-5.4.31.tar.bz2
mysql:mysql-5.6.19.tar.gz
Xcache:xcache-3.1.0.tar.gz
phpmyadmin:phpMyAdmin-4.2.7-all-languages.zip
一、安装前准备
修改主机名
[[email protected] ~]#sed -i 's/HOSTNAME=localhost.localdomain/HOSTNAME=linux.lamp.com/g' /etc/sysconfig/network [[email protected] ~]#vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.0.20.203 linux linux.topgloira.com.cn
关闭selinux
[[email protected] ~]#sed -i '[email protected][email protected][email protected]' /etc/sysconfig/selinux
设置防火墙,允许httpd:80和mysqld:3306端口访问
[[email protected] ~]#vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
二、创建一个YUM仓库
1.下载64位rpmforge的rpm包
[[email protected] ~]#wget wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
2.安装DAG的PGP Key
[[email protected] ~]#rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
3.验证rpmforge的rpm文件包
[[email protected] ~]#rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm: (sha1) dsa sha1 md5 gpg OK
4.安装rpmforge的rpm文件包
[[email protected] ~]#rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
5.编辑自己服务器的YUM仓库
[[email protected] ~]#vim /etc/yum.repos.d/rpmforge.repo [rpmforge] name=CentOS-6.5_X86-64_rpmforge baseurl=http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/ baseurlextra=http://apt.sw.be/redhat/el6/en/x86_64/extras/ mirrorlist=http://apt.sw.be/redhat/el6/en/mirrors-rpmforge mirrotextras=http://apt.sw.be/redhat/el6/en/mirrors-rpmforge-extras enbaled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag gpgcheck=1
6.查看自己服务器YUM库
[[email protected] ~]# yum repolist Loaded plugins: fastestmirror, priorities, refresh-packagekit, security Loading mirror speeds from cached hostfile * rpmforge: ftp.riken.jp base | 3.7 kB 00:00 rpmforge | 1.9 kB 00:00 rpmforge/primary_db | 2.7 MB 00:02 15 packages excluded due to repository priority protections repo id repo name status base CentOS-6.5_X86-64_sohu 6,352+15 rpmforge CentOS-6.5_X86-64_rpmforge 4,718 repolist: 11,070
三、安装Apache
1.安装编译环境
[[email protected] ~]#yum grouplist [[email protected] ~]#yum groupinstall desktop platform development development tools server platform development [[email protected] ~]#yum install -y pcre-devel openssl-devel
2.安装公共管理接口APR和APR-util
[[email protected] ~]#tar xf apr-1.5.1.tar.gz [[email protected] ~]#cd apr-1.5.1 [[email protected] ~]#./configure --prefix=/usr/local/apr [[email protected] ~]#make && make install [[email protected] ~]#cd ../ [[email protected] ~]#tar xf apr-util-1.5.3.tar.gz [[email protected] ~]#cd apr-util-1.5.3 [[email protected] ~]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [[email protected] ~]#make && make install
3.编译安装Apache
[[email protected] ~]#tar xf httpd-2.4.10.tar.gz [[email protected] ~]#cd httpd-2.4.10 [[email protected] httpd]./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zilb --with-pcre --with-crypto --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpm-shared=all --with-mpm=event [[email protected] httpd]make && make install
4.编辑配置文件
[[email protected] ~]#cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24 [[email protected] ~]#vim /etc/rc.d/init.d/httpd24 修改启动配置文件 apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} [[email protected] ~]#vim /etc/profile.d/httpd export PATH=/usr/local/apcahe/bin:$PATH [[email protected] ~]#chkconfig --add httpd24 [[email protected] ~]#chkconfig httpd24 on [[email protected] ~]#service httpd24 start Starting httpd: [ OK ]
四、编译安装mysql
1.安装依赖库
[[email protected] ~]#yum install -y cmake curses-devel
2.添加mysql用户和数据库目录
[[email protected] ~]#useradd -r mysql [[email protected] ~]#mkdir -p /mysql/data
3.编译配置msyql
[[email protected] ~]#tar xf mysql-5.6.19.tar.gz [[email protected] ~]#cd mysql-5.6.19 [[email protected] mysql-5.6.19]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mysql/data
Check size of pthread_t
-- Check size of pthread_t - done
-- Using cmake version 2.6.4
-- Not building NDB
-- Performing Test HAVE_PEERCRED
-- Performing Test HAVE_PEERCRED - Success
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
-- 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: /mydata/software/mysql-5.6.19
(以上输出说明Cmake mysql 完成)
[[email protected] mysql-5.6.19]#make && make install
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
(以上输出说明编译安装成功)
4.编辑配置mysql配置文件
[[email protected] ~]#chown -R root:msyql /usr/local/mysql [[email protected] ~]#chown -R mysql:msyql /mysql/data [[email protected] ~]#cd /usr/local/mysql/support-files [[email protected] scripts]#cp my-default.cnf /etc/my.cnf [[email protected] scripts]#cp mysql.server /etc/rc.d/init.d/mysqld [[email protected] scripts]#chkconfig --add mysqld [[email protected] scripts]#chkconfig mysqld on [[email protected] scripts]#vim /etc/profile.d/mysql.sh export PATH=/usr/loocal/mysql/bin:$PATH [[email protected] scripts]#cd ../scripts/ [[email protected] scripts]#./mysql_install_db --user=mysql --datadir=/mysql/data --basedir=/usr/local/mysql
Installing MySQL system tables...2014-05-14 15:00:41 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-05-14 15:00:42 12240 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-05-14 15:00:42 12240 [Note] InnoDB: The InnoDB memory heap is disabled
2014-05-14 15:00:42 12240 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-05-14 15:00:42 12240 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-05-14 15:00:42 12240 [Note] InnoDB: Using CPU crc32 instructions
2014-05-14 15:00:42 12240 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-05-14 15:00:43 12240 [Note] InnoDB: Completed initialization of buffer pool
2014-05-14 15:00:44 12240 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-05-14 15:00:44 12240 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-05-14 15:00:44 12240 [Note] InnoDB: Database physically writes the file full: wait...
2014-05-14 15:00:46 12240 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-05-14 15:00:53 12240 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-05-14 15:01:00 12240 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-05-14 15:01:00 12240 [Warning] InnoDB: New log files created, LSN=45781
2014-05-14 15:01:00 12240 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-05-14 15:01:01 12240 [Note] InnoDB: Doublewrite buffer created
2014-05-14 15:01:01 12240 [Note] InnoDB: 128 rollback segment(s) are active.
2014-05-14 15:01:01 12240 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-05-14 15:01:01 12240 [Note] InnoDB: Foreign key constraint system tables created
2014-05-14 15:01:01 12240 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-05-14 15:01:01 12240 [Note] InnoDB: Tablespace and datafile system tables created.
2014-05-14 15:01:01 12240 [Note] InnoDB: Waiting for purge to start
2014-05-14 15:01:01 12240 [Note] InnoDB: 5.6.19 started; log sequence number 0
2014-05-14 15:01:01 12240 [Note] RSA private key file not found: /mysql/data//private_key.pem. Some authentication plugins will not work.
2014-05-14 15:01:01 12240 [Note] RSA public key file not found: /mysql/data//public_key.pem. Some authentication plugins will not work.
2014-05-14 15:01:03 12240 [Note] Binlog end
2014-05-14 15:01:03 12240 [Note] InnoDB: FTS optimize thread exiting.
2014-05-14 15:01:03 12240 [Note] InnoDB: Starting shutdown...
2014-05-14 15:01:04 12240 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2014-05-14 15:01:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-05-14 15:01:04 12274 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-05-14 15:01:04 12274 [Note] InnoDB: The InnoDB memory heap is disabled
2014-05-14 15:01:04 12274 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-05-14 15:01:04 12274 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-05-14 15:01:04 12274 [Note] InnoDB: Using CPU crc32 instructions
2014-05-14 15:01:04 12274 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-05-14 15:01:04 12274 [Note] InnoDB: Completed initialization of buffer pool
2014-05-14 15:01:05 12274 [Note] InnoDB: Highest supported file format is Barracuda.
2014-05-14 15:01:05 12274 [Note] InnoDB: 128 rollback segment(s) are active.
2014-05-14 15:01:05 12274 [Note] InnoDB: Waiting for purge to start
2014-05-14 15:01:05 12274 [Note] InnoDB: 5.6.19 started; log sequence number 1625977
2014-05-14 15:01:05 12274 [Note] RSA private key file not found: /mysql/data//private_key.pem. Some authentication plugins will not work.
2014-05-14 15:01:05 12274 [Note] RSA public key file not found: /mysql/data//public_key.pem. Some authentication plugins will not work.
2014-05-14 15:01:06 12274 [Note] Binlog end
2014-05-14 15:01:06 12274 [Note] InnoDB: FTS optimize thread exiting.
2014-05-14 15:01:06 12274 [Note] InnoDB: Starting shutdown...
2014-05-14 15:01:06 12274 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
(以上初始化数据库OK)
5.启动数据库mysql
[[email protected] ~]#service mysqld start Starting MySQL......................... [ OK ]
五、编译安装PHP
1.yum安装编译需要的库
[[email protected] ~]#yum install -y libxml2-devel bzip2-devel libmcrypt-devel mhash-devel
2.编译安装PHP
[[email protected] ~]#tar xf php-5.4.31.tar.bz2 [[email protected] ~]#cd php-5.4.31 [[email protected] php-5.4.31]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts [[email protected] php-5.4.31]#make && make install [[email protected] ~]#service httpd24 restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
六、配置LAMP环境
1.编辑httpd.conf文件
[[email protected] ~]#vim /etc/httpd24/httpd.conf DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps [[email protected] ~]#vim /usr/local/apache/htdocs/index.php <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); phpinfo(); ?> [[email protected] ~]#service httpd24 restart
(测试LAMP环境成功)
七、安装phpmyadmin管理mysql
1.解压phpmyadmin文件
[[email protected] ~]#unzip phpMyAdmin-4.2.7-all-languages.zip
2.创建虚拟主机
[[email protected] ~]#vim /etc/httpd24/httpd.conf #DocumentRoot "/usr/local/apache/htdocs" Include /etc/httpd24/extra/httpd-vhosts.conf [[email protected] ~]#mkdir -p /web/host/phpadmin [[email protected] ~]#vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost *:80> ServerName linux.topgloria.com.cn DocumentRoot "/web/host/phpadmin" <Directory "/web/host/phpadmin"> Options none AllowOverride none Require all granted </Directory> </VirtualHost> [[email protected] ~]#mv phpMyAdmin-4.2.7-all-languages /web/host/phpadmin [[email protected] ~]#service httpd24 restart
八、编译安装Xcache
1.没有安装Xcache用ab工具测试服务器性能
[[email protected] ~]# ab -c 100 -n 1000 http://10.0.20.203/index.php
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.0.20.203 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache/2.4.10
Server Hostname: 10.0.20.203
Server Port: 80
Document Path: /index.php
Document Length: 8555 bytes
Concurrency Level: 100
Time taken for tests: 18.177 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 9911000 bytes
HTML transferred: 8555000 bytes
Requests per second: 55.02 [#/sec] (mean)
Time per request: 1817.653 [ms] (mean)
Time per request: 18.177 [ms] (mean, across all concurrent requests)
Transfer rate: 532.48 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 35 77.7 0 764
Processing: 287 1747 877.7 1534 13987
Waiting: 206 1588 881.7 1358 13728
Total: 287 1782 896.5 1552 14234
Percentage of the requests served within a certain time (ms)
50% 1552
66% 1754
75% 1980
80% 2134
90% 2779
95% 3577
98% 4386
99% 4738
100% 14234 (longest request)
2.编译安装Xcache
[[email protected] ~]#tar xf xcache-3.1.0.tar.gz [[email protected] ~]#cd xcache-3.1.0 [[email protected] xcache-3.1.0]#/usr/local/php/bin/phpize [[email protected] xcache-3.1.0]#./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config [[email protected] xcache-3.1.0]#make && make install [[email protected] xcache-3.1.0]#mkdir /etc/php.d [[email protected] xcache-3.1.0]#cp xcache.ini /etc/php.d [[email protected] xcache-3.1.0]#service httpd24 restart
3.安装完成Xcache后测试结果
[[email protected] ~]# ab -c 100 -n 1000 http://10.0.20.203/index
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.0.20.203 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache/2.4.10
Server Hostname: 10.0.20.203
Server Port: 80
Document Path: /index
Document Length: 203 bytes
Concurrency Level: 100
Time taken for tests: 0.327 seconds
Complete requests: 1000
Failed requests: 0
Non-2xx responses: 1000
Total transferred: 392000 bytes
HTML transferred: 203000 bytes
Requests per second: 3057.14 [#/sec] (mean)
Time per request: 32.710 [ms] (mean)
Time per request: 0.327 [ms] (mean, across all concurrent requests)
Transfer rate: 1170.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 7 17 8.4 16 48
Processing: 7 15 4.0 14 25
Waiting: 0 10 6.0 10 24
Total: 26 32 8.1 29 57
Percentage of the requests served within a certain time (ms)
50% 29
66% 30
75% 31
80% 32
90% 34
95% 56
98% 57
99% 57
100% 57 (longest request)
以上安装LAMP和Xcache完成!
转载于:https://blog.51cto.com/wuguohua2014/1535576