Linux-RPM-springBoot

rpm打包SpringBoot实战

  1. 环境需求安装rpm

    1
    2
    3
    4
    #centos
    yum -y install rpmdevtools
    #mac
    brew install rpm
  2. 添加插件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
      <properties>
    .......
    <rpm.release>0.3.0</rpm.release>
    <rpm.install.path>/home/face/java</rpm.install.path>
    <rpm.prefix>/data/micro-services/9090-web-api-jar</rpm.prefix>
    </properties>

    <build>
    <finalName>${autoPackage.name}</finalName>
    <plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>rpm-maven-plugin</artifactId>
    <version>2.2.0</version>
    <extensions>true</extensions>
    <executions>
    <execution>
    <goals>
    <goal>rpm</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
    <prefix>${rpm.prefix}</prefix>
    <distribution>myron</distribution>
    <group>myron.com</group>
    <packager>hello</packager>
    <version>${project.version}</version>
    <autoRequires>true</autoRequires>
    <release>3</release>
    <requires>
    <require>java-1.7.0 >= 1.7</require>
    </requires>
    <mappings>
    <mapping>
    <!-- 安装rpm后指向的服务器安装目录 -->
    <directory>${rpm.install.path}/${project.artifactId}</directory>
    <filemode>755</filemode>
    <username>root</username>
    <groupname>root</groupname>
    <sources>
    <source>
    <location>target/${project.artifactId}.jar</location>
    </source>
    </sources>
    </mapping>
    <!-- 复制安装相关脚本命令 根据具体项目需要决定是否使用-->
    <!-- <mapping>-->
    <!-- <directory>${rpm.install.path}/${project.artifactId}/bin</directory>-->
    <!-- <filemode>750</filemode>-->
    <!-- <username>root</username>-->
    <!-- <groupname>root</groupname>-->
    <!-- <sources>-->
    <!-- <source>-->
    <!-- <location>src/bin</location>-->
    <!-- </source>-->
    <!-- </sources>-->
    <!-- </mapping>-->

    <!--配置软连接注册服务起停项目,相当于:ln -sf myapp.jar /etc/init.d/myapp)
    启动: systemctl start myapp
    停止: systemctl stop myapp
    重启: systemctl restart myapp
    查看日志: journalctl -u myapp-->
    <!-- <mapping>-->
    <!-- <directory>/etc/init.d</directory>-->
    <!-- <filemode>750</filemode>-->
    <!-- <username>root</username>-->
    <!-- <groupname>root</groupname>-->
    <!-- <sources>-->
    <!-- <softlinkSource>-->
    <!-- <location>${rpm.install.path}/${project.artifactId}/${project.artifactId}-${project.version}.jar</location>-->
    <!-- <destination>${project.artifactId}</destination>-->
    <!-- </softlinkSource>-->
    <!-- </sources>-->
    <!-- </mapping>-->
    </mappings>
    <preinstallScriptlet>
    <script>echo "installing ${project.name} now"</script>
    </preinstallScriptlet>
    <postinstallScriptlet>
    <!-- 通过软链接 配置"service demo-swagger2 " 相关操作命令启动-->
    <!-- 使用上面softlinkSource配置替代
    <script>
    rm -f /etc/init.d/${project.artifactId};
    ln -sf ${rpm.install.path}/${project.artifactId}/bin/startup.sh /etc/init.d/demo-swagger2;
    </script>
    -->
    </postinstallScriptlet>
    <preremoveScriptlet>
    <script>
    <!--rm -f /etc/init.d/${project.artifactId};-->
    echo "uninstalling ${project.name} success";
    </script>
    <!-- 引用脚本方式
    <scriptFile>src/main/scripts/preremove</scriptFile>
    <fileEncoding>utf-8</fileEncoding>
    -->
    </preremoveScriptlet>
    </configuration>
    </plugin>
    ........
    </plugins>
    </build>
    </project>

空配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.2.0</version>
<inherited>false</inherited>
<executions>
<execution>
<!-- unbinds rpm creation from maven lifecycle -->
<phase>none</phase>
<goals>
<goal>attached-rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<release>1</release>
<distribution>loganshen</distribution>
<group>ifengkou.github.io</group>
<packager>loganshen</packager>
<prefix>/opt/soft</prefix>
<mappings>
<mapping>
<directory>/tmp</directory>
</mapping>
</mappings>
</configuration>
</plugin>

package rpm:rpm -U

参考

maven使用rpm-maven-plugin构建RPM包