重新布署开发环境,基于CentOS6.4 64位。直接贴记录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | 1. 基础配置 ================================================== 1.1 连接网络 vi /etc/sysconfig/network-scripts/ifcfg-eth0 #NM_CONTROLLED="no" ONBOOT="yes" 1.2 配置静态IP IPADDR="192.168.80.91" NETMASK="255.255.255.0" BROADCAST="192.168.80.255" GATEWAY="192.168.80.2" DNS1="8.8.8.8" DNS2="8.8.4.4" 1.3 配置网卡MAC地址 删除网卡信息 rm /etc/udev/rules.d/70-persistent-net.rules 重启 1.4 安装基础软件 yum install wget man lrzsz ntpdate 1.5 配置repe rpm -ivh epel-release-6-8.noarch.rpm 1.6 更新源 yum makecache yum update -x kernel* 1.7 更新系统 yum update 1.8 切换语言为中文 vi /etc/sysconfig/i18n LANG="zh_CN.UTF-8" source /etc/sysconfig/i18n 1.9 修改时区 tzselect cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 1.10 关闭防火墙和selinux chkconfig iptables off chkconfig ip6tables off service iptables stop service ip6tables stop 修改/etc/selinux/config文件中的SELINUX="" 为 disabled 如果不想重启系统,使用命令setenforce 0 1.11 加快启动 vi /boot/grub/grub.conf 修改 timeout = 5 为 timeout = 1 1.12 安装工具 # 压缩解压工具 yum install p7zip-plugins # 编译工具包软件 yum install gcc gcc-c++ make automake autoconf libtool zlib-devel openssl-devel 2. vmware相关配置 ================================================== 2.1 添加虚拟硬盘 #查看 cat /proc/scsi/scsi #添加 echo "scsi add-single-device 1 2 3 4" >>/proc/scsi/scsi #移除 echo "scsi remove-single-device 1 2 3 4" >> /proc/scsi/scsi #命令行解释 1 : SCSI HBA ID 2 : SCSI Channel 3 : SCSI ID 4 : LUN ID #添加到第一块SCSI HBA, Channel 0, ID 3, LUN 0: echo "scsi add-single-device 0 0 3 0" >>/proc/scsi/scsi 2.2 格式化,挂载 fdisk /dev/sdb 分区 mkfs.ext4 /dev/sdb1 格式化 mkdir /data vi /etc/fstab /dev/sdb1 /data ext4 defaults 0 0 mount -a 2.3 安装vmtools mkdir -p /mnt/cdrom mount /dev/cdrom /mnt/cdrom cp VMwareTools-9.2.0-799703.tar.gz /data/pkg/ cd /mnt/cdrom umount /mnt/cdrom tar -xzf VMwareTools-9.2.0-799703.tar.gz 开启时间同步 vmware-toolbox-cmd timesync enable 3. 编译软件 ================================================== 目录配置 #创建/data目录,所有数据放在此文件夹中 mkdir /data #存放源码包 mkdir /data/pkg #存放解压代码 mkdir /data/src 3.1 nodejs cd /data/pkg/ tar -xzf node-v0.10.10.tar.gz -C /data/src cd /data/src/node-v0.10.10 ./configure --prefix=/usr/local/node-v0.10.10 ln -s /usr/local/node-v0.10.4 /usr/local/node mkdir /usr/local/node/node_modules ln -s /usr/local/node/node_modules /usr/local/lib/ npm config set prefix /usr/local vim /etc/prefix #环境变量 export NODE_HOME=/usr/local/node export NODE_PATH=$NODE_PATH/node_modules export SOFT_PATH=$NODE_HOME/bin PATH=$PATH:$SOFT_PATH source /etc/prefix npm config set prefix /usr/local 3.2 编译nginx cd /data/pkg tar -xzf nginx-1.4.1.tar.gz -C /data/src #安装依赖 yum install pcre-devel #添加用户 groupadd www useradd -s /sbin/nologin -g www www -M cd /data/src/nginx-1.4.1 ./configure --prefix=/usr/local/nginx.basic \ --user=www \ --group=www \ --pid-path=/var/run/nginx.basic.pid \ --lock-path=/var/lock/nginx.basic.lock \ --with-http_ssl_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_realip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-mail --with-mail_ssl_module \ --http-client-body-temp-path=/var/tmp/nginx.basic/client \ --http-proxy-temp-path=/var/tmp/nginx.basic/proxy \ --http-fastcgi-temp-path=/var/tmp/nginx.basic/fastcgi \ --http-uwsgi-temp-path=/var/tmp/nginx.basic/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx.basic/scgi \ --error-log-path=/var/log/nginx.basic.error.log \ --http-log-path=/var/log/nginx.basic.access.log make && make install vi /usr/local/nginx.basic/sbin/nginxd ###启动脚本### {{{ #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 prefix="/usr/local/nginx.basic nginx="${prefix}/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="${prefix}/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac ###启动脚本结束### }}} ln -s /usr/local/nginx.basic /usr/local/nginx ln -s /usr/local/nginx/sbin/nginxd /etc/init.d/nginxd # 修改启动用户为www vim /usr/local/nginx/conf/nginx.conf user www www; # 添加开机启动 chkconfig --add nginxd 3.3 编译mysql cd /data/pkg rpm -ivh MySQL-5.6.12-1.el6.src.rpm cp /root/rpmbuild/SOURCES/mysql-5.6.12.tar.gz /data/pkg tar -xzf mysql-5.6.12.tar.gz -C /data/src/ yum install cmake bison gperf ncurses-devel readline-devel time #添加mysql用户 groupadd mysql useradd -s /sbin/nologin -g mysql mysql -M cd /data/src/mysql-5.6.12 cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql5.6 make && make install cd /opt/mysql5.6 ./scripts/mysql_install_db --user=db vi my.cnf datadir = /opt/mysql5.6/data socket = /tmp/mysql.sock pid-file = /var/run/mysql.pid ln -s /opt/mysql5.6/support-files/mysql.server /etc/rc.d/init.d/mysqld /etc/rc.d/init.d/mysqld start #修改密码 ./bin/mysqladmin -u root password '123456' #添加开机启动 chkconfig --add mysqld 3.4 编译php cd /data/pkg/ tar -xzf libiconv-1.14.tar.gz -C /data/src tar -xzf php-5.3.26.tar.gz -C /data/src yum install libxml2-devel curl-devel libjpeg-devel libpng-devel gd-devel freetype-devel zlib-devel libmcrypt-devel libtool-ltdl-devel cd /data/src/libiconv-1.14/ ./configure --prefix=/usr/local/libiconv make && make install echo "/usr/local/libiconv/lib">>/etc/ld.so.conf.d/usr_local_lib.conf ldconfig ldconfig -p | grep libiconv cd /data/src/php-5.3.26/ ./configure \ --prefix=/usr/local/php5.3 \ --with-config-file-path=/usr/local/php5.3/etc \ --with-config-file-scan-dir=/usr/local/php5.3/etc/conf.d \ --with-mysql=mysqlnd \ --with-iconv=/usr/local/libiconv \ --with-freetype-dir \ --with-jpeg-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-discard-path \ --enable-safe-mode \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --with-curlwrappers \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --with-mcrypt \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-pdo-mysql=mysqlnd \ --with-mysqli=mysqlnd make ZEND_EXTRA_LIBS='-liconv' make install #复制配置文件 ln -s /usr/local/php5.3 /usr/local/php mkdir /usr/local/php/etc/back cp php.ini* /usr/local/php/etc/back cp sapi/fpm/init.d.php-fpm /usr/local/php/bin/php-fpm #因为php5.3开始自带fpm,使用自带的管理脚本 cd /usr/local/php/etc cp back/php-fpm.conf.default ./php-fpm.conf cp back/php.ini-production ./php.ini #修改 php-fpm.conf vi /usr/local/php/etc/php-fpm.conf 修改 ;pid = run/php-fpm.pid 为 pid = run/php-fpm.pid (去掉前面的分号) 修改 user = nobody 为 user = www 修改 group = nobody 为 group = www #配置php-fpm chmod +x /usr/local/php/bin/php-fpm ln -s /usr/local/php/bin/php-fpm /etc/init.d/php-fpm #添加启服务 chkconfig --add php-fpm #启动php-fpm service php-fpm start 3.5 编译python cd /data/pkg/ tar -xjf Python-2.7.5.tgz -C /data/src cd /data/src/Python-2.7.5 ./configure --prefix=/usr/local/python27 make && make install rm /bin/python /bin/python2 -f #修改yum,引用python2.6 vi yum #!/usr/bin/python26 配置PATH vi /etc/profile export PY_PATH=/usr/local/python27 在SOFT_PATH后面加上:$PY_PATH/bin }}} cd /usr/bin rm python vi yum #!/usr/bin/python2.6 3.6 编译安装ruby tar -zxf yaml-0.1.4.tar.gz -C /data/src tar -jxf ruby-2.0.0-p195.tar.bz2 -C /data/src yaml cd /data/src/yaml-0.1.4 #pwd ./configure --prefix=/usr/local/libyaml make && make install ruby cd /data/src/ruby-2.0.0-p195 ./configure --prefix=/usr/local/ruby200 --enable-shared --disable-install-doc --with-opt-dir=/usr/local/libyaml make && make install vi /etc/profile export RUBY_PATH=/usr/local/ruby200 在SOFT_PATH后面加上:$RUBY_PATH/bin gem sources --remove http://rubygems.org/ gem sources -a http://ruby.taobao.org/ gem update --system 4. 其它配置 4.1 目录配置 #放置网站 mkdir /data/www ln -s /data/www /www #放置配置 mkdir cfg mkdir cfg/nginx #nginx配置 mkdir cfg/php53 #php5.3配置 mkdir cfg/vim #vim配置 4.2 配置samba yum install samba #存放samba共享 mkdir /share groupadd share useradd -M -s /sbin/nologin -g share share #设置share帐号的samba密码 smbpasswd -a share chown share:share /share chmod 777 /share vi /etc/samba/smb.conf # 在[global]处添加 ; 软链接 follow symlinks = yes wide links = yes unix extensions = no # 在底部添加 [Share] comment = share path = /share public = no writable = yes valid users = share ; 权限 force user = root force group = root create mask = 0664 directory mask = 0775 #链接目录 ln -s /data /share ln -s /data/www/ /share/ ln -s /data/cfg /share/ ln -s /data/local /share ln -s /data/opt /share ln -s /data/src /share ln -s /data/pkg /share 4.3 php扩展 安装 APC redis /usr/local/php/bin/phpize ./configure --enable-apc --with-php-config=/usr/local/php/bin/php-config make make install vi /usr/local/php/etc/conf.d/apc.ini extension = "apc.so" apc.enabled = 1 apc.cache_by_default = on apc.shm_segments = 1 apc.shm_size = 32M apc.ttl = 3600 apc.user_ttl = 3600 apc.num_files_hint = 0 apc.write_lock = On vi /usr/local/php/etc/conf.d/redis.ini [redis] extension = "redis.so" 4.4 nginx模板范本 # localhost server { listen 80 default; root /www/localhost; index index.html index.htm index.php index-dev.php; server_name localhost; location ~* \.php { fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/tmp/nginx_sockets_php5-fpm.sock; fastcgi_index index-dev.php; include fastcgi.conf; set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_NAME $real_script_name; #fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; #fastcgi_param PATH_INFO $fastcgi_path_info; #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } location ~* \.(jpg|png|jpeg|bmp|gif|swf|js|css) { #expires 7d; access_log off; add_header Cache-Control no-cache; } #if (!-e $request_filename) { #rewrite ([0-9]+)-qr\.png$ /qr.php?id=$1 last; #rewrite "^(.*)\.[0-9]{8,}\.(js|css|png|jpg|gif|bmp|ico)" $1.$2 last; #rewrite ^(((?!\.php).)*)$ /index-dev.php$1 break; #rewrite ^(.*)$ /index-dev.php?s=$1 break; #rewrite ^(.*)$ /index-dev.php$1 last; #} } |
Fedora17上能找到的PHP最低版本为5.4.x。因公司项目开发较早,仅能在上5.3.x上面正常运行,所以php采用编译方式安装,nginx、mysql使用源来安装。
1.安装nginx、mysql并设置自动启
2.安装基础库
3.下载源代码包
4.编译
cd
/usr/local/src
tar
-zxvf APC-3.1.9.tgz
cd
APC-3.1.9
/usr/local/php/bin/phpize
.
/configure
--
enable
-apc --
enable
-apc-mmap --with-php-config=
/usr/local/php/bin/php-config
make
make
install
参考链接:http://solf.me/compile-nginx-php-mysql-on-centos-lnmp/