1、centos7
安装linux
2、安装nginx
#!/bin/bash
#author:zhongshusong
#time 2019-10-15
#shuming: 安装nginx-1.17.4.tar.gz
#创建软件包存放目录
mkdir -pv /usr/local/src/nginx
is_pass(){
if [ $? != 0 ];then
echo "$1 error."
exit 1
fi
}
#安装weget命令,如果有安装包可以直接上传安装包,
yum -y install wget
wget http://nginx.org/download/nginx-1.17.4.tar.gz
#安装依赖包
yum -y install gcc gcc-c++ gcc gcc-g77 zlib zlib-devel bzip2 pcre pcre-devel openssl openssl-devel make cmake
#创建用户
groupadd nginx
useradd -r -g nginx nginx
echo nginx|passwd --stdin nginx
#开始安装nginx
mkdir -pv /usr/local/nginx
tar -zxvf nginx-1.17.4.tar.gz
pushd nginx-1.17.4
./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-stream
make && make install
is_pass
chown -R nginx:nginx /usr/local/nginx
popd
#给nginx程序让普通用户可以使用1024以下的端口
setcap cap_net_bind_service=+eip /usr/local/nginx/sbin/nginx
su nginx /usr/local/nginx/sbin/nginx
echo "setsid /usr/local/nginx/sbin/nginx &"
3、安装mysql
#!/bin/bash
#author:zhongshusong
#time 2019-10-15
#shuoming:安装mysql-5.7.27
Base_Path=`pwd`
is_pass(){
if [ $? != 0 ];then
echo "$1 error."
exit 1
fi
}
#判断是否安装 了mysql
qa=$(rpm -qa | grep mysql)
if [[ -z $qa ]];then
echo "the robot isnot mysql,please install it"
else
echo "the robot have mysql,please remove it"
exit 1
fi
export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/data/tools/mysql/bin"
#安装依赖组件
yum -y install \
pcre pcre-devel \
openssl openssl-devel \
bzip2 \
bison bison-devel \
gcc gcc-c++ gcc-g77 \
autoconf automake \
zlib* fiex* libxml* \
ncurses-devel \
libmcrypt* libtool-ltdl-devel* \
make cmake
#解压依赖库
mkdir -pv /usr/local/boost
tar -zxvf boost_1_59_0.tar.gz -C /usr/local/boost
# 使用 jemalloc 优化内存管理
tar xfj jemalloc-4.2.1.tar.bz2
pushd jemalloc-4.2.1
./configure
is_pass "jemalloc configure"
make
is_pass "jemalloc make"
make install
is_pass "jemalloc make install"
ln -s /usr/local/lib/libjemalloc.so.2 /usr/lib64/libjemalloc.so.1
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig
popd
#添加用、用户组
groupadd mysql
useradd -r -g mysql mysql
echo mysql|passwd --stdin mysql
# 安装 MySQL
tar -zxvf mysql-5.7.27.tar.gz
pushd mysql-5.7.27
cmake \
-DCMAKE_INSTALL_PREFIX=/data/tools/mysql-5.7.27 \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DTRACE=0 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=/usr/local/boost \
-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'
is_pass "MySQL cmake"
make
is_pass "MySQL make"
make install
is_pass "MySQL make install"
#配置my.cnf
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /data/tools/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
#skip-networking
back_log = 300
performance_schema = on
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
group_concat_max_len = 102400
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
ln -s /data/tools/mysql-5.7.27 /data/tools/mysql
/data/tools/mysql/bin/mysqld --user=mysql --basedir=/data/tools/mysql --datadir=/data/mysql --defaults-file=/etc/my.cnf --initialize-insecure
/bin/cp $Base_Path/mysql-5.7.27/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
popd
Mem=`free -m | awk '/Mem:/{print $2}'`
sed -i "s@max_connections.*@max_connections = $((${Mem}/2))@" /etc/my.cnf
if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnnf
sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
elif [ ${Mem} -gt 3500 ]; then
sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
fi
4、安装php
#!/bin/bash
#author:zhongshusong
#time 2019-10-15
#shuming: 安装php
#安装依赖组件
yum -y install gcc gcc-c++ \
zip unzip libxml2 libxml2-devel \
curl-devel autoconf \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
zlib zlib-devel \
glibc glibc-devel \
glib2 glib2-devel \
gd-devel bzip2 bzip2-devel\
pcre pcre-devel \
epel-release \
openssl openssl-devel \
make cmake
sleep 10
yum install -y libmcrypt-devel openldap openldap-devel
cp -frp /usr/lib64/libldap* /usr/lib/
groupadd php
useradd -r -g php php
yum -y install wget
wget https://www.php.net/distributions/php-7.1.32.tar.gz
mkdir -pv /usr/local/php-7.1.32
tar -zxvf php-7.1.32.tar.gz
pushd php-7.1.32
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php \
--with-fpm-group=php \
--with-zlib \
--enable-mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli \
--with-mysql-sock=/tmp/mysql.sock \
--with-gd \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-openssl \
--with-curl \
--enable-mbstring \
--enable-static \
--enable-zip \
--enable-sockets \
--enable-xml \
--with-mcrypt \
--enable-hash \
--with-ldap \
--with-gettext \
--enable-bcmath \
--enable-intl
# vim Makefile 在/^EXTRA_LIBS行尾加入 -llber
make EXTRA_LIBS='-llber' && make install
popd
echo "/usr/local/php/sbin/php-fpm &" >>/etc/rc.local
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sed -i 's@;pid = run/php-fpm.pid@pid = run/php-fpm.pid@' /usr/local/php/etc/php-fpm.conf
sed -i 's@;error_log = log/php-fpm.log@error_log = log/php-fpm.log@' /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/src/php/php-7.1.32/php.ini* /usr/local/php/etc