【linux服务器之最爱centos】 之 centos LAPM 安装 以前有过文档,现在收集一份

一、系统约定

软件源代码包存放位置


/usr/local/src


源码包编译安装位置(prefix)


/usr/local/Comsenz/software_name


脚本以及维护程序存放位置


/usr/local/Comsenz/sbin


MySQL数据库位置


/data/mysql(可按情况设置)


Apache网站根目录


/data/wwwroot(可按情况设置)


Apache虚拟主机日志根目录


/data/wwwroot/logs(可按情况设置)


Apache运行账户


www:www



二、系统环境初始化


1.检查系统是否正常

  1. more /var/log/messages(检查有无系统级错误信息)
  2. dmesg (检查硬件设备是否有错误信息)
  3. cat /proc/cpuinfo (检查CPU频率是否正常)
  4. top (按1检测CPU核数是否正常,内存大小是否正常)
  5. ifconfig(检查网卡设置是否正确)
  6. ping www.163.com(检查网络是否正常)
复制代码


2.关闭不需要的服务

  1. ntsysv
复制代码


以下仅列出需要启动的服务,未列出的服务一律推荐关闭:

  1. atd
  2. crond
  3. irqbalance
  4. microcode_ctl
  5. network
  6. sendmail
  7. sshd
  8. syslog
复制代码

关闭SElinux:修改/etc/selinux/config文件中的SELINUX=disabled


3.更换快速源


  1. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.old

  2. cd /etc/yum.repos.d/

  3. wget http://c.sihost.net/CentOS-Base-sohu.repo

  4. mv CentOS-Base-sohu.repo CentOS-Base.repo

  5. yum clean

  6. yum -y update

  7. lsb_release -a

  8. yum -yerasemysql

  9. yum -y erase php

  10. yum -y erase httpd
复制代码


4.使用yum程序安装所需开发包(以下为标准的RPM包名称)

  1. yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libtiff-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel fontconfig-devel zlib zlib-devel libevent-devel gcc gcc-c++flexbison bzip2-devel libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
复制代码


5.定时校正服务器时钟,定时与中国国家授时中心授时服务器同步

  1. crontab -e
复制代码

加入一行:

  1. */30 * * * * ntpdate 210.72.145.44 > /dev/null 2>&1
复制代码


6.下载程序包


请到各程序官方网站下载最新的稳定版本存放到/usr/local/src/目录


Apache
推荐稳定版2.2.21

http://archive.apache.org/dist/httpd/


PHP
推荐稳定版5.2.17

http://cn.php.net/downloads.php


Mysql
推荐稳定版5.5.18

http://www.mysql.com/downloads/mysql/


文中的配置文件和脚本限于篇幅,请到以下地址下载(仅支持linux下使用wget下载)


Apache控制脚本

http://c.sihost.net/jb/httpd


Apache配置文件

http://c.sihost.net/jb/httpd.conf


以上列出的程序最新推荐版下载列表

http://c.sihost.net/lamp_tools.list


/usr/local/src目录下执行

wgethttp://c.sihost.net/lamp_tools.list


wget -i lamp_tools.list


7.创建web运行用户


groupadd www

useradd -g www www

mkdir -p/data/wwwroot

chmod +w/data/wwwroot

chown www:www/data/wwwroot-R


8.重新启动


  1. init 6
复制代码


三、编译安装环境


1.安装MySQL


  1. cd /usr/local/src

  2. tar zxvf cmake-2.8.5.tar.gz

  3. cd cmake-2.8.5/

  4. ./configure

  5. gmake &&gmake install

  6. groupadd mysql
  7. useradd -g mysql mysql

  8. mkdir -p /data/mysql
  9. chown -R mysql:mysql /data/mysql

  10. cd /usr/local/src

  11. tar zxvf mysql-5.5.18.tar.gz

  12. cd mysql-5.5.18

  13. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Comsenz/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/usr/local/Comsenz/etc/ -DWITH_BLACKHOLE_STORAGE_ENGINE=1

  14. make && make install

  15. cd /usr/local/Comsenz/mysql

  16. ./scripts/mysql_install_db --user=mysql

  17. cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

  18. chmod 755 /etc/rc.d/init.d/mysqld

  19. chkconfig --add mysqld

  20. chkconfig --level 3 mysqld on
复制代码

编辑/etc/rc.d/init.d/mysqld

找到


  1. basedir=
  2. datadir=
复制代码
改成
  1. basedir=/usr/local/Comsenz/mysql
  2. datadir=/data/mysql
复制代码
然后
  1. mkdir -p /usr/local/Comsenz/etc

  2. cp ./support-files/my-huge.cnf /usr/local/Comsenz/etc/my.cnf
复制代码
编辑/usr/local/Comsenz/etc/my.cnf

[mysqld]段增加

  1. datadir = /data/mysql
  2. wait-timeout = 10
  3. max_connections = 512
  4. max_connect_errors = 10000000
  5. local-infile=0
复制代码

[mysqld]段修改

  1. max_allowed_packet = 16M
  2. thread_cache_size = CPU个数*2
复制代码

log-bin注释


  1. mv /usr/local/Comsenz/mysql/data/* /data/mysql

  2. service mysqld start

  3. bin/mysqladmin -u root password 'admin999'
复制代码

其中admin999是要设置的root密码


2.编译安装Apache


  1. cd /usr/local/src/

  2. tar zxvf httpd-2.2.21.tar.gz

  3. cd httpd-2.2.21

  4. ./configure --prefix=/usr/local/Comsenz/apache --enable-module=rewrite--disable-access --disable-auth --disable-charset-lite --disable-include --disable-log-config --disable-env --disable-setenvif --disable-mime--disable-status --disable-autoindex --disable-asis --disable-cgid --disable-cgi --disable-negotiation --disable-dir --disable-actions --disable-userdir --disable-alias--enable-so --enable-mods-shared='access auth auth_anon auth_dbm auth_digest dav dav_fs actions alias asis autoindex cache cern_meta cgi charset_lite deflate dir disk_cache env expires file_cache headers include info log_config logio mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias'

  5. make && make install

  6. cd /usr/local/src/

  7. mv /usr/local/Comsenz/apache/conf/httpd.conf /usr/local/Comsenz/apache/conf/httpd.conf.old

  8. cp -f /usr/local/src/httpd.conf /usr/local/Comsenz/apache/conf/httpd.conf

  9. cp -f /usr/local/src/httpd /etc/init.d/httpd

  10. chmod 755 /etc/init.d/httpd

  11. chkconfig --add httpd

  12. chkconfig httpd on
复制代码


3.编译安装PHP所需的支持库


  1. tar zxvf libiconv-1.14.tar.gz

  2. cd libiconv-1.14/

  3. ./configure --prefix=/usr/local

  4. make && make install

  5. cd /usr/local/src/

  6. tar zxvf libmcrypt-2.5.8.tar.gz

  7. cd libmcrypt-2.5.8

  8. ./configure

  9. make && make install

  10. /sbin/ldconfig

  11. cd libltdl/

  12. ./configure --enable-ltdl-install

  13. make && make install

  14. cd /usr/local/src/

  15. tar zxvf mhash-0.9.9.9.tar.gz

  16. cd mhash-0.9.9.9/

  17. ./configure

  18. make && make install

  19. cd /usr/local/src/

  20. 64bit系统执行下面的:
  21. ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
  22. ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
  23. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
  24. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
  25. ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
  26. ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
  27. ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
  28. ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
  29. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
  30. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  31. ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/libiconv.so.2

  32. 32bit系统执行下面的:
  33. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  34. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  35. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  36. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  37. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  38. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  39. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  40. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  41. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  42. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  43. ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2

  44. tar zxvf mcrypt-2.6.8.tar.gz

  45. cd mcrypt-2.6.8

  46. /sbin/ldconfig

  47. ./configure

  48. make && make install
复制代码


4.编译安装PHP


  1. cd /usr/local/src

  2. tar zxvf php-5.2.17.tar.gz

  3. cd php-5.2.17

  4. ./configure --prefix=/usr/local/Comsenz/php5--with-config-file-path=/usr/local/Comsenz/etc --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-magic-quotes --with-mysql=/usr/local/Comsenz/mysql --with-pear --enable-sockets --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --enable-sysvsem --enable-exif --enable-sysvshm --with-libxml-dir=/usr --with-apxs2=/usr/local/Comsenz/apache/bin/apxs --with-iconv=/usr/local/libiconv --with-iconv-dir=/usr/local --with-xmlrpc --enable-xml --enable-shmop --enable-zip --with-mhash --with-mcrypt --enable-discard-path --enable-bcmath --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --with-openssl

  5. make &&make install

  6. ./libtool --finish /usr/local/src/php-5.2.17/libs

  7. cp php.ini-dist /usr/local/Comsenz/etc/php.ini

  8. echo 'ulimit -SHn 65535' >> /etc/rc.local
复制代码


5.安装PHP扩展模块需要此功能的Discuz! X用户选装)

APC


  1. cd /usr/local/src

  2. tar zxvf APC-3.1.9.tgz
  3. cd APC-3.1.9
  4. /usr/local/Comsenz/php5/bin/phpize
  5. ./configure --enable-apc --enable-mmap --enable-apc-spinlocks --disable-apc-pthreadmutex --with-php-config=/usr/local/Comsenz/php5/bin/php-config
  6. make &&make install
复制代码

编辑/usr/local/Comsenz/etc/php.ini

查找


  1. extension_dir =
复制代码
在下面一行添加

  1. extension_dir = "/usr/local/Comsenz/php5/lib/php/extensions/no-debug-non-zts-20060613/"
  2. extension="apc.so"
  3. apc.enabled = 1
  4. apc.shm_size = 64M
  5. apc.stat = 1
复制代码
保存

6.查看确认L.A.M.P环境信息、提升PHP安全性


保存以下内容为info.php/home/www/wwwroot/,检查phpinfo中的各项信息是否正确。


<?

phpinfo();

?>


确认PHP能够正常工作后,编辑/usr/local/Comsenz/etc/php.ini进行设置提升PHP安全性。

查找


  1. disable_functions =
复制代码

修改成


  1. disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen
复制代码

然后

  1. service httpd restart
复制代码



严格按照如上步骤操作,菜鸟也不会有太大问题,如有不解,跟帖提问,随时欢迎高手指正,把此教程做成菜鸟能看懂,复制粘贴搞出来的环境能正常运行的好教程。

你可能感兴趣的:(centos)