Jenkins + Docker achieve quick update of discuz Forum

First, the use LNMP environment to build discuz Forum

1, LNMP from a container docker

docker run -itd --privileged -p 80:80 docker.io/centos /usr/sbin/init
#入口命令改为/usr/sbin/init,是为了支持systemctl风格启动服务 

Here Insert Picture DescriptionNote: If the above error occurs, you can restart the docker services try again!

2, the installation nginx, mariadb

yum install nginx mariadb mariadb-devel mariadb-server -y
vim /etc/nginx/nginx.conf
nginx -s reload
systemctl start mariadb
mysql_secure_installation
mysql -uroot -pmysql
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.php; #我现在才搞清楚这个根location的作用,无论动态页面还是静态页面都是先匹配/,index参数:是把root参数的目录下的相应文件取出来,然后再匹配下面这个动态和静态的处理方式的location,所以一般来说还需要一个匹配静态页面的location,但是我们这里不需要!
        }
	location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

3, install php

I tried using yum install php, the whole for a long time, php-fpm process began, listening on port 9000, but nginx is not a dynamic php page to resolve. So back on the use of wget, you go in!

php installation tutorial: https://blog.csdn.net/weixin_44571270/article/details/103223557
Note: This version can be installed php5.4.44! ! Do not install more than php5.5.0 version!

Second, build a platform jenkins

1, from the container docker

docker search jenkins
docker pull docker.io/jenkins
docker run -itd -p 8080:8080 docker.io/jenkins
#容器中需要部署服务的才加/usr/sbin/init入口命令,这个容器本身就是一个服务,所以不需要加入口命令就可以启动它!

Here Insert Picture DescriptionNote: The password is required

cat /var/jenkins_home/secrets/initialAdminPassword

Here Insert Picture Description

2, modify the admin user's password

Here Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture Description

Three jenkins Docker and integration,

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionShell here can execute the commands are executed in the container jenkins where!
Because we want to achieve discuz forum website content updates on jenkins, so we have to go to which container discuz web server (Nginx) where the operation! So we need to do ssh key authentication-free! Here does not support interactive scene!

#两个容器都要做:
yum install openssh openssh-server -y
vim /etc/ssh/sshd-config #看看那些参数需要修改,优化
systemctl start sshd
#discuz web容器:
yum install passwd -y
echo "1"|passwd --stdin root
#jenkins容器:
ssh-keygen
ssh-copy-id -i /var/jenkins_home/.ssh/id_rsa.pub root@172.17.0.2

Now we have to write shell scripts on jenkins to the site can discuz forum page updates!

One might ask: we write directly execute a shell script, not on the line, why should jenkins it?

A: What we are doing is the easiest one to use for ease of entry, jenkins can and svn, git code repository and other sites to establish connections to obtain the code, the code development reached the warehouse, and then click the update that is jenkins can , so you can understand jnekins usage scenarios it!

Scripting purpose: to make discuz forum will update its log picture! just find a picture log yourself!
First find the logo directory location:
Here Insert Picture DescriptionHere Insert Picture Description

ssh -tt root@172.17.0.2"
cd /usr/share/nginx/html/static/image/common
mv logo.png logo.png.bak
wget https://www.baidu.com/img/bd_logo1.png?qua=high
mv bd_logo1.png?qua=high logo.png"
#双引号表示将命令导入这个终端!
#如果不加-tt,会出现Pseudo-terminal will not be allocated because stdin is not a terminal.这样的报错!-tt可以强制分配伪终端!
#但是我看老师做的没加-tt也能远程执行成功!我加-tt解决了上面那个错误,也不能远程执行成功!

Then apply, save, build immediately! He completed
but this construct as described above, even if the configuration-free key authentication login can not execute remote shell command, always fail!

I later found a new version of Baidu jenkins, a man named Publish Over SSHplug-in, you can remotely execute shell commands, so here I will use wget to download jenkins.war package, publish it in the tomcat!

Third, the use tomcat release jenkins

Note: Because we need to install SSH plug-in, the old version does not support SSH, so we can only use their own tomcat release a new version!

1, tomcat installation, and start tomcat

https://blog.csdn.net/weixin_44571270/article/details/102939666

2, download jenkins, and unzip tomcat directory publishing

wget -O /opt/tomcat/webapps/ROOT/jenkins.war /opt http://mirrors.jenkins-ci.org/war-stable/2.204.3/jenkins.war

/usr/local/jdk1.8.0_141/bin/jar xvf /opt/tomcat/webapps/ROOT/jenkins.war

carry out! Now you can visit!

3, download Publish Over SSH plug-in

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture DescriptionAfter the download is complete restart jenkins can!

4, the use of plug-ins and configure SSH

Here Insert Picture DescriptionNormally we use the user name plus password can ssh!
Here Insert Picture Description
Note: this do not move, do not fill, this is the use of public and private key file to connect.
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionJust click this can be! Without this, it will complain!
Here Insert Picture DescriptionThen turned up to find the Test Configuration, click on it.
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture Description

5, building engineering 172.17.0.2, to see whether to replace logo

Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionYou can see the construction of a success! clear cache! Refresh discuz forum site!
Here Insert Picture DescriptionUsing jenkins, logo replace the success!

He published 188 original articles · won praise 150 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_44571270/article/details/104587783