centos7安装grafana

设置源

1
vi /etc/yum.repos.d/grafana.repo

源文件内容

1
2
3
4
5
6
7
8
9
[grafana]
name = grafana
baseurl = https://packages.grafana.com/oss/rpm
repo_gpgcheck = 1
enabled = 1
gpgcheck = 1
gpgkey = https://packages.grafana.com/gpg.key
sslverify = 1
sslcacert = /etc/pki/tls/certs/ca-bundle.crt

安装

1
yum install grafana

启动

1
systemctl start grafana-server

设为开机启动

1
systemctl enable grafana-server

访问

访问http://localhost:3000

grafana重置密码

找到grafana.db数据库,用sqlite工具执行下无sql语句

1
update user set password = '59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6', salt = 'F3FAxVm33R' where login = 'admin';

重置后登录用户和密码为:admin/admin

centos7安装mysql

安装

下载地址https://downloads.mysql.com/archives/community/

找到想要的版本

1
2
3
4
5
6
7
8
9
yum install libaio
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm

# 提示
error: Failed dependencies:
mysql-community-client(x86-64) >= 5.7.9 is needed by mysql-community-server-5.7.34-1.el7.x86_64
mysql-community-common(x86-64) = 5.7.34-1.el7 is needed by mysql-community-server-5.7.34-1.el7.x86_64

提示依赖mysql-community-clientmysql-community-common

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
# 提示和mariadb-libs冲突
file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.34-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
# 查看出来删除掉
rpm -qa|grep mariadb-libs
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
# 再重新安装mysql-community-common

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
error: Failed dependencies:
mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.34-1.el7.x86_64

提示依赖mysql-community-libs

1
2
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm

一共需要下面4个文件

  • mysql-community-client-5.7.34-1.el7.x86_64.rpm
  • mysql-community-common-5.7.34-1.el7.x86_64.rpm
  • mysql-community-libs-5.7.34-1.el7.x86_64.rpm
  • mysql-community-server-5.7.34-1.el7.x86_64.rpm

启动

1
2
3
systemctl start mysqld
# 查看状态
systemctl status mysqld

设置密码

如果没有设置密码

1
/usr/bin/mysqladmin -u root password 'xxx'

如果设置了密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 找到密码
sudo grep 'temporary password' /var/log/mysqld.log
# 登录
mysql -uroot -p
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'

# 出错
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

# 降低密码强度
set global validate_password_policy=0;
set global validate_password_length=1;

# mysql8,没这两个变量
SHOW VARIABLES LIKE 'validate_password%';
# 改为
set global validate_password.policy=0;
set global validate_password.length=1;
systemctl restart mysqld

用户加入sudo列表

新创建的用户,使用sudo切换到root时提示错误

1
xxx is not in the sudoers file.  This incident will be reported.

解决方法:

1
2
3
4
5
6
7
8
9
10
# 切换到`root`下
su
# 授权
chmod u+w /etc/sudoers
# 编辑sudoers文件
vi /etc/sudoers
# 添加
username ALL=(ALL) ALL
# 保存
chmod u-w /etc/sudoers

centos安装docker

官网步骤

删除旧的

1
2
3
4
5
6
7
8
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

设置源

1
2
3
4
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

安装

启用Nightly版

1
sudo yum-config-manager --enable docker-ce-nightly

安装

1
sudo yum install docker-ce docker-ce-cli containerd.io

搜索可用版本

1
yum list docker-ce --showduplicates | sort -r

指定版本

1
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

启动

1
sudo systemctl start docker

验证

1
sudo docker run hello-world

配置免费ssl证书

安装acme.sh

官方安装

1
curl  https://get.acme.sh | sh -s email=my@example.com

安装之后会在目录下生成个.acme.sh目录

资源在github,经常下载失败,手动克隆仓库安装

https://github.com/acmesh-official/acme.sh同步到gitee上,再克隆下来,执行下面命令

1
2
3
4
git https://gitee.com/xxx/acme.sh.git
cd acme.sh
./acme.sh --install -m my@example.com
alias acme.sh=~/.acme.sh/acme.sh

生成证书

1
acme.sh  --issue -d www.example.com  --webroot  /home/wwwroot/example.com/

如果80端口只配置了一个站点,可以这样

1
2
3
4
# apache
acme.sh --issue -d www.example.com --apache
# nginx
acme.sh --issue -d www.example.com --nginx

安装证书

官方例子nginx

1
2
3
4
5
acme.sh --install-cert -d www.example.com \
--cert-file /path/to/certfile/in/apache/cert.pem \
--key-file /path/to/keyfile/in/apache/key.pem \
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \
--reloadcmd "service apache2 force-reload"

官方例子apache

1
2
3
4
acme.sh --install-cert -d www.example.com \
--key-file /path/to/keyfile/in/nginx/key.pem \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd "service nginx force-reload"

手动安装

拷贝到指定的目录

1
2
cp  ~/.acme.sh/www.example.com/fullchain.cer /etc/nginx/ssl/www.example.com.cer
cp ~/.acme.sh/www.example.com/www.example.com.key /etc/nginx/ssl/www.example.com.key

修改nginx配置/etc/nginx/conf.d/www.example.com.conf

  • 启用https
1
2
listen 443 ssl;
listen [::]:443 ssl;
  • 证书
1
2
ssl_certificate /etc/nginx/ssl/www.example.com.cer;
ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
  • http跳转https
1
2
3
4
5
server {
listen 80;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}

linux用户管理

创建用户

创建一个用户

1
useradd username

创建用户并创建用户目录

1
useradd -m username

创建用户不创建用户目录

1
useradd -M username

创建用户不用于登录

1
useradd -s /sbin/nologin

创建用户不用于登录和不创建目录

1
useradd -s /sbin/nologin -M username

删除用户

1
userdel username

把用户目录也删掉

1
userdel -r username

设置密码

1
passwd username

用户组

创建组

1
groupadd groupname

删除组

1
groupadd groupname

用户加入组

1
usermod -G groupname username

用户加入组(并从原来组中移出)

1
usermod -g groupname username

用户移出用户组

1
gpasswd -d username groupname

相关查看

所有用户

1
cat /etc/passwd

所有用户组

1
cat /etc/group

ssh长时间保持不断开

远程ssh连接服务器,默认长时间不用会自动断开,设置不自动断开方式有三种

客户端连接加参数

1
2
# 相当于每隔120秒向服务器发送心跳
ssh -o ServerAliveInterval=120 user@ip

客户端设置配置

如果ssh服务器信息放~/.ssh/config中的,设置ServerAliveInterval

1
2
3
4
Host alias 
HostName ip
User root
ServerAliveInterval 120

服务器配置

修改sshd_config

1
2
3
4
5
6
7
vi vim /etc/ssh/sshd_config

## 发送心跳间隔
ClientAliveInterval 120
## 最大发送次数
ClientAliveCountMax 720

minikube安装

本地安装kubernetes开发环境minikube

下载安装

minikube官网选择系统对应的安装包

1
2
3
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

测试是否安装成功

启动minikube查看运行结果

1
minikube start

遇到的问题

安装之后,apt用的是阿里镜像,运行apt-get update报错

1
2
3
W: GPG error: https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB
E: The repository 'https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.

解决方法

1
sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

linux中clash安装

下载地址github clash

1
wget https://github.com/Dreamacro/clash/releases/download/v1.8.0/clash-linux-amd64-v1.8.0.gz

解压

1
gunzip clash-linux-amd64-v1.8.0.gz

创建clash目录

1
2
mkdir ~/clash

复制文件到clash目录

1
mv clash-linux-amd64-v1.8.0 ~/clash/clash

进入clash目录下载配置

1
2
3
cd ~/clash
wget -O config.yaml https://xxx/config.yml

启动class

1
2
3
./clash -d .
# clash不能执行,加可执行权限
sudo chmod +x clash

打开clash dashboard,设置:Host: 127.0.0.1,端口: 9090

打开网络设置代理,HTTP和HTTPS代理为 127.0.0.1:7890,Socks代理为 127.0.0.1:7891。