#!/bin/bash -
#关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
#安装工具
yum -y install cmake automake autoconf libedit-devel pkgconfig python-docutils python-sphinx glib2 glib2-devel bzip2 \
gcc-g77 gcc gcc-c++ flex bison file libtool libtool-libs vim wget links make tree unzip libcap lsof net-tools \
libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel \
bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel \
libidn libidn-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel openssl
#判断此步骤是否成功执行
if [ $? -ne 0 ]; then
echo "安装工具fail"
exit
else
echo "安装工具success"
fi
#创建管理用户,配置文件属性
egrep "mysql" /etc/group >& /dev/null
if [ $? -ne 0 ];then
groupadd mysql
fi
egrep "mysql" /etc/passwd >& /dev/null
if [ $? -ne 0 ];then
useradd -g mysql mysql
fi
#判断此步骤是否成功执行
if [ $? -ne 0 ]; then
echo "创建mysql用户fail"
exit
else
echo "创建mysql用户success"
fi
#安装Cmake
cd /usr/local/src
cmake --version
if [ $? -ne 0 ]; then
rm -rf cmake-3.11.4
if [ ! -f cmake-3.11.4.tar.gz ];then
wget http://www.cmake.org/files/v3.11/cmake-3.11.4.tar.gz
fi
tar -zxvf cmake-3.11.4.tar.gz
cd cmake-3.11.4
./configure --prefix=/usr/local/cmake
gmake
make install
#判断此步骤是否成功执行
if [ $? -ne 0 ]; then
echo "安装Cmake fail"
exit
else
echo "安装Cmake success"
fi
else
echo "您的Cmake已经安装"
fi
#安装Cmake后,记得在/etc/profile中添加PATH路径,并重新载入新文件
sed -i '$a export PATH=/usr/local/cmake/bin:$PATH' /etc/profile
source /etc/profile
#安装mysql,如何需要下载对应版本,更改数字即可,比如5.7.23(5系列最新版),更改下面所有数字即可
if [ ! -d /etc/local/mysql ];then
rm -rf mysql-5.6.17
if [ ! -f mysql-5.6.17.tar.gz ];then
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
fi
tar -zxvf mysql-5.6.17.tar.gz
cd mysql-5.6.17
#指向myslq安装目录
#指向mysql数据文件目录
#指向mysql配置文件目录
#数据库引擎
#数据库引擎
#数据库引擎
#数据库引擎
#启用readline库支持
#指定mysql.sock路径
#指定TCP端口为3306
#启用本地数据导入支持
#启用额外的字符集类型(默认为all)
#指定默认的字符集为utf8
#utf8_general_ci 设定默认排序规则(utf8_general_ci快速/utf8_unicode_ci准确)
#指定mysql用户(默认为mysql)
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0
#-DWITH_BOOST=/usr/local/boost \ (在5.7.xx版本中添加wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz)
#
make
make install
#判断此步骤是否成功执行
if [ $? -ne 0 ]; then
echo "安装mysql fail"
exit
else
echo "安装mysql success"
fi
else
echo"您的mysql已经安装"
fi
#配置文件权限
cd /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/data/
#配置mysql配置文件
mv /etc/my.cnf /etc/my.cnf.back
cat > /etc/my.cnf <<end
[client]
#password = your_password
port = 3306
socket = /tmp/mysqld.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
user=mysql
datadir=/usr/local/mysql/data
default-storage-engine=MyISAM
port = 3306
socket = /tmp/mysqld.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
end
#设置开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
sed -i '$a export PATH=/usr/local/mysql/bin:$PATH' /etc/profile
source /etc/profile
/etc/init.d/mysqld start
chkconfig --add mysqld
chkconfig mysqld on
#数据库密码设置,这里设置123456
/usr/local/mysql/bin/mysqladmin -u root password 123456
#查看数据库状态
netstat -tunlp |grep mysql
#mysql删除空用户
#mysql -u root -p
#输入密码
#use mysql;
#delete user from user where user=" ";
#select user,host from user;
#mysql忘记密码,先关闭mysql服务 service mysqld stop
#mysqld_safe--user=root--skip-grant-tables
#mysql-u root
#use mysql;
#update user set password=password("new_pass")where user="root";
#flush privileges;
#mysql 远程访问(建议不要开启,数据库安全性考虑)
#GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
#接下来安装php
#创建管理用户www
egrep "www" /etc/group >& /dev/null
if [ $? -ne 0 ];then
groupadd www
fi
egrep "www" /etc/passwd >& /dev/null
if [ $? -ne 0 ];then
useradd -g www www
fi
#安装libconv,libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。
rm -rf libiconv-1.14
if [ ! -f libiconv-1.14.tar.gz ];then
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
fi
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
cd srclib/
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ..
CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
make -j $CPU_NUM
else
make
fi
make install
cd ..
#安装libmcrypt,libmcrypt是加密算法扩展库
rm -rf libmcrypt-2.5.8
if [ ! -f libmcrypt-2.5.8.tar.gz ];then
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
fi
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
if [ $CPU_NUM -gt 1 ];then
make -j $CPU_NUM
else
make
fi
make install
cd ..
#安装mhash,Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。
#mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存
rm -rf mhash-0.9.9.9
if [ ! -f mhash-0.9.9.9.tar.gz ];then
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
fi
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
if [ $CPU_NUM -gt 1 ];then
make -j $CPU_NUM
else
make
fi
make install
cd ..
#安装mcrypt,mcrypt是php里面重要的加密支持扩展库,扩展库可以实现加密解密功能,既能将明文加密,也可以密文还原。
#解决libmcrypt not found 错误
sed -i '$a /usr/local/lib' /etc/ld.so.conf
ldconfig
#export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
rm -rf mcrypt-2.6.8
if [ ! -f mcrypt-2.6.8.tar.gz ];then
wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
fi
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
#解决编译mcrypt报错:/bin/rm: cannot remove `libtoolT': No such file or directory
sed -i "s/RM='\$RM'/RM='\$RM -f'/g" ./configure
./configure
if [ $CPU_NUM -gt 1 ];then
make -j $CPU_NUM
else
make
fi
make install
#安装openssl
cd /usr/local/src
rm -rf openssl-1.0.1g
if [ ! -f openssl-1.0.1g.tar.gz ];then
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
fi
tar -zxvf openssl-1.0.1g.tar.gz
cd ..
#安装PHP
cd /usr/local/src
rm -rf php-7.2.8
if [ ! -f php-7.2.8.tar.gz ];then
wget http://cn2.php.net/distributions/php-7.2.8.tar.gz
fi
tar -zxvf php-7.2.8.tar.gz
cd php-7.2.8
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql_config \
--with-pdo-mysql=/usr/local/mysql_config \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir= \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--with-openssl=/usr/local/src/openssl-1.0.1g \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--disable-fileinfo \
--enable-maintainer-zts
if [ $CPU_NUM -gt 1 ];then
make -j $CPU_NUM
else
make
fi
make install
#配置PHP
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp ./php.ini-production /usr/local/php/etc/php.ini
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -t
/etc/init.d/php-fpm start
#安装nginx
#安装openssl
cd /usr/local/src
rm -rf openssl-1.0.1g
if [ ! -f openssl-1.0.1g.tar.gz ];then
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
fi
tar -zxvf openssl-1.0.1g.tar.gz
cd ..
#安装zlib
cd /usr/local/src
rm -rf zlib-1.2.11
if [ ! -f zlib-1.2.11.tar.gz ];then
wget http://zlib.net/zlib-1.2.11.tar.gz
fi
tar -zxvf zlib-1.2.11.tar.gz
cd ..
#安装pcre
cd /usr/local/src
rm -rf pcre-8.33
if [ ! -f pcre-8.33.tar.gz ];then
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
fi
tar -zxvf pcre-8.33.tar.gz
cd ..
#编译优化,安装nginx,
cd /usr/local/src
rm -rf nginx-1.11.10
if [ ! -f nginx-1.11.10.tar.gz ];then
wget http://nginx.org/download/nginx-1.11.10.tar.gz
fi
tar -zxvf nginx-1.11.10.tar.gz
cd nginx-1.11.10
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--without-http-cache \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/local/src/pcre-8.33 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1g
CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
make -j $CPU_NUM
else
make
fi
make install
cd ..
#x86_64的机器 在/lib64里面找.so文件
ln -s /usr/local/lib/* /lib64/
#配置文件权限
chmod 775 /usr/local/nginx/logs
chmod 755 /usr/local/nginx/sbin/nginx
chown -R www:www /usr/local/nginx/logs
#重写nginx
cd /etc/init.d
touch nginx
cat >>/etc/init.d/nginx <<end
#
# 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: /logs/nginx.pid
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "\$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog="\$(basename \$nginx)"
sysconfig="/etc/sysconfig/\$prog"
lockfile="/var/lock/subsys/nginx"
pidfile="/usr/local/nginx/logs/nginx.pid"
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f \$sysconfig ] && . "\$sysconfig"
start() {
[ -x \$nginx ] || exit 5
[ -f \$NGINX_CONF_FILE ] || exit 6
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 -p \$pidfile \$prog
retval=\$?
echo
[ \$retval -eq 0 ] && rm -f \$lockfile
return \$retval
}
restart() {
configtest_q || return 6
stop
start
}
reload() {
configtest_q || return 6
echo -n \$"Reloading \$prog: "
killproc -p \$pidfile \$prog -HUP
echo
}
configtest() {
\$nginx -t -c \$NGINX_CONF_FILE
}
configtest_q() {
\$nginx -t -q -c \$NGINX_CONF_FILE
}
rh_status() {
status \$prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
# Upgrade the binary with no downtime.
upgrade() {
local oldbin_pidfile="\${pidfile}.oldbin"
configtest_q || return 6
echo -n \$"Upgrading \$prog: "
killproc -p \$pidfile \$prog -USR2
retval=\$?
sleep 1
if [[ -f \${oldbin_pidfile} && -f \${pidfile} ]]; then
killproc -p \$oldbin_pidfile \$prog -QUIT
success \$"\$prog online upgrade"
echo
return 0
else
failure \$"\$prog online upgrade"
echo
return 1
fi
}
# Tell nginx to reopen logs
reopen_logs() {
configtest_q || return 6
echo -n \$"Reopening \$prog logs: "
killproc -p \$pidfile \$prog -USR1
retval=\$?
echo
return \$retval
}
case "\$1" in
start)
rh_status_q && exit 0
\$1
;;
stop)
rh_status_q || exit 0
\$1
;;
restart|configtest|reopen_logs)
\$1
;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
\$1
;;
status|status_q)
rh_\$1
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
*)
echo \$"Usage: \$0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
exit 2
esac
end
chmod +x ./nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
#配置各个文件
cd /usr/local/nginx/conf
mv nginx.conf nginx.conf.bak
cat >>/usr/local/nginx/conf/nginx.conf<<end
user www www;
worker_processes 1;
error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 51200;
}
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;
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 /usr/local/nginx/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 /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html\$fastcgi_script_name;
include fastcgi_params;
}
}
include vhost/*.conf;
}
end
/etc/init.d/php-fpm restart
cd /etc/init.d/
./nginx start
#防火墙放行80 3306 9000端口
systemctl start firewalld.service
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=9000/tcp --permanent
搭建LNMP环境----源码安装
最新推荐文章于 2022-07-21 17:26:20 发布