#!/bin/bash
repo="/etc/yum.repos.d/epel-7.repo"
if [ ! -e $repo ]; then # -e 判断文件存在;参考:Shell if 条件判断文件或目录
yum install -y wget
cd /etc/yum.repos.d/
mkdir bak
mv * bak
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
# 移动两个文件到 目录
#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
#sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
# yum源没有对应版本包匹配;修改yum为centos7
yum clean all # 清除原有缓存
yum makecache # 生成新的缓存
# make cache [meɪk] [kaʃ] 制作 缓存{ka xi}
yum list # 校验yum
cd
else
echo "yum已经切换"
fi
############################################ azmariadb ######################################################
azmariadb(){
lsphp=(`find / -name "mysql.server" | sed "s/ //g"`) # shell 小括号属性是 定义数组变量 lsnginx 它的值是一条命令的执行结果
echo "
nginx 配置文件总个数为:${#lsphp[*]}
列出 nginx 配置文件" ${lsphp[*]} # [*] 星号列出所有元素, 星号改成1 为指定角标1,含义为第二个元素,默认从0开始
if [ ${#lsphp[*]} -lt 1 ] # -lt 小于; $ 为空,! 非运算; $? 判断上一条命令执行状态,0正常; 参考:linux shell $$,$! 等的特殊用法
then
echo "配置文件为空,正在安装mariadb"
yum install -y openssl openssl-devel ncurses ncurses-devel bison bison-devel jemalloc jemalloc-devel centos-release-scl devtoolset-7 gcc gcc-c++
# 安装gcc等依赖
yum remove cmake -y
ln -s /usr/local/bin/cmake /usr/bin/ # 移除旧版本cmake
cd
wget work.eisc.cn/ruanjian/rpm/lnmp/cmake-3.19.1.tar.gz
tar -xvf cmake-3.19.1.tar.gz # cmake版本要高于3.10
cd cmake-3.19.1
rm -f CMakeCache.txt # 清除历史编译
./bootstrap && gmake && gmake install
/usr/local/bin/cmake --version # 查看编译后的cmake版本
# wget https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz
# 安装libevent
cd
wget work.eisc.cn/ruanjian/rpm/lnmp/libevent-2.1.10-stable.tar.gz
tar -xvf libevent-2.1.10-stable.tar.gz
cd tar -xvf libevent-2.1.10-stable
./configure --prefix=/usr --disable-static && make && make install
yum install -y centos-release-scl devtoolset-7 # 安装C++高版本
gcc --version
scl enable devtoolset-7 bash & echo " 单个 & 符号并列执行 后面的命令"
### 使用新版本 gcc 重启失效 ###
gcc --version
echo "后面的命令没有scl 那样要求中断,所以得到了继续执行"
cd
wget http://work.eisc.cn/ruanjian/rpm/lnmp/mariadb-10.5.8.tar.gz
# https://downloads.mariadb.org/ # 官网镜像
tar -zxvf mariadb-10.5.8.tar.gz
cd mariadb-10.5.8
sed -i "s/MYSQL_VERSION_MAJOR.*/MYSQL_VERSION_MAJOR=101/g" VERSION
# 修改版本号
sed -i "s/MYSQL_VERSION_MINOR.*/MYSQL_VERSION_MINOR=42/g" VERSION
sed -i "s/MYSQL_VERSION_PATCH.*/MYSQL_VERSION_PATCH=63/g" VERSION
groupadd -g 41 mysql && useradd -c "MySQL Server" -d /srv/mysql -g mysql -s /bin/false -u 41 mysql
# 为mariadb创建用户组和用户
# sed -i "s@data/test@\${INSTALL_MYSQLTESTDIR}@g" sql/CMakeLists.txt && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DINSTALL_DOCDIR=share/doc/mariadb-10.5.8 \
-DINSTALL_DOCREADMEDIR=share/doc/mariadb-10.5.8 \
-DINSTALL_MANDIR=share/man \
-DINSTALL_MYSQLSHAREDIR=share/mysql \
-DINSTALL_MYSQLTESTDIR=share/mysql/test \
-DINSTALL_PLUGINDIR=lib/mysql/plugin \
-DINSTALL_SBINDIR=sbin \
-DINSTALL_SCRIPTDIR=bin \
-DINSTALL_SQLBENCHDIR=share/mysql/bench \
-DINSTALL_SUPPORTFILESDIR=share/mysql \
-DMYSQL_DATADIR=/srv/mysql \
-DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock \
-DWITH_EXTRA_CHARSETS=complex \
-DWITH_EMBEDDED_SERVER=ON \
-DSKIP_TESTS=ON \
-DTOKUDB_OK=0
make && make install
:<<! # 多行注释
-DCMAKE_INSTALL_PREFIX= 指向mysql安装目录
-DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)
-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)
-DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)
-DINSTALL_INFODIR=share/info 指向info文档存放目录(prefix/share/info)
prefix官方推荐设为/usr
!
install -v -dm 755 /etc/mysql # 创建文件/etc/mysql/my.cnf
cat > /etc/mysql/my.cnf << "EOF"
# Begin /etc/mysql/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /run/mysqld/mysqld.sock
# The MySQL server
[mysqld]
port = 3306
socket = /run/mysqld/mysqld.sock
datadir = /srv/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all.
#skip-networking
# 注意此处 skip 打开会导致 3306端口异常
# required unique id between 1 and 2^32 - 1
server-id = 1
# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000
# InnoDB tables are now used by default
innodb_data_home_dir = /srv/mysql
innodb_log_group_home_dir = /srv/mysql
# All the innodb_xxx values below are the default ones:
innodb_data_file_path = ibdata1:12M:autoextend
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 128M
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
# End /etc/mysql/my.cnf
EOF
:<<!
cd /usr/bin
mv mysql_install_db mysql_install_db_bak
cp /root/mysql_install_db /usr/bin
!
mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
chown -R mysql:mysql /srv/mysql # 初始化数据库以及修改所有者权限
cp /root/mariadb-10.5.8/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
# update-rc.d mysqld defaults
chkconfig --add mysqld
/etc/init.d/mysqld restart
systemctl status mysqld
'/usr/bin/mysqladmin' -u root password 'root' # 为mysql 设置密码
#mysql # 登录,默认没有密码
mysql -e "set password = password('WWWeisccn')" # 为root 用户设置密码
mysql -uroot -pWWWeisccn -e "create database eisc character set utf8 collate utf8_bin;"
# 登录数据库并且创建数据库名字为
##################################################################################################################################
#### 防火墙配置 ####
systemctl restart firewalld
firewall-cmd --permanent --add-port=3306/tcp # 开放端口 3306
firewall-cmd --permanent --add-port=9000/tcp
firewall-cmd --permanent --add-port=80/tcp
systemctl restart firewalld # 重启防火墙
firewall-cmd --zone=public --list-ports # 列出防火墙已经开放的端口
netstat -ntlp # 监听运行中的端口运用
#### 自动启动配置 ####
#说明:编译安装的运用reboot 后不会自动启动,所以需要加入开机启动配置文件 /etc/rc.d/rc.local
echo "
source /etc/profile
bash /www/server/StartLnmp.sh
" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
echo "
nginx
systemctl restart php-fpm
/etc/init.d/mysqld restart
echo ' LNMP 启动时间 ==========>> `date`' >> /root/LNMPlog.txt
" >> /www/server/StartLnmp.sh
##################################################################################################################################
else
echo "数据库已经安装"
fi
}
azmariadb