其他一键安装脚本

This commit is contained in:
2022-03-13 14:56:33 +08:00
parent 1bee668c48
commit 18e447c880
20 changed files with 787 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/.DS_Store

View File

@@ -0,0 +1,58 @@
# Nginx 安装 ssl 证书
1、以腾讯云为例去 SSL 证书管理控制台https://console.cloud.tencent.com/ssl 下载并解压缩证书文件包到本地目录。
2.、解压缩后,可获得相关类型的证书文件。其中包含 Nginx 文件夹和 CSR 文件。
```
文件夹名称Nginx
文件夹内容:
1_www.domain.com_bundle.crt 证书文件
2_www.domain.com.key 私钥文件
CSR 文件内容: www.domain.com.csr 文件
```
说明CSR 文件是申请证书时由您上传或系统在线生成的,提供给 CA 机构。安装时可忽略该文件。
3、将已获取到的 1_www.domain.com_bundle.crt 证书文件和 2_www.domain.com.key 私钥文件从本地拷贝到服务器的某个目录下。
4、Nginx 配置:
```
server {
listen 443;
server_name phpedu.club www.phpedu.club;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# 启用 SSL 功能
ssl on;
# 证书文件名称
ssl_certificate /etc/nginx/conf.d/ssl/1_phpedu.club_bundle.crt;
# 私钥文件名称
ssl_certificate_key /etc/nginx/conf.d/ssl/2_phpedu.club.key;
ssl_session_timeout 5m;
# 请按照这个协议配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# 请按照这个套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location ~* /\. {
deny all;
}
}
server {
listen 80;
server_name phpedu.club www.phpedu.club;
# 把 http 的域名请求转成 https
rewrite ^(.*)$ https://$host$1 permanent;
}
```
5、重启Nginx。
### 参考
- [https://cloud.tencent.com/document/product/400/35244](https://cloud.tencent.com/document/product/400/35244)

View File

@@ -0,0 +1,34 @@
#!/bin/bash
# 安装 epel 源epel 是基于 Fedora 的一个项目,为"红帽系"的操作系统提供额外的软件包)
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# 安装 webtatic 源(安装 webtatic-release 之前需要先安装 epel-release
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装 PHP 及其扩展
yum -y install mod_php72w \
php72w-bcmath \
php72w-cli \
php72w-common \
php72w-devel \
php72w-fpm \
php72w-gd \
php72w-mbstring \
php72w-mysql \
php72w-opcache \
php72w-pdo \
php72w-xml
# 安装 Composer 并配置阿里云源
curl -sSL https://getcomposer.org/installer | php &&\
mv composer.phar /usr/local/bin/composer &&\
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
echo "===================================================="
php -v
composer -V
echo "===================================================="

View File

@@ -0,0 +1,51 @@
# 通过 yum 安装 PHP7
### 脚本描述
```
通过 yum 安装 PHP7 并安装 Composer
```
### 脚本内容
[PHP7-yum-install.sh](PHP7-yum-install.sh)
```shell
#!/bin/bash
# 安装 epel 源epel 是基于 Fedora 的一个项目,为"红帽系"的操作系统提供额外的软件包)
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# 安装 webtatic 源(安装 webtatic-release 之前需要先安装 epel-release
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装 PHP 及其扩展
yum -y install mod_php72w \
php72w-bcmath \
php72w-cli \
php72w-common \
php72w-devel \
php72w-fpm \
php72w-gd \
php72w-mbstring \
php72w-mysql \
php72w-opcache \
php72w-pdo \
php72w-xml
# 安装 Composer 并配置阿里云源
curl -sSL https://getcomposer.org/installer | php &&\
mv composer.phar /usr/local/bin/composer &&\
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
echo "===================================================="
php -v
composer -V
echo "===================================================="
```
### 执行
```shell
bash PHP7-yum-install.sh
```

View File

@@ -0,0 +1,37 @@
# CentOS7 初始化
### 脚本描述
```
纯净的 CentOS7 系统, 需要安装一些常用的软件, 如 git、vim 等.
```
### 脚本内容
[common-software-install.sh](common-software-install.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} common-software's install begin ${NC} \n"
echo "===================================================="
# 为了使用 ifconfig 命令, 需要安装 net-tools
yum -y install net-tools
yum -y install vim
yum -y install wget
yum -y install autoconf
yum -y install gcc gcc-c++ make
yum -y install git
echo "===================================================="
printf "${GREENCOLOR} common-software's install finish ${NC} \n"
echo "===================================================="
```
### 执行
```shell
bash common-software-install.sh
```

View File

@@ -0,0 +1,21 @@
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} common-software's install begin ${NC} \n"
echo "===================================================="
# 为了使用 ifconfig 命令, 需要安装 net-tools
yum -y install net-tools
yum -y install vim
yum -y install wget
yum -y install autoconf
yum -y install gcc gcc-c++ make
yum -y install git
echo "===================================================="
printf "${GREENCOLOR} common-software's install finish ${NC} \n"
echo "===================================================="

37
docker-rm-all/README.md Normal file
View File

@@ -0,0 +1,37 @@
# 删除所有容器和镜像
### 脚本描述
```
删除所有容器和镜像
```
### 脚本内容
[docker-rm-all.sh](docker-rm-all.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} Docker's rm begin ${NC} \n"
echo "===================================================="
# 删除所有容器
docker rm -f $(docker ps -aq)
# 删除所有镜像
docker rmi $(docker images -q)
echo "===================================================="
printf "${GREENCOLOR} Docker's rm finish ${NC} \n"
echo "===================================================="
```
### 执行
```shell
bash docker-rm-all.sh
```

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} Docker's rm begin ${NC} \n"
echo "===================================================="
# 删除所有容器
docker rm -f $(docker ps -aq)
# 删除所有镜像
docker rmi $(docker images -q)
echo "===================================================="
printf "${GREENCOLOR} Docker's rm finish ${NC} \n"
echo "===================================================="

View File

@@ -0,0 +1,49 @@
# 安装 docker、docker-compose
### 脚本描述
```
使用 yum 安装安装 docker、docker-compose 并启动 docker, 同时配置阿里云 docker 镜像加速器.
```
### 脚本内容
[docker-yum-install.sh](docker-yum-install.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} Docker's install begin ${NC} \n"
echo "===================================================="
# 安装 EPEL
yum -y install epel-release
# 安装docker和docker-compose
yum -y install docker docker-compose
# 配置阿里云 docker 镜像加速器
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://8auvmfwy.mirror.aliyuncs.com"]
}
EOF
# 重新加载配置、重启 docker
systemctl daemon-reload
systemctl restart docker
echo "===================================================="
printf "${GREENCOLOR} Docker's install finish ${NC} \n"
docker_version=$(docker -v)
printf "${GREENCOLOR} ${docker_version} ${NC} \n"
echo "===================================================="
```
### 执行
```shell
bash docker-yum-install.sh
```

View File

@@ -0,0 +1,30 @@
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} Docker's install begin ${NC} \n"
echo "===================================================="
# 安装 EPEL
yum -y install epel-release
# 安装 docker 和 docker-compose
yum -y install docker docker-compose
# 配置阿里云 docker 镜像加速器
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://8auvmfwy.mirror.aliyuncs.com"]
}
EOF
# 重新加载配置、重启 docker
systemctl daemon-reload
systemctl restart docker
echo "===================================================="
printf "${GREENCOLOR} Docker's install finish ${NC} \n"
docker_version=$(docker -v)
printf "${GREENCOLOR} ${docker_version} ${NC} \n"
echo "===================================================="

View File

@@ -0,0 +1,38 @@
# 关闭并开机禁用 firewalld
### 脚本描述
```
关闭并开机禁用 firewalld
```
### 脚本内容
[firewalld-disable.sh](firewalld-disable.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} firewalld's disable begin ${NC} \n"
echo "===================================================="
# 关闭防火墙
systemctl stop firewalld
# 开机禁用防火墙
systemctl disable firewalld
echo "===================================================="
printf "${GREENCOLOR} firewalld's disable finish ${NC} \n"
echo "===================================================="
```
### 执行
```shell
bash firewalld-disable.sh
```

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
echo "===================================================="
printf "${GREENCOLOR} firewalld's disable begin ${NC} \n"
echo "===================================================="
# 关闭防火墙
systemctl stop firewalld
# 开机禁用防火墙
systemctl disable firewalld
echo "===================================================="
printf "${GREENCOLOR} firewalld's disable finish ${NC} \n"
echo "===================================================="

16
go-install/README.md Normal file
View File

@@ -0,0 +1,16 @@
# Go 安装
```sh
# 下载 & 解压
wget https://mirrors.ustc.edu.cn/golang/go1.17.1.linux-amd64.tar.gz
tar -xvf go1.17.1.linux-amd64.tar.gz -C /home/work/service
# vim /etc/profile
export GOROOT=/home/work/service/go
export GOPATH=/home/work/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source /etc/profile
# 创建目录
mkdir -p /home/work/gopath
```

View File

@@ -0,0 +1,88 @@
# 安装 Mysql
### 脚本描述
```
使用 yum 安装 MySQL5.7 并启动
```
### 脚本内容
[mysql57-yum-install.sh](mysql57-yum-install.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm"
echo "===================================================="
printf "${GREENCOLOR} MySQL's install begin ${NC} \n"
echo "===================================================="
# 安装 MySQL
# 如果安装过 MySQL, 先卸载
yum -y remove mysql
# 进入目录
cd $DOWNLOAD_DIR
# 下载 MySQL 包
wget $SOURCE_DIR
# 安装 MySQL 的 yum 源
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
# 安装 MySQL
yum -y install mysql-community-server
# 启动 MySQL
service mysqld start
echo "===================================================="
printf "${GREENCOLOR} MySQL's install finish ${NC} \n"
cat /var/log/mysqld.log | grep 'temporary password'
echo "===================================================="
```
### 执行
```shell
bash mysql57-yum-install.sh
```
### 如何修改 root 密码?
1、首先查看初始化的密码。
```sh
cat /var/log/mysqld.log | grep 'temporary password'
```
2、用初始密码登录 MySQL然后修改 root 的密码。
```sql
ALTER user 'root'@'localhost' IDENTIFIED BY 'duiying*D123';
```
3、刷新权限。
```sql
FLUSH PRIVILEGES;
```
4、允许其他主机连接 MySQL。
```sql
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
```
### 如何设置 MySQL 开机自启动?
```sh
# 编辑文件
vim /etc/rc.log
# 在尾部新增下面这行
service mysqld start
```

View File

@@ -0,0 +1,31 @@
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm"
echo "===================================================="
printf "${GREENCOLOR} MySQL's install begin ${NC} \n"
echo "===================================================="
# 安装 MySQL
# 如果安装过 MySQL, 先卸载
yum -y remove mysql
# 进入目录
cd $DOWNLOAD_DIR
# 下载 MySQL 包
wget $SOURCE_DIR
# 安装 MySQL 的 yum 源
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
# 安装 MySQL
yum -y install mysql-community-server
# 启动 MySQL
service mysqld start
echo "===================================================="
printf "${GREENCOLOR} MySQL's install finish ${NC} \n"
cat /var/log/mysqld.log | grep 'temporary password'
echo "===================================================="

View File

@@ -0,0 +1,48 @@
# 安装 Nginx
### 脚本描述
```
使用 yum 安装 Nginx 并启动
```
### 脚本内容
[nginx-yum-install.sh](nginx-yum-install.sh)
```shell
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm"
echo "===================================================="
printf "${GREENCOLOR} Nginx's install begin ${NC} \n"
echo "===================================================="
# 安装 Nginx
# 进入目录
cd $DOWNLOAD_DIR
# 下载 Nginx 包
wget $SOURCE_DIR
# 安装 Nginx 的 yum 源
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
# 安装 Nginx
yum -y install nginx
# 启动 Nginx
service nginx restart
echo "===================================================="
printf "${GREENCOLOR} Nginx's install finish ${NC} \n"
echo "===================================================="
```
### 执行
```shell
bash nginx-yum-install.sh
```

View File

@@ -0,0 +1,28 @@
#!/bin/bash
# '\033[字背景颜色;字体颜色m字符串\033[0m'
GREENCOLOR='\033[1;32m'
NC='\033[0m'
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm"
echo "===================================================="
printf "${GREENCOLOR} Nginx's install begin ${NC} \n"
echo "===================================================="
# 安装 Nginx
# 进入目录
cd $DOWNLOAD_DIR
# 下载 Nginx 包
wget $SOURCE_DIR
# 安装 Nginx 的 yum 源
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
# 安装 Nginx
yum -y install nginx
# 启动 Nginx
service nginx restart
echo "===================================================="
printf "${GREENCOLOR} Nginx's install finish ${NC} \n"
echo "===================================================="

View File

@@ -0,0 +1,72 @@
# 通过源码安装 redis5.0.5
### 脚本描述
```
通过源码安装 redis5.0.5 并启动服务
```
### 脚本内容
[redis5-src-install.sh](redis5-src-install.sh)
```shell
#!/bin/bash
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://download.redis.io/releases/redis-5.0.5.tar.gz"
# 安装依赖
yum -y install libxml2 libxml2-devel telnet pcre-devel curl-devel
# 进入下载目录
cd $DOWNLOAD_DIR
# 下载源码包
wget $SOURCE_DIR
# 解压
tar -xzvf redis-5.0.5.tar.gz
# 进入目录
cd redis-5.0.5
# 编译
make
# 安装
make install
# 启动 redis 服务端
cd src
./redis-server
```
### 客户端连接
```shell
redis-cli -h 127.0.0.1 -p 6379
```
### 让 redis 服务在后台启动
```shell
# 进入目录
cd /usr/src/redis-5.0.5/
# 拷贝出一份自定义配置文件
cp redis.conf myredis.conf
# 修改配置文件 daemonize no => daemonize yes port 6379 => port 6397
# 如何开启远程访问?将 bind 127.0.0.1 注释掉
# 如何设置密码requirepass myPassword
vim myredis.conf
# 以指定配置文件启动 redis 服务
cd /usr/src/redis-5.0.5/src
./redis-server /usr/src/redis-5.0.5/myredis.conf
# 查看 redis 服务是否启动
[root@localhost src]# ps -ef | grep redis
root 6431 1 0 15:59 ? 00:00:00 ./redis-server 127.0.0.1:6397
root 6438 6361 0 16:00 pts/1 00:00:00 grep --color=auto redis
# 客户端连接
redis-cli -h 127.0.0.1 -p 6397
```
### 执行
```shell
bash redis5-src-install.sh
```

View File

@@ -0,0 +1,25 @@
#!/bin/bash
DOWNLOAD_DIR="/usr/src"
SOURCE_DIR="http://download.redis.io/releases/redis-5.0.5.tar.gz"
# 安装依赖
yum -y install libxml2 libxml2-devel telnet pcre-devel curl-devel
# 进入下载目录
cd $DOWNLOAD_DIR
# 下载源码包
wget $SOURCE_DIR
# 解压
tar -xzvf redis-5.0.5.tar.gz
# 进入目录
cd redis-5.0.5
# 编译
make
# 安装
make install
# 启动 redis 服务端
cd src
./redis-server

87
samba/README.md Normal file
View File

@@ -0,0 +1,87 @@
# CentOS7 搭建 samba 实现与Win共享目录
**搭建**
```shell
# 1、关闭防火墙、selinux
# 2. 安装samba
yum -y install samba
# 3、修改 samba 配置文件(首先备份配置文件)
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
vim /etc/samba/smb.conf
# 底部新增内容
[www]
comment = www # 说明
path = /data/www # 资源路径
valid users = smbuser # 能够访问资源的用户
browseable = yes # 是yes/否no在浏览资源中显示共享目录
writable = yes # 是yes/否no不以只读方式共享
create mask = 0777 # 建立文件时所给的权限
directory mask = 0777 # 建立目录时所给的权限
# 4、添加用户
useradd smbuser
passwd smbuser
# samba添加用户
smbpasswd -a smbuser
# 5、添加共享文件夹
mkdir -p /data/www
chmod -R 777 /data/www
chown -R smbuser:smbuser /data
# 6、重启 samba 服务
systemctl restart smb
```
**如何在 Win 中打开**
1、文件夹中打开
<div align=center><img src="https://raw.githubusercontent.com/duiying/img/master/samba.png" width="400"></div>
2、运行中打开
<div align=center><img src="https://raw.githubusercontent.com/duiying/img/master/samba-2.png" width="400"></div>
3、映射网络驱动器
<div align=center><img src="https://raw.githubusercontent.com/duiying/img/master/映射网络驱动器.png" width="400"></div>
此时会多出一个盘符
<div align=center><img src="https://raw.githubusercontent.com/duiying/img/master/盘符.png" width="400"></div>
**注意**
Win 在登录 samba 时,会缓存用户名和密码,当想切换 samba 用户登录时需要清除缓存
```
# net use 打印缓存连接列表
# net use 远程连接名称 /del 删除一个连接
# net use * /del 删除全部连接
C:\Users\wyx>net use
会记录新的网络连接。
状态 本地 远程 网络
-------------------------------------------------------------------------------
已断开连接 \\192.168.246.128\IPC$ Microsoft Windows Network
命令成功完成。
C:\Users\wyx>net use \\192.168.246.128\IPC$ /del
\\192.168.246.128\IPC$ 已经删除。
C:\Users\wyx>net use * /del
列表是空的。
```
**参考**
- [https://blog.csdn.net/yt_php/article/details/80787331](https://blog.csdn.net/yt_php/article/details/80787331)
- [https://www.cnblogs.com/thammer/p/8283704.html](https://www.cnblogs.com/thammer/p/8283704.html)