在准备部署之前,需要安装好Linux系统,Linux系统安装好后,在服务器上安装环境所需要的服务,需要安装java8、docker、docker-compose、gitea、git、maven等服务
centos7安装这里不详细展开,详细请看这里https://blog.csdn.net/andyLyysh/article/details/127248551?spm=1001.2014.3001.5502
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
在安装前检查是否有安装gcc和gcc-c++
whereis gcc
whereis gcc-c++
或者gcc -version
安装软件包
yum install -y yum-utils
设置阿里云镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新软件包索引
yum makecache fast
安装docker
yum -y install docker-ce docker-ce-cli containerd.io
启动docker
systemctl start docker
开机启动
systemctl enable docker
查看版本号
docker version
官网:https://docs.docker.com/compose/compose-file/compose-file-v3/
安装:
curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
分配权限
chmod +x /usr/local/bin/docker-compose
查看版本
docker-compose --version
使用docker-compose + mysql 部署gitea
version: "3"
services:
gitea-mysql:
container_name: gitea-mysql
environment:
- TZ=Asia/Shanghai
- MYSQL_USER=gitea
- MYSQL_DATABASE=gitea
- MYSQL_ROOT_PASSWORD=gitea@123
hostname: gitea-mysql
image: mysql:8.0.30
networks:
gitea-network:
ipv4_address: 172.19.0.2
ports:
- 3310:3306
restart: always
privileged: true
volumes:
- ./mysql/mysql-files:/var/lib/mysql-files/
- ./mysql/data:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
- ./mysql/initdb:/docker-entrypoint-initdb.d
gitea-service:
container_name: gitea
image: gitea/gitea:1.17.3
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=gitea-mysql:3306
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
restart: always
privileged: true
networks:
gitea-network:
ipv4_address: 172.19.0.2
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
depends_on:
- gitea-mysql
networks:
gitea-network:
driver: bridge
ipam:
config:
- subnet: 172.19.0.0/24
name: gitea-network
初始化文件位置是你安装gitea目录中,图中是我安装gitea所在位置,如果在初始化页面上操作失误或者漏写,并且已经进行初始化后,出现错误提示,根据错误提示在app.ini配置文件排查或者修改配置
例如:域名更改或者写错等都可以在这里修改配置
**注意:**如果MySQL使用gitea用户,需要手动创建并授权
创建用户:
//低版本数据库
create user '用户民'@'%' identified by '密码';
//高版本数据库
create user 'gitea'@'%' identified with mysql_native_password by 'gitea@123';
给用户授权:
//指定数据库
grant all privileges on 想授权的数据库.* to '用户名'@'%';
//全部数据库
grant all privileges on *.* to 'gitea'@'%';
安装
yum install -y git
查看版本
git -version
java8这里也不详细展开,详细请看这里https://blog.csdn.net/andyLyysh/article/details/126866505?spm=1001.2014.3001.5502
maven下载:https://maven.apache.org/download.cgi
下载后上传到服务器中进行解压
将maven解压至/usr/local/maven目录下,安装目录可以自定义
tar -zxvf apache-maven-3.8.6-bin.tar.gz -C /usr/local/maven
配置环境变量
vim /etc/profile
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
如果PATH有多个,在其后面添加,如:
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
依次添加
source /etc/profile
验证安装是否成功
mvn -v
/usr/local/maven/conf/setting.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repositorylocalRepository>
<pluginGroups>
<pluginGroup>org.mortbay.jettypluginGroup>
pluginGroups>
<proxies>
proxies>
<servers>
<server>
<id>releasesid>
<username>aliusername>
<password>alipassword>
server>
<server>
<id>Snapshotsid>
<username>aliusername>
<password>alipassword>
server>
servers>
<mirrors>
<mirror>
<id>nexusid>
<mirrorOf>*mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
mirror>
<mirror>
<id>nexus-public-snapshotsid>
<mirrorOf>public-snapshotsmirrorOf>
<url>http://maven.aliyun.com/nexus/content/repositories/snapshots/url>
mirror>
<mirror>
<id>nexus-public-snapshots1id>
<mirrorOf>public-snapshots1mirrorOf>
<url>https://artifacts.alfresco.com/nexus/content/repositories/public/url>
mirror>
mirrors>
<profiles>
<profile>
<id>developmentid>
<repositories>
<repository>
<id>centralid>
<url>http://centralurl>
<releases><enabled>trueenabled><updatePolicy>alwaysupdatePolicy>releases>
<snapshots><enabled>trueenabled><updatePolicy>alwaysupdatePolicy>snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>centralid>
<url>http://centralurl>
<releases><enabled>trueenabled><updatePolicy>alwaysupdatePolicy>releases>
<snapshots><enabled>trueenabled><updatePolicy>alwaysupdatePolicy>snapshots>
pluginRepository>
pluginRepositories>
profile>
<profile>
<id>public-snapshotsid>
<repositories>
<repository>
<id>public-snapshotsid>
<url>http://public-snapshotsurl>
<releases><enabled>falseenabled>releases>
<snapshots><enabled>trueenabled><updatePolicy>alwaysupdatePolicy>snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>public-snapshotsid>
<url>http://public-snapshotsurl>
<releases><enabled>falseenabled>releases>
<snapshots><enabled>trueenabled><updatePolicy>alwaysupdatePolicy>snapshots>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>developmentactiveProfile>
<activeProfile>public-snapshotsactiveProfile>
activeProfiles>
settings>
使用docker-compose安装Jenkins
version: "3"
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins:lts
user: root
privileged: true
restart: always
ports:
- 8082:8080
- 50000:50000
volumes:
- ./jenkins-data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
networks:
gitea-network:
ipv4_address: 172.19.0.2
networks:
jenkins-network:
driver: bridge
ipam:
config:
- subnet: 172.19.0.0/24
name: jenkins-network
访问:可以直接使用ip访问或者域名,eg: http://192.168.226.129/8082
访问成功后,会提示需要输入密钥,密钥是放在/var/jenkins_home/secrets/initialAdminPassword文件中
输入下面命令获取密钥:
docker exec [container_id/container_name] cat /var/jenkins_home/secrets/initialAdminPassword
找到密钥输入,继续,在密钥输入并设置管理账号后initialAdminPassword文件会自动销毁
在可选插件页面中搜索,查找到后,勾选,然后点击install without restart按钮进行安装
在安装时忘记截图,这里给大家看一下,安装好的
到此!整个自动化部署环境搭建完成。