搭建Jenkins的CI环境

配置docker环境

1. 检查系统内核,docker要求64位+3.10及以上内核

2. 添加yum源

3. 安装并启动docker,检查docker是否正常启动

4. 如果已经安装docker,考虑升级到最新稳定版

安装jenkins

1. jenkins提供多种安装方式,包括下载war包,apt-get等依赖下载,以及通过docker安装,这是使用docker安装并启动jenkins。

2. 检查是否正常启动容器,并从日志中拷贝初始化密码。

安全策略(可选)

如果在云平台部署jenkins,例如阿里云,AWS等,可能需要配置安全策略,否则无法访问端口8888。
这里以阿里云配置为例,增加8888端口开放,如下图

配置jenkins

当配置端口,通过http://:8888打开初始状态jenkins如下图,通过输入初始密码(如果之前未在logs中拷贝,可以通过如图上步骤获取默认密码)进入配置页面,推荐选取安装默认插件,然后设置管理员账户,最终可以成功打开jenkins管理员页面。

搭建Jenkins的CI环境

搭建基于Hexo+Git+Nginx的静态博客平台

综述

  • 使用Hexo编写/调试基于Markdown的博客,并负责生成静态文件
  • 在云主机上搭建Git环境,实现本地hexo博客到云主机的自动部署
  • Nginx用做静态文件服务器,实现外界对博客的访问

环境

  • Mac pro book – macOS Sierra + iTerm2
  • 阿里云 ECS – CentOS 7 64bit

前提

确认本地已安装Hexo

安装篇

登录阿里云ECS

安装node, git, nginx

安装node

配置篇

增加git用户并赋予权限

按下’i’开始编辑模式,找到’root ALL=(ALL) ALL’,在它后面加上一行’git ALL=(ALL) ALL’,’esc’退出编辑,’:wq!’保存编辑,如下图

输入并确认git密码

添加密钥给git用户

在iTerm2打开另一个tab,运行如下命令获取rsa密钥串

回到阿里云ssh tab,粘贴密钥串到authorized_keys文件并保存

创建应用目录和Nginx配置

多次按exit退出root账号,然后以git账号ssh重新登录ECS,如下

找到server配置块,主要配置listen, server_name, root三个字段。listen是端口,这里由于80端口被其它应用占用,所以使用8000端口,server_name是域名,这里先不考虑,root是应用所在目录,这里是/var/www/hexo,如上所创建的文件夹,如下图

创建git工程和git-hooks实现自动部署

增加如下两行,让hooks找到repo和work路径,如下图

部署篇

本地自动部署配置和实现

Hexo git部署参考官方文档,首先安装hexo git deploy插件

到hexo所在目录,打开_config.yml配置文件,找到deploy部分,添加如下几行配置,如下图

生成静态文件并部署到阿里云ECS。hexo g -d用于生成静态文件,并根据deploy配置自动部署到环境。如果遇到permission问题,加上sudo。

部署过程如下图

部署成功后可以在ECS上查看到如下文件

启动/停止Nginx服务器

完成上述步骤,即可使用浏览器(http://<your_ip>:8000)访问博客

参考: http://blog.csdn.net/fjinhao/article/details/77096951

搭建基于Hexo+Git+Nginx的静态博客平台

阿里云ECS外网访问设置[http/https]

在阿里云安装和配置好运行环境后,外网还是不能直接通过ip直接访问,需要增加安全组规则配置
按照步骤:管理控制台->云服务器ECS->网络和安全->安全组->(右侧找到实例对应的安全组)->配置规则->添加安全组规则,参考如上链接案例六配置,选择相应的协议,端口和授权对象,如下图。


配置完无需重启实例和server,刷新即可看到效果。

阿里云ECS外网访问设置[http/https]

Node set up on CentOS 7

Node official site gives instruction to install node & npm on CentOS 7, as see https://nodejs.org/en/download/package-manager/, just copy that.

1. Running script to check and provide instructions

2. Install with yum command

3. Check its success

Node set up on CentOS 7

Docker系列 – Linux环境下Docker安装(CentOS7)

目前Docker仅提供了Enterprise Version(EE)和Community Version(CE)两个版本,分别是docker-ee和docker-ce,官网已经推荐删除历史版本包括docker或docker-engine。
这里以阿里云ECS(CentOS7)为演示环境。

1. 安装前检测

1.1 查看CentOS版本,安装docker需要CentOS 7。

1.2 查看Linux Kernel信息

2. 清除已安装docker

2.1 检测是否已安装docker,如果有参考2.2和2.3,如果没有直接跳到步骤3。

2.2 如果已经安装历史版本,首先删除

2.3 如果已经安装新版,但想从新安装,需要先卸载并删除已有image和container

3. 安装docker

3.1 方式一:使用docker-ce repository
这是官网推荐的方法,参考[3],分别执行如下命令。

3.2 方式二:
使用epel安装,参考[1],分别执行如下命令。这里它安装的是docker-io,但实际安装的就是docker-ce。docker-io命名是留给Ubuntu的,沿用到了epel,目的是为了避免和Ubuntu docker system-tray binary的命名冲突。

4. 查看docker安装情况

4.1 检测是否docker已经被安装,出现如图说明已经安装

4.2 启动并检测是否docker成功安装,如果成功会出现如图信息。

参考:
[1] https://help.aliyun.com/document_detail/51853.html
[2] https://fedoraproject.org/wiki/EPEL
[3] https://docs.docker.com/engine/installation/linux/docker-ce/centos/#os-requirements

Docker系列 – Linux环境下Docker安装(CentOS7)

Install Mysql on CentOS

Part Ⅰ Lost in MariaDB

    1. Install Mysql using yum

Type in ‘yum install mysql’
Type in ‘yum list installed | grep -i mysql’, but return nothing…Does Mysql NOT installed correctly? Actually, one database named MariaDB is installed rather than that Mysql what we want.

    2. Brief to MariaDB

As wikipedia says, ‘MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. It is notable for being led by the original developers of MySQL, who forked it due to concerns over its acquisition by Oracle.’, so MariaDB is treated as an alternative to Mysql.
However, we don’t need it and clean it before installing the right Mysql.

     3. Remove MariaDB

Type in ‘yum list installed | grep -i mariadb’, which will get two packages prefixed with ‘mariadb’
Type in ‘yum remove <name prefixed with mariadb-libs>, result as shown below:

1

2

 

Part Ⅱ Install Oracle Mysql

    1. Download Mysql RPM

Go to mysql official website (http://www.mysql.com/), and find ‘yum repository’ page to scroll down to select ‘Red Hat Enterprise Linux 7 / Oracle Linux 7 RPM package’, click download button at right side, then right click ’No thanks, just start my download’ to get noarch rpm download link on appearing page.

3

4

5

    2. Import Mysql RPM and Install Mysql

Type ‘wget <mysql noarch rpm url>’.

6

Next, type in ‘sudo rpm -ivh <mysql noarch rpm>’ to add mysql repo resources to yum list.
Type in ‘yum install mysql-server’ to start install mysql, input ‘y’ if prompt appears.

7

    3. Configure Mysql

Type in ‘sudo chown -R root:root /var/lib/mysql’ to resolve limits of access permission ( if ‘ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ appears)
(If you are not sure the running account, type whoami or who -p)

Type in ‘mysql’ or ‘mysql -u root -p’ even if password is correct, you will get error message ‘ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)’, because Mysql has set default password for root user. Type in ‘sudo grep ‘temporary password’ /var/log/mysqld.log’ to get default password, then use it to login in.
Next, to run Mysql normally, it is essential to change default password. The default password validation policy is upper case, lower case, number and special character, so the new password should contain all of these listed, otherwise it will show error message ‘ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.’. Type ‘SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘<new password>’);’ to change it.

8

9

10

Openning 3306 port
vi + /etc/sysconfig/iptables
-A INPUT -p tcp -m state –state NEW -m tcp –dport 3306 -j ACCEPT
service iptables restart
All done

 

 

 

 

 

Install Mysql on CentOS

Download & Install Tomcat on CentOS

    1. Get URL from tomcat official website

1 2

    2. Download and Start tomcat

        tar -zxvf apache-tomcat-9.0.0.M4.tar.gz
        mv ./apache-tomcat-9.0.0.M4 /usr/local/tomcat9
        (run/stop tomcat)
        /usr/local/tomcat9/bin/startup.sh
        /usr/local/tomcat9/bin/shutdown.sh
        (change port)
       1. CentOS 7+
        CentOS 7 replaces iptables with firewalld, so the most straight forward way is stopping firewall as shown below, or allow port to CentOs.
        yum install firewalld
        systemctl stop firewalld
systemctl disable firewalld
        2. Old CentOS
        vi + /etc/sysconfig/iptables
        -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT
       service iptables restart

    3. Config Tomcat

    Type in ‘cd /usr/local/tomcat/conf’
    Type in ‘vim server.xml’
    Edit server.xml by typing ‘i’, firstly change port of “<Connector port=“8080” protocol=“HTTP/1.1” from 8080 to 80, then add “<Context path=”” docBase=“ashton/” reloadable=”true” debug=”0″></Context>” into <host></host>, which directory ‘ashton’ is under webapps, use absolute path if directory is not under webapps.

    4. Start Tomcat Server

    Type in ‘/usr/local/tomcat9/bin/startup.sh’

    5.Type <your ip address> to web browser

3
Download & Install Tomcat on CentOS

Download & Install JDK on CentOS (AliYun)

    1. Get download link by using Firebug

     (It is difficult to download JDK directly from oracle site because ‘AuthParam’ is needed)
     Go to Oracle download page (http://www.oracle.com/technetwork/java/javase/downloads/index.html), click ‘JDK download’ button, then click tar link after accept licence agreement, such that complete download link will be seen in Firebug as shown in picture below.
 Screen Shot 2016-04-28 at 9.59.08 AM

    2. Download JDK using wget

Screen Shot 2016-04-28 at 10.20.02 AM
     Check whether JDK is downloaded completely by typing ‘du -sh jdk-8u91-linux-x64.tar.gz\?AuthParam\=1461808625_0225561591d4352a85eea97691609d8a’
     I prefer changing JDK name by typing ‘mv ./jdk-8u91-linux-x64.tar.gz\?AuthParam\=1461808625_0225561591d4352a85eea97691609d8a ./jdk-8u91-linux-x64.tar.gz’

    3. Uncompress to install JDK into given directory

     mkdir /usr/lib/jvm
     sudo tar -zxvf ./jdk-8u91-linux-x64.tar.gz  -C /usr/lib/jvm
     cd /usr/lib/jvm/

    4. Configure environment variable

     vim ~/.bashrc
     Adding lines code:
          export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_91
          export JRE_HOME=${JAVA_HOME}/jre
          export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
          export PATH=${JAVA_HOME}/bin:$PATH
     source ~/.bashrc

    5. Check JDK installation

      java -version
Screen Shot 2016-04-28 at 11.07.16 AM
    Done!
Download & Install JDK on CentOS (AliYun)