1 创建组和用户:
groupadd mysql useradd -g mysql mysql -s /sbin/nologin
2 创建数据库安装目录:
mkdir -p /usr/local/mysql
3 创建数据库配置文件存放目录:
mkdir -p /etc/mysql
4 创建数据库存放目录
mkdir -p /data/mysql chown -R mysql:mysql /data/mysql
5 数据库安装
#安装cmake,cmake用于安装MySQL,可以使用yum -y install cmake,或从源文件安装如下 mkdir -p /usr/local/cmake tar zxpvf cmake-2.8.9.tar.gz cd cmake-2.8.9 ./configure --prefix=/usr/local/cmake make make install
#在文件/etc/profile尾部加入下列行 #export PATH=$PATH:/usr/local/cmake/bin echo "export PATH=$PATH:/usr/local/cmake/bin" >> /etc/profile source /etc/profile # 或者 . /etc/profile
tar zxpvf mysql-5.5.27.tar.gz cd mysql-5.5.27 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 make make install
6 配置数据库
cd /usr/local/mysql cp ./support-files/my-huge.cnf /etc/mysql/my.cnf #修改/etc/mysql/my.cnf文件,将下列行添加到[mysqld]部分 vi /etc/mysql/my.cnf datadir = /data/mysql
7 生成mysql系统数据库
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
8 把MySQL加入系统开机启动
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig mysqld on #启动mysql service mysqld start
9 把MySQL可执行文件加入系统变量,把MySQL库文件连接到系统默认位置
#在文件/etc/profile尾部加入下列行 #export PATH=$PATH:/usr/local/mysql/bin echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile source /etc/profile #或 . /etc/profie
可采用下列两种方式之一把MySQL库连接到系统默认位置(安装php时会用到libmysqlclient库):
(1)
ln -s /usr/local/mysql/lib/libmysqlclient.so.* /usr/lib
(2)
vi /etc/ld.so.conf #把下面一行加入/etc/ld.so.conf文件尾部 /usr/local/mysql/lib ldconfig # 使用ldconfig -p查看设置结果 ldconfig -p | less
10 创建具有root权限的用户(user)和密码(123456789)
mysql -u root -p -S /tmp/mysql.sock # (提示输入密码是直接回车) GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY '123456789'; GRANT ALL PRIVILEGES ON *.* TO 'user'@'127.0.0.1' IDENTIFIED BY '123456789';
11 为root用户设置初始密码
mysqladmin -u root password 'new password'
12 删除空密码账号
#以根用户登陆 mysql -u root -p USE mysql SELECT host, user, password FROM user; DELETE FROM user WHERE password=""; FLUSH privileges;
1 安装PHP依赖库
(1)安装 libiconv:
tar zxpvf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local make make install
(2)安装 libmcrypt
tar zxpvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make make install ldconfig cd libltdl ./configure --enable-ltdl-install make make install
(3)安装 mhash
tar zxpvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure make make install ln -s /usr/local/lib/libmcrypt.* /usr/lib ln -s /usr/local/lib/libmhash.* /usr/lib
(4)安装 mcrypt
tar zxpvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 ldconfig ./configure make make install
2 安装PHP
mkdir -p /usr/local/php tar zxpvf php-5.4.6.tar.gz cd php-5.4.6 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --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 --enable-ftp --with-openssl -with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session make ZEND_EXTRA_LIBS='-liconv' make install cp php.ini-production /usr/local/php/etc/php.ini #将php可执行文件路径添加到系统路径 echo "export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile source /etc/profile
3 安装PHP扩展模块
(1)安装 memcached
#安装memcached依赖包libevent tar zxpvf libevent-2.0.19-stable.tar.gz cd libevent-2.0.19-stable ./configure --prefix=/usr/local/libevent make make install #安装 memcached tar zxpvf memcached-1.4.14.tar.gz cd memcached-1.4.14 ./configure --with-libevent=/usr/local/libevent make make install #安装PHP的memcache扩展 tar zxpvf memcache-3.0.6.tgz cd memcache-3.0.6 phpize ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir make make install
(2)安装 eaccelerator
tar zxpvf eaccelerator-eaccelerator-42067ac.tar.gz cd eaccelerator-eaccelerator phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config make make install
(3)安装 PDO_MYSQL
tar zxpvf PDO_MYSQL-1.0.2.tgz cd PDO_MYSQL-1.0.2 phpize ln -s /usr/local/mysql/include/* /usr/local/include/ ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql make make install
(4)安装 ImageMagick
tar zxpvf ImageMagick-6.7.9.0.tar.gz cd ImageMagick-6.7.9.0 ./configure make make install
(5)安装 imagick
tar zxpvf imagick-3.1.0RC2.tgz cd imagick-3.1.0RC2 phpize export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig # MagickWand.pc所在库目录,可以在/usr目录下使用find -name "MagickWand.pc"查找该路径 ./configure --with-php-config=/usr/local/php/bin/php-config make make install
4 配置PHP扩展模块
(1)修改php.ini文件
当前所有扩展模块都存放在目录:/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525
#修改extension_dir = "./" vi /usr/local/php/etc/php.ini extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/" #添加下列行 extension = "memcache.so" extension = "pdo_mysql.so" extension = "imagick.so" #修改output_buffering output_buffering = on
(2)配置 eAccelerator 加速PHP
mkdir -p /usr/local/eaccelerator_cache vi /usr/local/php/etc/php.ini #将下列几行加入文件php.ini尾部 [eaccelerator] zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so" eaccelerator.shm_size="64" eaccelerator.cache_dir="/usr/local/eaccelerator_cache" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="3600" eaccelerator.shm_prune_period="3600" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9"
(3)配置php-fpm
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf vi /usr/local/php/etc/php-fpm.conf
修改php-fpm配置参数:[global] [www]
[global] pid = run/php-fpm.pid [www] user = www group = www pm.max_children = 128 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 5000 #设置php-fpm开机自启动 #回到php源文件目录 cd /usr/local/src/php-5.4.6 cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm chmod +x /etc/rc.d/init.d/php-fpm chkconfig php-fpm on #为Nginx创建用户组和用户名 groupadd www useradd -g www www -s /sbin/nologin service php-fpm start
1 安装依赖库
mkdir /usr/local/pcre tar zxpvf pcre-8.31.tar.gz cd pcre-8.31 ./configure --prefix=/usr/local/pcre make make install
2 安装Nignx
tar zxpvf nginx-1.2.3.tar.gz cd nginx-1.2.3 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.31 make make install
--with-pcre指向安装源文件目录
echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile source /etc/profile #启动nginx nginx
3 设置nginx开机启动
# 创建nginx配置文件 vi /etc/rc.d/init.d/nginx #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.1.2.3 version # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library . /etc/rc.d/init.d/functions # Source networking configuration . /etc/sysconfig/network # Check that networking is up [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ]; then echo "nginx already running..." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog { start | stop | restart | reload | status | help }" exit 1 esac exit $RETVAL #保存文件 wq
chmod +x /etc/rc.d/init.d/nginx chkconfig nginx on service nginx restart
4 fastcgi配置文件
#确认fastcgi配置文件存在 vi /usr/local/nginx/conf/fastcgi_params #文件内容如下 fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;
5 配置nginx, /usr/local/nginx/conf/nginx.conf文件内容如下
#user nobody; worker_processes 8; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
service nginx restart