CentOS 5.6(X64)下编译安装LAMP平台

环境:MySQL-5.1.51.tar.gz httpd-2.2.19.tar.bz2 php-5.3.6.tar.bz2
数据库数据目录:/data
Web目录:/html

1 安装必备的开发包
yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel \
ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \
gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \
libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel
 
#yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd  -y


2 同步系统时间:
#vim /etc/ntp.conf  //添加下面三行内容(19行下面添加)
 
server 3.cn.pool.ntp.org
server 3.asia.pool.ntp.org
server 0.asia.pool.ntp.org
 
# service ntpd stop
#ntpdate  cn.pool.ntp.org  //更新时间
#service ntpd start
chkconfig ntpd on


3 Install mysql编译安装mysql
cd mysql-5.1.51
./configure \
--prefix=/usr/local/mysql \
--exec-prefix=/usr/local/mysql \
--with-mysqld-user=mysql \
--with-charset=utf8 \
--with-extra-charsets=all \
--with-innodb \
--with-pthread \
--enable-assembler \
--enable-thread-safe-client \
--with-big-tables \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
make && make install

添加用户
groupadd –g 306 mysql
useradd –g mysql –u 306 –M –s /sbin/nologin
chown –R mysql:mysql /data

/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/data
chown -R root:mysql /usr/local/mysql/
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql/
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
编辑/etc/my.cnf,在[mysqld]加入 datadir = /data
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld 
chkconfig --level 3 mysqld on
service mysqld start

测试数据库服务器
/usr/local/mysql/bin/mysql -uroot
root用户的默认密码是空
如出现标识符
mysql>
说明MySQL数据库安装成功,并且已经启动了!
为root用户设置密码
mysql>use mysql;
mysql>set password for root@localhost=password("CentOSmysqla#");
mysql>set password for root@127.0.0.1=password("centosmysqla#");
删除空帐户,查看帐户信息
mysql>delete from mysql.user where user='';
mysql>select user,host,password from mysql.user;
允许root用户远程登录
mysql>grant all privileges on *.* to root@'%' identified by 'centosmysqla#';
mysql>flush privileges;
mysql>quit

参考选项:Mysql 优化,在[mysqld]配置参数下面添加下面几行(大概37行下面),根据服务器不同配置进行不同的设置
max_allowed_packet = 500M  //先找到这行内容,修改成500
innodb_file_per_table
log-bin-trust-function-creators=1
skip-name-resolv//禁用DNS解析
sync-binlog=1
lower_case_table_names=1
max_connections = 1500 (默认100)
log-error=/data/mysql/log/mysql.err.log  //指定错误日志位置
max_heap_table_size = 256M
join_buffer_size = 128M
thread_cache_size = 1200  //线程缓存
thread_concurrency = 4  //设置成cpu数x2,只有一个设置2
thread_stack = 256K 
query_cache_type = 1  //指定是否使用查询缓冲,可以设置为0、1、2,该变量是SESSION级的变量
query_cache_size = 512M  //查询缓冲大小
query_cache_limit = 4M  //单个查询缓冲大小。默认1M
query_cache_min_res_unit = 4k    //指定分配缓冲区空间的最小单位,缺省为4K       
tmp_table_size = 256M     
myisam_sort_buffer_size = 64M
back_log = 1024//设定缓存队列数,节省连接开销
long_query_time = 3 
open_files_limit    = 10240
interactive_timeout = 120
wait_timeout = 120
external-locking = FALSE//禁用文件系统外部锁
table_cache = 1024//高速缓存大小,4G内存设置为2048
修改配置文件里下面的参数,去掉前面的#
innodb_buffer_pool_size = 2048M (默认16M,可以为系统内存50%~70%)
innodb_additional_mem_pool_size = 256M (默认2M)
innodb_log_file_size = 512M    (默认5M,innodb_buffer_pool_size的四分之一)
innodb_log_buffer_size = 16M  //设置位每秒的数据量
innodb_max_dirty_pages_pct = 90
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 0
innodb_flush_method=O_DIRECT
innodb_open_files=4096
innodb_lock_wait_timeout = 120
innodb_file_per_table=1
 
:wq //保存退出
service mysqld restart


4 apache安装
cd ../httpd-2.2.19
cd srclib/apr
./configure --prefix=/usr/local/apr;make;make install

cd ../apr-util
./configure \
--prefix=/usr/local/apr-util \
--with-apr=/usr/local/apr/ \
--with-mysql=/usr/local/mysql;
make;make install

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/03e2273ed60efc9a10ff3f675c2503df.html