本文共 5621 字,大约阅读时间需要 18 分钟。
!/bin/bash#关闭防火墙与SELINUXsystemctl stop firewalldsystemctl disable firewalldsed -i '/^SELINUX/ s/enforcing/disabled/g' /etc/sysconfig/selinuxsetenforce 0#配置yum源cd /etc/yum.repos.d/curl -o 163.repo http://mirrors.163.com/.help/CentOS7-Base-163.reposed -i 's/\$releasever/7/g' /etc/yum.repos.d/163.reposed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/163.repoyum -y install epel-releaseyum -y install wgetyum -y install gcc gcc-c++#安装依赖环境yum -y install pcre-devel openssl openssl-devel gd-develyum -y groups install 'Development Tools'#安装nginxid nginxif [ $? -ne 0 ];thengroupadd -r nginxuseradd -r -M -s /sbin/nologin -g nginx nginxfi#创建日志存放目录if [ -d /var/log/ninx ];thenmkdir -p /var/log/nginxfichown -R nginx.nginx /var/log/nginx#下载nginxcd /usr/src#wget wget http://nginx.org/download/nginx-1.14.0.tar.gztar xf nginx-1.14.0.tar.gzcd nginx-1.14.0./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-debug \--with-http_ssl_module \--with-http_realip_module \--with-http_image_filter_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_stub_status_module \--http-log-path=/var/log/nginx/access.log \--error-log-path=/var/log/nginx/error.logmake -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install#配置变量环境echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh. /etc/profile.d/nginx.sh#启动nginxnginxss -antl#安装mysql#创建用户和组id mysqlif [ $? -ne 0 ];thengroupadd -r -g 306 mysqluseradd -M -s /sbin/nologin -g 306 -u 306 mysqlfi#下载二进制格式的mysql软件包cd /usr/src#wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz#解压tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/cd /usr/local/ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysqlchown -R mysql.mysql /usr/local/mysql#添加环境变量echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh. /etc/profile.d/mysql.shecho $PATH#建立数据存放目录cd /usr/local/mysqlif [ -d "/opt/data" ];thenmkdir /opt/datafichown -R mysql.mysql /opt/data/#初始化数据库/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/ &> /var/log/mysql.logtemp_password=$(grep 'password' /var/log/mysql.log | awk '{print $NF}')ln -sv /usr/local/mysql/include/ /usr/local/include/mysqlecho '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.confldconfig -v#生成配置文件cat > /etc/my.cnf </etc/profile.d/php7.shsource /etc/profile.d/php7.shphp -v#配置php-fpmcd /usr/srccd php-7.2.8cp php.ini-production /etc/php.inicp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/rc.d/init.d/php-fpmcp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.confcp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf#编辑php-fpm的配置文件cat >> /usr/local/php7/etc/php-fpm.conf << 'EOF'pm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 2pm.max_spare_servers = 8EOF#启动php-fpmservice php-fpm startss -antlps -ef | grep php#配置nginx\cp /usr/local/nginx/conf/nginx.conf{,-bak}cat > /usr/local/nginx/conf/nginx.conf <<'EOF'user nginx;worker_processes 4;error_log logs/error.log;pid logs/nginx.pid;events { worker_connections 1024;}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; sendfile on; keepalive_timeout 65; #gzip on;server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.php index.html index.htm; }#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 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}EOF/usr/local/nginx/sbin/nginx -s reloadps -ef | grep nginxcd /usr/local/nginx/html/touch test.phpcat > test.php << EOF EOFss -antl
转载于:https://blog.51cto.com/13910274/2166108