标签:groupadd archive fir charset maria stat ssl mat sqlite
LNMP架构脚本[root@yxr ~]# vim hnmp.sh
#!/bin/bash
nginxlogs=/var/log/nginx
mysqltar=mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mysqldata=/opt/data
phptar=php-7.2.8.tar.xz
configurefile=/usr/local/php7/etc/php-fpm.conf
setenforce 0
sed -ri ‘s/^(SELINUX=).*/\1disabled/g‘ /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
cd /etc/yum.repos.d/
mv * /tmp/
curl -o 163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
sed -i ‘s/\$releasever/7/g‘ /etc/yum.repos.d/163.repo
sed -i ‘s/enabled=0/enabled=1/g‘ /etc/yum.repos.d/163.repo
yum clean all
yum -y gcc gcc-c++
yum -y install wget
#配置nginx
id nginx
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin nginx
fi
yum -y install pcre-devel openssl openssl-devel gd-devel
yum -y groups mark install ‘Development Tools‘
if [ ! -d $nginxlogs ];then
mkdir -p $nginxlogs
fi
cd /usr/src/
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar xf nginx-1.12.0.tar.gz
cd nginx-1.12.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.log
make -j $(grep ‘processor‘ /proc/cpuinfo | wc -l) && make install
echo ‘export PATH=/usr/local/nginx/sbin:$PATH‘ > /etc/profile.d/nginx.sh
source /etc/profile.d/nginx.sh
/usr/local/nginx/sbin/nginx
ss -antl
mysql install
yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
id mysql
if [ $? -ne 0 ];then
groupadd -r -g 306 mysql
useradd -M -s /sbin/nologin -g 306 -u 306 mysql
fi
cd /usr/src
if [ ! -f $mysqltar ];then
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
fi
tar xf $mysqltar -C /usr/local/
ln -s /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/ /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
cd
echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
if [ ! -d $mysqldata ];then
mkdir -p $mysqldata
fi
chown -R mysql.mysql $mysqldata
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=$mysqldata &> /var/log/mysql.log
temp_password=$(grep ‘password‘ /var/log/mysql.log | awk ‘{print $NF}‘)
ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
ldconfig -v
cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = $mysqldata
socket = /tmp/mysql.sock
port = 3306
pid-file = $mysqldata/mysql.pid
user = mysql
skip-name-resolve
EOF
#config scripts of mysql
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld
# start service
service mysqld start
ss -antl
ps -ef |grep mysql
#set password
mysql -uroot -p"$temp_password" --connect-expired-password -e ‘set password=password("yaoxiaorong!");‘
install php
yum -y install epel-release
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
cd /usr/src/
if [ ! -f $phptar ];then
wget http://cn.php.net/distributions/php-7.2.8.tar.xz
fi
tar xf $phptar
cd php-7.2.8/
./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir=/usr --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-jpeg-dir --with-png-dir --with-xmlrpc --with-xsl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make -j $(cat /proc/cpuinfo |grep processor|wc -l) && make install
#install after
echo ‘export PATH=/usr/local/php7/bin:$PATH‘ > /etc/profile.d/php7.sh
source /etc/profile.d/php7.sh
php -v
#configure php-fpm
cp /usr/src/php-7.2.8/php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default $configurefile
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#update configurefile
echo "pm.max_children = 50" >> $configurefile
echo "pm.start_servers = 5" >> $configurefile
echo "pm.min_spare_servers = 2" >> $configurefile
echo "pm.max_spare_servers = 8" >> $configurefile
tail $configurefile
#svevier start
service php-fpm start
ss -antl
ps -ef | grep php
# config 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 reload
ps -ef | grep nginx
cd /usr/local/nginx/html/
cat > index.php <<EOF
<?php
phpinfo();
?>
EOF
ss -antl
标签:groupadd archive fir charset maria stat ssl mat sqlite
原文地址:http://blog.51cto.com/13835001/2165765