withCredentials([usernamePassword(credentialsId: '1.1.1.1-SSH', passwordVariable: 'PassWord', usernameVariable: 'UserName')]){
   def remote = [name:'root',host:'1.1.1.1',port:22,allowAnyHosts:true,user:UserName,password:PassWord]
        stage("部署服务"){
            writeFile file: 'deploy.sh', text: """#!/bin/bash
cd /data/server
ver_now=`cat docker-compose.yaml | grep image | awk -F: '{print \$NF}'`
time=`date +%F-%H-%M`
mkdir -p /data/bak
cp docker-compose.yaml /data/bak/\${time}.yaml
echo docker-compose.yaml中版本号是\${ver_now} 更新的版本号是${IMAGES_TAG}
sed -i "s/\${ver_now}/${IMAGES_TAG}/g" docker-compose.yaml
docker pull registry.cn-chengdu.aliyuncs.com/vv/server:${IMAGES_TAG}
docker-compose down
sleep 1
docker-compose up -d
"""
            sshScript remote: remote, script: 'deploy.sh'}

今天被自己坑的事情:

sshScript remote: remote, script: 'deploy.sh'

用于执行本地的脚本/命令,如果是执行远程服务器上面的脚本应该使用

sshScript remote: remote, command: '~/deploy.sh'

另一个需要注意的地方:在本地执行远程脚本的时候,脚本里面的远程变量需要转义,否则jenkins会报错找不到变量,因为jenkins会将它当成本地全局变量操作。

CENTOS7二进制安装MYSQL.sh

#!/bin/bash
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
yum -y install cmake gcc gcc-c++ bison ncurses ncurses-devel wget
mkdir -p /data/mys &&cd /data/mys
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
tar xf mysql-5.7.22.tar.gz
rm -f mysql-5.7.22.tar.gz
cd /data/mys/mysql-5.7.22/
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz --no-check-certificate
tar xf boost_1_59_0.tar.gz
rm -f boost_1_59_0.tar.gz
mv boost_1_59_0 boost
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DWITH_BOOST=/data/mys/mysql-5.7.22/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
make && make install
cat >/etc/my.cnf<<EOF
[client]
default-character-set = utf8mb4
socket=/data/mysql/mysql.sock
[mysql]
default-character-set = utf8mb4
[mysqld]
port=3306
user=mysql
basedir=/data/mysql
datadir=/data/mysql/data
log-error=/data/mysql/logs/error.log
socket=/data/mysql/mysql.sock
pid-file=/data/mysql/mysqld.pid
default-time-zone = '+8:00'
innodb_online_alter_log_max_size=128M
innodb_open_files=3000
table_open_cache=2000
innodb_lock_wait_timeout=120
innodb_log_files_in_group=3
thread_cache_size=100
max_connect_errors=200
myisam_sort_buffer_size=64M
back_log=800
server-id=1
innodb_log_file_size=1G
innodb_buffer_pool_size=1G
log_bin_trust_function_creators=1
character_set_server=utf8mb4
default_storage_engine=InnoDB
wait_timeout=28800
expire_logs_days=7
long_query_time=1
binlog_format=ROW
log-bin=mysql-bin
tmp_table_size=64M
read_buffer_size=4M
join_buffer_size=8M
sort_buffer_size=16M
max_heap_table_size=64M
binlog_cache_size=4M
max_allowed_packet=20M
max_connections=2000
long_query_time=1
slow-query-log=ON
log-output=TABLE
default_authentication_plugin = mysql_native_password
symbolic-links=0
lower_case_table_names=1
includedir /etc/my.cnf.d
EOF
mkdir -p /etc/my.cnf.d
mkdir -p /data/mysql/logs
touch /data/mysql/logs/error.log
chown -R mysql:mysql /data/mysql
/data/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/data/mysql \
--datadir=/data/mysql/data
#添加环境变量
cat >>/etc/profile<<EOF
PATH=$PATH:/data/mysql/bin:
EOF
source /etc/profile
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl daemon-reload && systemctl enable mysql && systemctl start mysql
mysqld_safe --defaults-file=/etc/my.cnf
#设置密码为123456并允许从任何地方登陆
mysql -uroot -e "SET PASSWORD = PASSWORD('123456');"
mysql -uroot -p123456 -e "use mysql;UPDATE user SET host = '%' WHERE user = 'root';"
mysql -uroot -p123456 -e "flush privileges;"
rm -fr /data/mys
rm -f $0

环境:

[root@master01 prometheus]# docker -v
Docker version 19.03.14, build 5eb3275d40
[root@master01 prometheus]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.9", GitCommit:"a17149e1a189050796ced469dbd78d380f2ed5ef", GitTreeState:"clean", BuildDate:"2020-04-16T11:44:51Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

docker是19.03.14
k8s是v1.16.9不同版本yaml文件可能有微调

下面上文件
config-map.yaml
grafana.yaml
prometheus.yaml
node-exporter.yaml
rbac-setup.yaml
直接应用上述文件,查看svc:

 [root@rke-master01 prometheus]# kubectl -n kube-system get svc
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                  AGE
grafana          NodePort    172.21.15.98   <none>        3000:31000/TCP           6m8s
kube-dns         ClusterIP   172.21.0.10    <none>        53/UDP,53/TCP,9153/TCP   18d
metrics-server   ClusterIP   172.21.0.11    <none>        443/TCP                  18d
node-exporter    NodePort    172.21.9.202   <none>        9100:31672/TCP           6m8s
prometheus       NodePort    172.21.9.246   <none>        9090:30003/TCP           6m7s

查看pod

 [root@rke-master01 prometheus]# kubectl -n kube-system get pod
NAME                                      READY   STATUS      RESTARTS   AGE
coredns-89bcfc8d5-mxdd4                   1/1     Running     0          18d
coredns-89bcfc8d5-x4dv8                   1/1     Running     0          18d
coredns-autoscaler-976fbb6bf-2q456        1/1     Running     0          18d
grafana-core-5b8dbf444-v2xkq              1/1     Running     0          31m
kube-flannel-4nvgs                        2/2     Running     0          18d
kube-flannel-nbzjv                        2/2     Running     0          18d
kube-flannel-t5m5l                        2/2     Running     0          18d
metrics-server-8cdbf5cd7-bmp2q            1/1     Running     0          18d
node-exporter-26b7h                       1/1     Running     0          30m
node-exporter-99p6b                       1/1     Running     0          30m
node-exporter-p4flt                       1/1     Running     0          30m
prometheus-759d85775b-2589h               1/1     Running     0          34m

都是running就可以通过192.168.100.241:31000访问grafana了,默认账号密码都是admin
进去后如图添加数据库,再import-315就可以看到一些基础数据了。
添加数据库

环境:
CentOS7.9+nginx+php+pgsql
坑一:
在初始化界面找不到pgsql插件
解决方案:
安装了php-pgsql之后,需要重启php-fpm

坑二:
不能写入配置文件
解决方案:
将文件夹给nginx:nginx并授予777权限

坑三:
这也是耽搁时间最长的一个问题,进来之后主页可以正常访问,但是其他页面几乎都是404
解决方案:
1、在admin/options-permalink.php界面启用地址重写功能;
2、nginx配置添加如下:

location ~ \.php$ {
    try_files $uri $uri/ =404;
    if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }
}

坑四:
我以为所有的问题都搞定之后,发布本文的时候遇到问题,正常发布文档没问题,但是添加未添加过的标签的时候报报错“Database Query Error”
解决方案:
先在标签界面添加相关的标签,再编译文章就不会出现了。
技术上待解决
坑五:
上传附件失败
chmod -R 777 ./usr/uploads
本目录权限在nginx上需要由apache上传文件