Linux一键安装部署环境

2023-05-16

安装Java环境

yum install -y java-1.8.0-openjdk-devel.x86_64

安装mariadb

1. vi install-mariadb.sh  创建文件并打开

image

2. 输入 i 进入编辑(复制一下内容粘贴)

#!/bin/bash
MARIADB_DIR=/usr/local/mariadb
DATA_DIR=/data/mariadb
MARIADB_VER=10.3.27
ROOT_PASSWORD=123456
# 创建数据存放目录
mkdir -p ${DATA_DIR}
# 创建mysql的用户做为mariadb的运行用户
useradd -r mysql -s /sbin/nologin
# 下载
cd /usr/local/src
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-${MARIADB_VER}/bintar-linux-systemd-x86_64/mariadb-${MARIADB_VER}-linux-systemd-x86_64.tar.gz
tar -zxvf mariadb-${MARIADB_VER}-linux-systemd-x86_64.tar.gz 
mv mariadb-${MARIADB_VER}-linux-systemd-x86_64 ${MARIADB_DIR}
ln -s ${MARIADB_DIR} /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql/
# 授权
chown -R mysql.mysql ${DATA_DIR}
# my.conf configuration
cat > /etc/my.cnf <<EOF
[mysqld]
port            = 3306
character-set-server = utf8
collation-server = utf8_general_ci
datadir = ${DATA_DIR}
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
EOF
cd ${MARIADB_DIR}
./scripts/mysql_install_db --datadir=${DATA_DIR} --user=mysql
# 设置开机自启动
cp ${MARIADB_DIR}/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
${MARIADB_DIR}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${ROOT_PASSWORD}\" with grant option;"
${MARIADB_DIR}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${ROOT_PASSWORD}\" with grant option;"
${MARIADB_DIR}/bin/mysql -uroot -p${ROOT_PASSWORD} -e "delete from mysql.user where Password='';"
${MARIADB_DIR}/bin/mysql -uroot -p${ROOT_PASSWORD} -e "delete from mysql.db where User='';"
${MARIADB_DIR}/bin/mysql -uroot -p${ROOT_PASSWORD} -e "delete from mysql.proxies_priv where Host!='localhost';"
${MARIADB_DIR}/bin/mysql -uroot -p${ROOT_PASSWORD} -e "drop database test;"
# 添加环境变量
echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile.d/mysql.sh
# 刷新环境变量
. /etc/profile.d/mysql.sh

image

3. 按 Esc 输入 :wq! 
4. 授权文件为可执行命令: chmod 777 install-mariadb.sh 
5. 安装wget命令: yum -y install wget
6. 执行安装mariadb命令 ./install-mariadb.sh

安装 Nginx install-nginx.sh

#!/bin/bash
# 版本
NGINX_VERSION=1.16.0
# 安装目录
NGINX_DIR=/usr/local/nginx
# 安装依赖
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel wget
# 下载
cd /usr/local/src
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
# 解压
tar -zxvf nginx-${NGINX_VERSION}.tar.gz
# 安装
cd nginx-1.16.0
./configure --prefix=${NGINX_DIR} --with-http_stub_status_module --with-http_ssl_module
make install
# 设置为系统服务
cat > /etc/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx service
After=network.target 
[Service] 
Type=forking 
ExecStart=${NGINX_DIR}/sbin/nginx
ExecReload=${NGINX_DIR}/sbin/nginx -s reload
ExecStop=${NGINX_DIR}/sbin/nginx -s quit
PrivateTmp=true
[Install] 
WantedBy=multi-user.target
EOF
# 刷新
systemctl daemon-reload
# 设置开机自启
systemctl enable nginx
# 启动
systemctl start nginx

image

安装redis install-redis.sh

#!/bin/bash
# 版本
REDIS_VERSION=5.0.9
# 安装目录
REDIS_DIR=/usr/local/redis
# 安装依赖
yum install -y gcc 
# 下载
cd /usr/local/src
wget http://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gz
# 解压
tar -zxvf redis-${REDIS_VERSION}.tar.gz
# 安装
cd redis-${REDIS_VERSION}
make install PREFIX=${REDIS_DIR}
# 复制配置文件
cp /usr/local/src/redis-${REDIS_VERSION}/redis.conf ${REDIS_DIR}/bin/
# 配置后台启动
sed -i 's/daemonize no/daemonize yes/g' ${REDIS_DIR}/bin/redis.conf
# 设置为系统服务
cat > /etc/systemd/system/redis.service <<EOF
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=${REDIS_DIR}/bin/redis-server ${REDIS_DIR}/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
# 刷新
systemctl daemon-reload
# 设置开机自启
systemctl enable redis
# 启动
systemctl start redis
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux一键安装部署环境 的相关文章

随机推荐