#!/bin/bash echo -e "33[44;37m 使用说明书 33[0m" echo -e "33[40 37m ftp的连接地址,如果是生产上的话,则开启fix_ftp 这个函数,并修改ftp的连接地址,如果是测试环境则在函数哪里将其注释即可 33[0m" echo -e "33[31m 看完这些之后,会暂停20秒钟,如果要修改ctrl +C ,进入脚本修改指定的参数,如果不需要会继续执行 33[0m" sleep 20 # 创建安装所需服务的安装目录 mkdir -p /opt/ygzy/jar/{account,org} mkdir -p /opt/ygzy/{redis,nginx,mysql} # 安装相关命令 yum -y install wget vim net-tools unzip lrzsz # 安装jdk java1.8 wget -P /opt/ygzy/ https://mirrors.huaweicloud.com/java/jdk/8u191-b12/jdk-8u191-linux-x64.tar.gz >/dev/null && echo -e "33[32m 下载完成33[0m" cd /opt/ygzy/ && tar -zxf jdk-8u191-linux-x64.tar.gz && rm -rf jdk-8u191-linux-x64.tar.gz >/dev/null && echo -e "33[32m 解压完成33[0m" # 加入配置文件,这个<<- 的意思是防止出现 下面的那个EOF 有制表符,也当作内容输入进去 cat <<- 'EOF' >> /etc/profile export JAVA_HOME=/opt/ygzy/jdk1.8.0_191 export JAVA_HOME=/opt/ygzy/jdk1.8.0_191/jre export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar EOF source /etc/profile && java -version >java.txt && cat java.txt # 开始安装相应的服务 echo -e -n "33[32m 当前可以安装的服务有:33[0m";echo -e "33[32m nginx redis mysql emqx ftp 33[0m" function add_nginx_file (){ cat <<-'EOF' >> /usr/lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/opt/ygzy/nginx/sbin/nginx [Install] WantedBy=multi-user.target EOF } function fix_reconfigure_mysql (){ mysql -uroot -p' ' <<- 'EOF' create database cloud; use mysql; set global validate_password.length=1; set global validate_password.policy=0; flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED BY 'samysql@Y6516~'; flush privileges; create user 'root'@'%' identified by 'samysql@Y6516~'; flush privileges; grant all privileges on *.* to 'root'@'%' with grant option; create user 'test'@'localhost' identified by 'test@Y6516~'; flush privileges; create user 'test'@'%' identified by 'test@Y6516~'; flush privileges; grant all privileges on *.* to 'root'@'%' with grant option; grant all privileges on *.* to 'root'@'localhost' with grant option; flush privileges; grant all privileges on cloud.* to 'test'@'localhost' with grant option; grant all privileges on cloud.* to 'test'@'%' with grant option; grant all on cloud.* to 'test'@'localhost' with grant option; grant all on cloud.* to 'test'@'%' with grant option; flush privileges; EOF } function fix_ftp (){ cat <<-'EOF' >> /etc/vsftpd/vsftpd.conf local_root=/data/ftpdata/sunsoft pasv_enable=yes pasv_min_port=30000 pasv_max_port=31000 pasv_address=192.168.1.122 EOF } while : do echo "********************" echo " menu " echo "nginx" echo "redis" echo "mysql" echo "emqx" echo "ftp" echo "qxit" read -p "Please enter the name of the software you want to install(只输入开头的一个字母即可):" server case "$server" in [nN]|[gG][iI][nN][xX] ) echo -e "33[32m*****开始安装nginx******** 33[0m" yum -y install openssl openssl-devel pcre-devel gcc-c++ zlib zlib-devel mkdir -p /opt/ygzy/jar/org/temp/ wget -P /opt/ygzy/ https://nginx.org/download/nginx-1.16.1.tar.gz cd /opt/ygzy/ && tar -zxf nginx-1.16.1.tar.gz -C /opt/ygzy/ && cd /opt/ygzy/nginx-1.16.1 && ./configure --prefix=/opt/ygzy/nginx --with-http_stub_status_module --with-http_ssl_module && make && make install echo 'export PATH=$PATH:/opt/ygzy/nginx/sbin' >> /etc/profile source /etc/profile add_nginx_file systemctl start nginx && systemctl enable nginx && echo -e "33[32m*****nginx启动完成********33[0m" read -p "press [enter] key to continue..." Key ;; [rR]|[eE][dD][iI][sS]) echo -e "33[32m*****开始安装redis********33[0m" wget -P /opt/ygzy/ http://download.redis.io/releases/redis-4.0.2.tar.gz && echo -e "33[32m*****下载完成********33[0m" cd /opt/ygzy/ && tar -zxf redis-4.0.2.tar.gz -C /opt/ygzy/ && mv /opt/ygzy/redis-4.0.2/* /opt/ygzy/redis/ && cd /opt/ygzy/redis/ && make && make install ln -s /opt/ygzy/redis/src/* /usr/bin/ echo '511' > /proc/sys/net/core/somaxconn echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf sysctl vm.overcommit_memory=1 echo never > /sys/kernel/mm/transparent_hugepage/enabled ##创建数据目录 mkdir /opt/ygzy/redis/pidfile mkdir -p /opt/ygzy/redis/logs/logfile mkdir /opt/ygzy/redis/dir ## 修改配置文件 sed -i '/bind 127.0.0.1/s/127.0.0.1/0.0.0.0/' /opt/ygzy/redis/redis.conf sed -i '/daemonize no/s/daemonize no/daemonize yes/' /opt/ygzy/redis/redis.conf sed -i '/pidfile /var/run/redis_6379.pid/s/pidfile /var/run/redis_6379.pid/pidfile /opt/ygzy/redis/pidfile/redis_6379.pid/' /opt/ygzy/redis/redis.conf sed -i '/logfile ""/s/logfile ""/logfile "/opt/ygzy/redis/logs/redis-6379.log"/' /opt/ygzy/redis/redis.conf sed -i '/dir ./s/dir ./dir /opt/ygzy/redis/dir//' /opt/ygzy/redis/redis.conf redis-server /opt/ygzy/redis/redis.conf && ps -ef | grep 0.0.0.0:6379 && echo $? && echo -e "33[32m*****redis启动完成******33[0m" read -p "press [enter] key to continue..." Key ;; [mM]|[yY][sS][qQ][lL]) echo -e "33[32m*****开始安装mysql********33[0m******" wget -P /opt/ygzy/mysql/ http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm && echo -e "33[32m*****mysql安装包下载完成*******33[0m" # 安装mysql的rpm包并安装 cd /opt/ygzy/mysql/ && yum -y install mysql80-community-release-el7-3.noarch.rpm && echo -e "33[32m*****mysqlrpm包安装完成*******33[0m" yum -y install mysql-community-server && echo -e "33[32m*****mysql服务端下载完成*******33[0m" # 跳过密码并重启 echo "skip-grant-tables">> /etc/my.cnf && systemctl start mysqld.service && echo -e "33[32m*****mysql启动成功*******33[0m" && systemctl status mysqld.service # 调用函数 fix_reconfigure_mysql # 删除最后一行的密码 sed -i '$d' /etc/my.cnf systemctl restart mysqld.service && echo -e "33[32m*****mysql启动成功*******33[0m" && systemctl status mysqld.service read -p "press [enter] key to continue..." Key ;; [eE]|[mM][qQ][xX]) # 1、 安装依赖 yum install -y yum-utils device-mapper-persistent-data lvm2 #获取当前系统的发行版本 VERSION=$(cat /etc/redhat-release) #提取当前系统的版本号 V_NUM=${VERSION:21:1} echo -e "33[35m 当前的版本号为:$V_NUM 33[0m" if [ $V_NUM=='7' ] ;then # 设置稳定存储库(centos7) yum-config-manager --add-repo https://repos.emqx.io/emqx-ce/redhat/centos/7/emqx-ce.repo else # 2、 设置稳定存储库(centos8) yum-config-manager --add-repo https://repos.emqx.io/emqx-ce/redhat/centos/8/emqx-ce.rep fi # 3、查看当亲版本有哪些 yum list emqx --showduplicates | sort -r # 4、安装指定版本 yum -y install emqx-4.3.3 # 5、启动 systemctl start emqx && systemctl enable emqx && echo -e "33[32m*****EMQX启动完成******33[0m" read -p "press [enter] key to continue..." Key ;; [fF]|[tT][pP]) # 1、安装vsftpd yum install -y vsftpd # 2、编辑ftp配置文件 # 禁止匿名用户登录 sed -i '/anonymous_enable=YES/s/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf # 允许本地用户登录 sed -i 's/^#chroot_local_user=YES/chroot_local_user=YES/' /etc/vsftpd/vsftpd.conf # 允许写入 *** 作 sed -i '$a allow_writeable_chroot=YES' /etc/vsftpd/vsftpd.conf # echo -e "33[31m 这里ftp的地址根据实际情况进行改变,此处暂时写成固定的 33[0m" # sed -i '$a pasv_address=192.168.1.122' /etc/vsftpd/vsftpd.conf # 调用函数 fix_ftp # 3、启动 systemctl start vsftpd && systemctl enable vsftpd && echo -e "33[32m*****FTP启动完成******33[0m" #4、建立ftp账户 #创建账户目录 mkdir -p /data/ftpdata/ # 创建用户组和用户 groupadd sunsoft useradd -d /data/ftpdata/sunsoft -g sunsoft sunsoft # 为ftp设置密码 echo 'zyftp@Y6516$' | passwd --stdin sunsoft # 6、设置账户权限 chown -R sunsoft:sunsoft /data/ftpdata/sunsoft chmod 777 /data/ftpdata/sunsoft/ # FTP 安装完毕 echo -e "33[32m*****FTP--successful******33[0m" read -p "press [enter] key to continue..." Key ;; [qQ]|[uU][iI][tT]) echo -e "33[32m*****欢迎使用******33[0m" exit 0 ;; *) echo -e "33[32m*****安装失败******33[0m" read -p "press [enter] key to continue..." Key ;; esac done
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)