安装mysql(二进制免编译安装包)
# cd /usr/local/src/ # wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz # tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz # mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql # cd /usr/local/mysql # useradd -s /sbin/nologin mysql # mkdir -p /data/mysql # chown -R mysql:mysql /data/mysql # yum install perl -y # yum install perl-Data-Dumper.x86_64 -y # yum install libaio-devel -y # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql # vim /etc/my.cnf //定义datadir=/data/mysql socket=/tmp/mysql.sock #log-error=/var/log/mariadb/mariadb.log #pid-file=/var/run/mariadb/mariadb.pid # cp support-files/mysql.server /etc/init.d/mysqld # vim /etc/init.d/mysqld //定义basedir=/usr/local/mysql datadir=/data/mysql # chkconfig --add mysqld # chkconfig mysqld on # service mysqld start
如果之前安装过php,则按如下操作
# cd php-5.6.30/ # make clean //将之前编译过的文件删除
源码包安装php
# yum install gcc -y # yum install libxml2-devel.x86_64 -y # yum install openssl-devel.x86_64 -y # yum install libcurl-devel.x86_64 -y # yum install libjpeg-turbo-devel.x86_64 -y # yum install libpng-devel.x86_64 -y # yum install freetype-devel.x86_64 -y # yum install libmcrypt-devel.x86_64 -y # ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl # make && make install
# /usr/local/php-fpm/sbin/php-fpm -m //php加载了哪些模块 # /usr/local/php-fpm/sbin/php-fpm -i //查看phpinfo()信息 # /usr/local/php-fpm/sbin/php-fpm -t //检测php语法错误
配置文件
# cp php.ini-production /usr/local/php-fpm/etc/php.ini # cd /usr/local/php-fpm/etc/ # vim php-fpm.conf [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock 或 listen=127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
启动脚本,启动php-fpm
# cd /usr/local/src/php-5.6.30/ # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod 755 /etc/init.d/php-fpm # chkconfig --add php-fpm # chkconfig php-fpm on # service php-fpm start
# useradd -s /sbin/nologin php-fpm # service php-fpm start
源码包安装nginx
# cd /usr/local/src/ # wget http://nginx.org/download/nginx-1.12.2.tar.gz # tar -zxvf nginx-1.12.2.tar.gz # cd nginx-1.12.2/ # ./configure --prefix=/usr/local/nginx # make && make install
查看语法错误
# /usr/local/nginx/sbin/nginx -t
创建启动脚本
# vim /etc/init.d/nginx #!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload() { echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart() { stop start } configtest() { $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL
# chmod 755 /etc/init.d/nginx # chkconfig --add nginx # chkconfig nginx on
修改配置文件
# cd /usr/local/nginx/conf/ # mv nginx.conf nginx.conf.bak # vim nginx.conf 1 user nobody nobody; 2 worker_processes 2; 3 error_log /usr/local/nginx/logs/nginx_error.log crit; 4 pid /usr/local/nginx/logs/nginx.pid; 5 worker_rlimit_nofile 51200; 6 events 7 { 8 use epoll; 9 worker_connections 6000; 10 } 11 http 12 { 13 include mime.types; 14 default_type application/octet-stream; 15 server_names_hash_bucket_size 3526; 16 server_names_hash_max_size 4096; 17 log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' 18 ' $host "$request_uri" $status' 19 ' "$http_referer" "$http_user_agent"'; 20 sendfile on; 21 tcp_nopush on; 22 keepalive_timeout 30; 23 client_header_timeout 3m; 24 client_body_timeout 3m; 25 send_timeout 3m; 26 connection_pool_size 256; 27 client_header_buffer_size 1k; 28 large_client_header_buffers 8 4k; 29 request_pool_size 4k; 30 output_buffers 4 32k; 31 postpone_output 1460; 32 client_max_body_size 10m; 33 client_body_buffer_size 256k; 34 client_body_temp_path /usr/local/nginx/client_body_temp; 35 proxy_temp_path /usr/local/nginx/proxy_temp; 36 fastcgi_temp_path /usr/local/nginx/fastcgi_temp; 37 fastcgi_intercept_errors on; 38 tcp_nodelay on; 39 gzip on; 40 gzip_min_length 1k; 41 gzip_buffers 4 8k; 42 gzip_comp_level 5; 43 gzip_http_version 1.1; 44 gzip_types text/plain application/x-javascript text/css text/htm 45 application/xml; 46 server 47 { 48 listen 80; 49 server_name localhost; 50 index index.html index.htm index.php; 51 root /usr/local/nginx/html; 52 location ~ \.php$ 53 { 54 include fastcgi_params; 55 fastcgi_pass unix:/tmp/php-fcgi.sock; 56 fastcgi_index index.php; 57 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; 58 } 59 } 60 }
# /usr/local/nginx/sbin/nginx -t # /etc/init.d/nginx start # ps aux|grep nginx # nginx 的平滑启动 # kill -HUP `cat /usr/local/nginx/logs/nginx.pid` # /usr/local/nginx/sbin/nginx -s reload # nginx 完美停止 # kill -QUIT `cat /usr/local/nginx/logs/nginx.pid` # nginx 快速停止 # kill -TERM `cat /usr/local/nginx/logs/nginx.pid` # kill -INT `cat /usr/local/nginx/logs/nginx.pid` # 完美停止工作进程(主要用于平滑升级) # kill -WINCH `cat /usr/local/nginx/logs/nginx.pid` # 强制停止 # pkill -9 nginx # nginx -s stop # nginx -V 查看版本和配置参数 # nginx -v 查看版本