diff --git a/README.md b/README.md index ccdda17c798b5de9d122a1664e1eeaa0bd4baf10..25e77c9a1c7ed7431dbcf42e05b2cbe8c8af3205 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Brief Introduction -Docs maintains openEuler documentaions which is integrated by online website. Now we are under developing. +Docs maintains openEuler documentations which is integrated by online website. Now we are under developing. you are welcome to join us. ### Installation @@ -15,6 +15,14 @@ docker build -t docs:v0.0.1 . note: here ```docs``` is the image name, you can change it as you need. +> TO THOSE WHO MAY CONCERN: +> +> If you are working behind proxy, use `--build-arg` option to tell `docker build` about it: +> +> ```docker build --build-arg http_proxy="http://username:password@your.proxy.com:port" -t docs:v0.0.1 .``` +> +> `--build-arg` can be specified many times, like `http_proxy`, `https_proxy`, `HTTP_PROXY`, `HTTPS_PROXY` and so on. + 2. Running in container ``` @@ -46,5 +54,3 @@ Please refer to [CONTRIBUTING](./CONTRIBUTING.md) for more guide. - IRC: #openeuler-doc - MAIL: dev@openeuler.org - - diff --git a/content/en/docs/Administration/basic-configuration.md b/content/en/docs/Administration/basic-configuration.md index 3adb15547b4f83130f65880aa563f0b7cc2cd41a..606c1e5040ac97a0d4e098bd70f6deb4bd99f85d 100644 --- a/content/en/docs/Administration/basic-configuration.md +++ b/content/en/docs/Administration/basic-configuration.md @@ -66,10 +66,10 @@ For example, if you want to use Simplified Chinese as the locale, run the follow ``` >![](public_sys-resources/icon-note.gif) **NOTE:** ->After the modification, log in again or run the following command to update the configuration file for the modification to take effect: ->``` ->source /etc/locale.conf ->``` +>After the modification, log in again or run the following command to update the configuration file for the modification to take effect: +``` +source /etc/locale.conf +``` ## Setting the Keyboard Layout diff --git a/content/en/docs/Administration/configuring-the-network.md b/content/en/docs/Administration/configuring-the-network.md index c1c546115795d729e233ba96af06b085d501eccb..2f73c57f0101e9ddfa9dc0464b143ab8aca9c858 100644 --- a/content/en/docs/Administration/configuring-the-network.md +++ b/content/en/docs/Administration/configuring-the-network.md @@ -542,7 +542,7 @@ To change the host name in a remote system, run the **hostnamectl** command wi # hostnamectl set-hostname -H [username]@hostname new_hostname ``` -In the preceding command, _hostname_ indicates the name of the remote host to be configured, _username _indicates the user-defined name, and _new\_hostname_ indicates the new host name. **hostnamectl** is used to connect to the remote system through SSH. +In the preceding command, _hostname_ indicates the name of the remote host to be configured, _username_ indicates the user-defined name, and *new\_hostname* indicates the new host name. **hostnamectl** is used to connect to the remote system through SSH. ### Configuring a Host Name by Running the nmcli Command diff --git a/content/en/docs/Administration/service-management.md b/content/en/docs/Administration/service-management.md index 49aceffcaddf76d85dc19a14d8a3923b72c6b984..58457238c65e283618308bc13ea644c034a77fd8 100644 --- a/content/en/docs/Administration/service-management.md +++ b/content/en/docs/Administration/service-management.md @@ -300,21 +300,21 @@ The **systemctl** command from the **systemd** command has the functions sim

Checks whether a service is enabled.

-

chkconfig --list

+

chkconfig \-\-list

-

systemctl list-unit-files --type=service

+

systemctl list-unit-files \-\-type=service

Lists all services in each runlevel and checks whether they are enabled.

-

chkconfig network --list

+

chkconfig network \-\-list

ls /etc/systemd/system/*.wants/network.service

Lists the runlevels in which a service is enabled and those in which the service is disabled.

-

chkconfig network --add

+

chkconfig network \-\-add

systemctl daemon-reload

diff --git a/content/en/docs/Administration/setting-up-the-database-server.md b/content/en/docs/Administration/setting-up-the-database-server.md index 93b96a711dd93f80befc8e8f12fa7bc15cac9abd..d7ef2d75375223f3f82021b6b16b2ce4d32c264c 100644 --- a/content/en/docs/Administration/setting-up-the-database-server.md +++ b/content/en/docs/Administration/setting-up-the-database-server.md @@ -745,7 +745,7 @@ In the preceding information: - _databasename_: database name. If this parameter is not specified, the environment variable **PGDATABASE** is used. If that environment variable is not specified, use the username that initiates the connection. - _outfile_: database backup file. - _option_: parameter option of the **pg\_dump** command. Multiple parameters can be separated by spaces. The common parameters of the **pg\_dump** command are as follows: - - **-f **_filename_**, \-\-file**= _filename_: specified output file. If this parameter is ignored, the standard output is used. + - **-f, \-\-file**= _filename_: specified output file. If this parameter is ignored, the standard output is used. - **-d, \-\-dbname**= _databasename_: database to be dumped. - **-h, \-\-host**= _hostname_: specifies the hostname. - **-p, \-\-port**= _portnumber_: port number. @@ -774,7 +774,7 @@ In the preceding information: - _username_: name of a user. - _infile_: **outfile** parameter in the **pg\_dump** command. - _option_: parameter option of the **psql** command. Multiple parameters can be separated by spaces. The common parameters of the **psql** command are as follows: - - **-f **_filename_**, \-\-file**= _filename_: specified output file. If this parameter is ignored, the standard output is used. + - **-f, \-\-file**= _filename_: specified output file. If this parameter is ignored, the standard output is used. - **-d, \-\-dbname**= _databasename_: database to be dumped. - **-h, \-\-host**= _hostname_: specifies the hostname. - **-p, \-\-port**= _portnumber_: port number. diff --git a/content/en/docs/ApplicationDev/about-this-document.md b/content/en/docs/ApplicationDev/about-this-document.md deleted file mode 100644 index 5bf23ecd91c8579567128e5ad2b19b8c23f2fa4b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/about-this-document.md +++ /dev/null @@ -1,93 +0,0 @@ -# About This Document - -## Overview - -This document describes the following four parts to guide users to use openEuler and develop code based on openEuler. - -- Install and use the GCC compiler in the openEuler operating system \(OS\), and complete the development, compilation, and execution of simple code. -- In the openEuler OS, use the JDK built-in tool to compile and execute code. -- Install IntelliJ IDEA in the openEuler OS for Java development. -- Create an RPM package locally or using the Open Build Service \(OBS\). - -## Intended Audience - -This document is intended for all users who use the openEuler OS for code development. You are expected to have the following experience or capabilities: - -- Have basic knowledge of the Linux OS. -- Know how to use Linux command lines. - -## Symbol Conventions - -The symbols that may be found in this document are defined as follows. - - - - - - - - - - - - - -

Symbol

-

Description

-

-

Indicates a potentially hazardous situation which, if not avoided, could result in equipment damage, data loss, performance deterioration, or unanticipated results.

-

NOTICE is used to address practices not related to personal injury.

-

-

Supplements the important information in the main text.

-

NOTE is used to address information not related to personal injury, equipment damage, and environment deterioration.

-
- -## Command Conventions - -**Table 1** Command conventions - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Format

-

Description

-

Boldface

-

Command keywords, which remain unchanged in the commands, are in boldface.

-

Italic

-

Command parameters, which are replaced with actual values in the commands, are in italic.

-

[ ]

-

Items in square brackets are optional.

-

{ x | y | ... }

-

Optional items are grouped in braces and separated by vertical bars. One item is selected.

-

[ x | y | ... ]

-

Optional items are grouped in brackets and separated by vertical bars. One item is selected or no item is selected.

-

{ x | y | ... }*

-

Optional items are grouped in brackets and separated by vertical bars. A minimum of one or a maximum of all can be selected.

-

[ x | y | ... ]*

-

Optional items are grouped in brackets and separated by vertical bars. One or more items are selected or no item is selected.

-
- diff --git a/content/en/docs/ApplicationDev/adding-a-software-package-10.md b/content/en/docs/ApplicationDev/adding-a-software-package-10.md deleted file mode 100644 index da1392758edb92d6bdd66df2abf2fe23fec01964..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/adding-a-software-package-10.md +++ /dev/null @@ -1,56 +0,0 @@ -# Adding a Software Package - -To use the OSC tool of OBS to add a new software package, perform the following steps: - -**Creating a Project** - -1. Create a project based on the dependency of the new software package and a proper project. For example, to create a project based on **zlib** of the **openEuler:Mainline** project, run the following command \(**zlib** is any software package in the project\): - - ``` - # osc branch openEuler:Mainline zlib - ``` - -2. Delete unnecessary software packages added during project creation. For example, to delete the **zlib** software package, run the following command: - - ``` - # cd home:testUser:branches:openEuler:Mainline - # osc rm zlib - # osc commit -m "commit log" - ``` - -3. Create a software package in your own project. For example, to add the **my-first-obs-package** software package, run the following command: - - ``` - # mkdir my-first-obs-package - # cd my-first-obs-package - ``` - - -**Building an RPM Package** - -1. Add the prepared source file and .spec file to the software package directory. -2. Modify the source code and .spec file, and upload all files of the corresponding software package to the OBS server. The following is a command example. The information after the **-m** parameter is the commission record. - - ``` - # cd home:testUser:branches:openEuler:Mainline - # osc add my-first-obs-package - # osc ci -m "commit log" - ``` - -3. Run the following command to obtain the repository name and architecture of the current project: - - ``` - # osc repos home:testUser:branches:openEuler:Mainline - ``` - -4. After the modification is committed, OBS automatically compiles the software package. You can run the following command to view the compilation logs of the corresponding repository. In the command, _standard\_aarch64_ and _aarch64_ indicate the repository name and architecture obtained in the command output. - - ``` - # cd home:testUser:branches:openEuler:Mainline/my-first-obs-package - # osc buildlog standard_aarch64 aarch64 - ``` - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >You can also open the created project on the web client to view the build logs. - - diff --git a/content/en/docs/ApplicationDev/adding-a-software-package.md b/content/en/docs/ApplicationDev/adding-a-software-package.md deleted file mode 100644 index f79993f840f5b5136e46d5a9199c35a416ec8c44..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/adding-a-software-package.md +++ /dev/null @@ -1,37 +0,0 @@ -# Adding a Software Package - -To add a new software package on the OBS web page, perform the following steps: - -1. Log in to the OBS console. -2. Select a project based on the dependency of the new software package. That is, click **All Projects** and select the corresponding project, for example, **openEuler:Mainline**. -3. Click a software package in the project. The software package details page is displayed. -4. Click **Branch package**. On the confirmation page that is displayed, click **Accept**. -5. Click **Delete package** to delete the software package in the new subproject, as shown in [Figure 1](#fig18306181103615). - - **Figure 1** Deleting a software package from a subproject - ![](figures/deleting-a-software-package-from-a-subproject.png "deleting-a-software-package-from-a-subproject") - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >The purpose of creating a project by using existing software is to inherit the dependency such as the environment. Therefore, you need to delete these files. - -6. Click **Create Package**. On the page that is displayed, enter the software package name, title, and description, and click **Create** to create a software package, as shown in [Figure 2](#fig6762111693811) and [Figure 3](#fig18351153518389). - - **Figure 2** **Create Package** page - ![](figures/create-package-page.png "create-package-page") - - **Figure 3** Creating a software package - ![](figures/creating-a-software-package.png "creating-a-software-package") - -7. Click **Add file** to upload the .spec file and the file to be compiled \(specified in the .spec file\), as shown in [Figure 4](#fig1475845284011). - - **Figure 4** **Add file** page - ![](figures/add-file-page.png "add-file-page") - -8. After the file is uploaded, OBS automatically starts to build the RPM software package. Wait until the build is complete and view the build status in the status bar on the right. - - **succeeded**: The build is successful. You can click **succeeded** to view the build logs. - - **failed**: The build failed. Click **failed** to view error logs, locate the fault, and rebuild again. - - **unresolvable**: The build is not performed. The possible cause is that the dependency is missing. - - **disabled**: The build is manually closed or is queuing for build. - - **excluded**: The build is prohibited. The possible cause is that the .spec file is missing or the compilation of the target architecture is prohibited in the .spec file. - - diff --git a/content/en/docs/ApplicationDev/application-development.md b/content/en/docs/ApplicationDev/application-development.md index 2232745b25efcc425e0ff6b7030b81c5fadb14cf..d80e8b2f7d0a55040966ae74f04c1a3b2cde40b2 100644 --- a/content/en/docs/ApplicationDev/application-development.md +++ b/content/en/docs/ApplicationDev/application-development.md @@ -1 +1,94 @@ -This document describes the common tools used for application development and guides users to develop applications based on openEuler. \ No newline at end of file +# Application Development Guide + +This document describes the common tools used for application development and guides users to develop applications based on openEuler. + +## Overview + +This document describes the following four parts to guide users to use openEuler and develop code based on openEuler. + +- Install and use the GCC compiler in the openEuler operating system \(OS\), and complete the development, compilation, and execution of simple code. +- In the openEuler OS, use the JDK built-in tool to compile and execute code. +- Install IntelliJ IDEA in the openEuler OS for Java development. +- Create an RPM package locally or using the Open Build Service \(OBS\). + +## Intended Audience + +This document is intended for all users who use the openEuler OS for code development. You are expected to have the following experience or capabilities: + +- Have basic knowledge of the Linux OS. +- Know how to use Linux command lines. + +## Symbol Conventions + +The symbols that may be found in this document are defined as follows. + + + + + + + + + + + + + +

Symbol

+

Description

+

+

Indicates a potentially hazardous situation which, if not avoided, could result in equipment damage, data loss, performance deterioration, or unanticipated results.

+

NOTICE is used to address practices not related to personal injury.

+

+

Supplements the important information in the main text.

+

NOTE is used to address information not related to personal injury, equipment damage, and environment deterioration.

+
+ +## Command Conventions + +**Table 1** Command conventions + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Format

+

Description

+

Boldface

+

Command keywords, which remain unchanged in the commands, are in boldface.

+

Italic

+

Command parameters, which are replaced with actual values in the commands, are in italic.

+

[ ]

+

Items in square brackets are optional.

+

{ x | y | ... }

+

Optional items are grouped in braces and separated by vertical bars. One item is selected.

+

[ x | y | ... ]

+

Optional items are grouped in brackets and separated by vertical bars. One item is selected or no item is selected.

+

{ x | y | ... }*

+

Optional items are grouped in brackets and separated by vertical bars. A minimum of one or a maximum of all can be selected.

+

[ x | y | ... ]*

+

Optional items are grouped in brackets and separated by vertical bars. One or more items are selected or no item is selected.

+
diff --git a/content/en/docs/ApplicationDev/basics-2.md b/content/en/docs/ApplicationDev/basics-2.md deleted file mode 100644 index 2012a0516a531e33cd0bad7080d1f8d8902a7d6b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/basics-2.md +++ /dev/null @@ -1,3 +0,0 @@ -# Basics - - diff --git a/content/en/docs/ApplicationDev/basics-6.md b/content/en/docs/ApplicationDev/basics-6.md deleted file mode 100644 index a8ceb975ce211619b977be0aed6268dfe6dc8ca3..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/basics-6.md +++ /dev/null @@ -1,4 +0,0 @@ -# Basics - - - diff --git a/content/en/docs/ApplicationDev/basics.md b/content/en/docs/ApplicationDev/basics.md deleted file mode 100644 index 914c9e826fd134d9da8e83a12c7505312a2011ca..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/basics.md +++ /dev/null @@ -1,4 +0,0 @@ -# Basics - - - diff --git a/content/en/docs/ApplicationDev/building-a-software-package-using-osc.md b/content/en/docs/ApplicationDev/building-a-software-package-using-osc.md deleted file mode 100644 index 3f328f5ee04a3b0945112342b25ead7fd758ef2a..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-a-software-package-using-osc.md +++ /dev/null @@ -1,6 +0,0 @@ -# Building a Software Package Using OSC - -This section describes how to use the OBS command line tool OSC to create a project and build an RPM software package. - - - diff --git a/content/en/docs/ApplicationDev/building-an-existing-software-package-9.md b/content/en/docs/ApplicationDev/building-an-existing-software-package-9.md deleted file mode 100644 index 651213b7e304774d3026508b8b14f8477b054d74..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-an-existing-software-package-9.md +++ /dev/null @@ -1,82 +0,0 @@ -# Building an Existing Software Package - -**Creating a Project** - -1. You can copy an existing project to create a subproject of your own. For example, to copy the **zlib** software package in the **openEuler:Mainline** project to the new branch, run the following command: - - ``` - # osc branch openEuler:Mainline zlib - ``` - - If the following information is displayed, a new branch project **home:testUser:branches:openEuler:Mainline** is created for user **testUser**. - - ``` - A working copy of the branched package can be checked out with: - osc co home:testUser:branches:openEuler:Mainline/zlib - ``` - -2. Download the configuration file \(for example, **\_service**\) of the software package to be modified to the local directory. In the preceding command, _testUser_ indicates the account name configured in the **\~/.oscrc** configuration file. Change it based on the actual requirements. - - ``` - # osc co home:testUser:branches:openEuler:Mainline/zlib - ``` - - Information similar to the following is displayed: - - ``` - A home:testUser:branches:openEuler:Mainline - A home:testUser:branches:openEuler:Mainline/zlib - A home:testUser:branches:openEuler:Mainline/zlib/_service - ``` - -3. Go to the local subproject directory and synchronize the remote code of the software package to the local host. - - ``` - # cd home:testUser:branches:openEuler:Mainline/zlib - # osc up -S - ``` - - Information similar to the following is displayed: - - ``` - A _service:tar_scm_kernel_repo:0001-Neon-Optimized-hash-chain-rebase.patch - A _service:tar_scm_kernel_repo:0002-Porting-optimized-longest_match.patch - A _service:tar_scm_kernel_repo:0003-arm64-specific-build-patch.patch - A _service:tar_scm_kernel_repo:zlib-1.2.11-optimized-s390.patch - A _service:tar_scm_kernel_repo:zlib-1.2.11.tar.xz - A _service:tar_scm_kernel_repo:zlib-1.2.5-minizip-fixuncrypt.patch - A _service:tar_scm_kernel_repo:zlib.spec - ``` - - -**Building an RPM Package** - -1. Rename the source file and add the renamed source file to the temporary storage of OBS. - - ``` - # rm -f _service;for file in `ls | grep -v .osc`;do new_file=${file##*:};mv $file $new_file;done - # osc addremove * - ``` - -2. Modify the source code and .spec file, and synchronize all modifications of the corresponding software package to the OBS server. The following is a command example. The information after the **-m** parameter is the commission record. - - ``` - # osc ci -m "commit log" - ``` - -3. Run the following command to obtain the repository name and architecture of the current project: - - ``` - # osc repos home:testUser:branches:openEuler:Mainline - ``` - -4. After the modification is committed, OBS automatically compiles the software package. You can run the following command to view the compilation logs of the corresponding repository. In the command, _standard\_aarch64_ and _aarch64_ indicate the repository name and architecture obtained in the command output. - - ``` - # osc buildlog standard_aarch64 aarch64 - ``` - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >You can also open the created project on the web client to view the build logs. - - diff --git a/content/en/docs/ApplicationDev/building-an-existing-software-package.md b/content/en/docs/ApplicationDev/building-an-existing-software-package.md deleted file mode 100644 index 2cd85096a7937e5d41383b58d02103baefacb1f1..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-an-existing-software-package.md +++ /dev/null @@ -1,48 +0,0 @@ -# Building an Existing Software Package - ->![](public_sys-resources/icon-note.gif) **NOTE:** ->- If you use OBS for the first time, register an individual account on the OBS web page. ->- With this method, you must copy the modified code and commit it to the code directory before performing the following operations. The code directory is specified in the **\_service** file. - -To modify the source code of the existing software and build the modified source file into an RPM software package on the OBS web client, perform the following steps: - -1. Log in to OBS at [http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/). -2. Click **All Projects**. The **All Projects** page is displayed. -3. Click the project to be modified. The project details page is displayed. For example, click **openEuler:Mainline**. -4. On the project details page, search for the software package to be modified and click the software package name. The software package details page is displayed. -5. Click **Branch package**. In the displayed dialog box, click **Accept**, as shown in [Figure 1](#fig77646143214). - - **Figure 1** **Branch Confirmation** page - ![](figures/branch-confirmation-page.png "branch-confirmation-page") - -6. Click the **\_service** file to go to the editing page, modify the file content, and click **Save**. An example of the **\_service** file content is as follows. **userCodeURL** and **userCommitID** indicate the user code path and commission version number or branch, respectively. - - ``` - - - git - userCodeURL - userCommitID - - - bz2 - *.tar - - - ``` - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >Click **Save** to save the **\_service** file. OBS downloads the source code from the specified URL to the software directory of the corresponding OBS project based on the **\_service** file description and replaces the original file. For example, the **kernel** directory of the **openEuler:Mainline** project in the preceding example. - -7. After the files are copied and replaced, OBS automatically starts to build the RPM software package. Wait until the build is complete and view the build status in the status bar on the right. - - **succeeded**: The build is successful. You can click **succeeded** to view the build logs, as shown in [Figure 2](#fig10319114217337). - - **Figure 2** **Succeeded** page - ![](figures/succeeded-page.png "succeeded-page") - - - **failed**: The build failed. Click **failed** to view error logs, locate the fault, and rebuild again. - - **unresolvable**: The build is not performed. The possible cause is that the dependency is missing. - - **disabled**: The build is manually closed or is queuing for build. - - **excluded**: The build is prohibited. The possible cause is that the .spec file is missing or the compilation of the target architecture is prohibited in the .spec file. - - diff --git a/content/en/docs/ApplicationDev/building-an-rpm-package-8.md b/content/en/docs/ApplicationDev/building-an-rpm-package-8.md deleted file mode 100644 index 123ffc9f95feb89454162ee47323f79ed9683299..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-an-rpm-package-8.md +++ /dev/null @@ -1,22 +0,0 @@ -# Building an RPM Package - -Run the following command in the directory where the .spec file is located to build the source code, binary files, and software packages that contain debugging information: - -``` -# rpmbuild -ba hello.spec -``` - -Run the following command to view the execution result: - -``` -# tree ~/rpmbuild/*RPMS - -/home/testUser/rpmbuild/RPMS -└── aarch64 - ├── hello-2.10-1.aarch64.rpm - ├── hello-debuginfo-2.10-1.aarch64.rpm - └── hello-debugsource-2.10-1.aarch64.rpm -/home/testUser/rpmbuild/SRPMS -└── hello-2.10-1.src.rpm -``` - diff --git a/content/en/docs/ApplicationDev/building-an-rpm-package-locally.md b/content/en/docs/ApplicationDev/building-an-rpm-package-locally.md deleted file mode 100644 index 2a13212598a84cfd9c816984174902ac81922972..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-an-rpm-package-locally.md +++ /dev/null @@ -1,6 +0,0 @@ -# Building an RPM Package Locally - -This section uses an example to describe how to build an RPM software package locally. - - - diff --git a/content/en/docs/ApplicationDev/building-an-rpm-package-using-the-obs.md b/content/en/docs/ApplicationDev/building-an-rpm-package-using-the-obs.md deleted file mode 100644 index c98dabbd85e5174b05a8a3a226a6e9195b23052a..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-an-rpm-package-using-the-obs.md +++ /dev/null @@ -1,9 +0,0 @@ -# Building an RPM Package Using the OBS - -This section describes how to build RPM software packages using the OBS on the web page or with OSC. There are two methods: - -- Modifying an existing software package: Modify the source code of an existing software package and build the modified source code into an RPM software package. -- Adding a software package: A new software source file is developed from scratch, and the newly developed source file is used to build an RPM software package. - - - diff --git a/content/en/docs/ApplicationDev/building-an-rpm-package.md b/content/en/docs/ApplicationDev/building-an-rpm-package.md index 4f2789343ff6f9b1ed2632689e486c32d7501fb4..bb3693195b72c438607b408b9abf0c58fffdc6bd 100644 --- a/content/en/docs/ApplicationDev/building-an-rpm-package.md +++ b/content/en/docs/ApplicationDev/building-an-rpm-package.md @@ -1,6 +1,812 @@ -# Building an RPM Package +# Building an RPM Package This section describes how to build an RPM software package on a local PC or using OBS. For details, see [https://gitee.com/openeuler/community/blob/master/zh/contributors/packaging.md](https://gitee.com/openeuler/community/blob/master/zh/contributors/packaging.md). + +- [Building an RPM Package](#building-an-rpm-package) + - [Packaging Description](#packaging-description) + - [Principles](#principles) + - [Packaging Process](#packaging-process) + - [Packaging Options](#packaging-options) + - [Building an RPM Package Locally](#building-an-rpm-package-locally) + - [Setting Up the Development Environment](#setting-up-the-development-environment) + - [Creating a Hello World RPM Package](#creating-a-hello-world-rpm-package) + - [Building an RPM Package Using the OBS](#building-an-rpm-package-using-the-obs) + - [OBS Overview](#obs-overview) + - [Building an RPM Software Package Online](#building-an-rpm-software-package-online) + - [Building a Software Package Using OSC](#building-a-software-package-using-osc) + + + +## Packaging Description + +### Principles +During RPM packaging, the source code needs to be compiled. The compiled configuration files and binary command files need to be placed in proper positions. The RPM packages need to be tested as required. A workspace is required for these operations. The **rpmbuild** command uses a set of standard workspaces. + +``` +# rpmdev-setuptree +``` + +The **rpmdev-setuptree** command is used to install rpmdevtools. After the command is executed, the **rpmbuild** folder is generated in the **/root** directory \(or the **/home/**_username_ directory for non-root users\). The directory structure is as follows: + +``` +# tree rpmbuild +rpmbuild +├── BUILD +├── RPMS +├── SOURCES +├── SPECS +└── SRPMS +``` + +The content is described as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Content

+

Macro Code

+

Name

+

Function

+

~/rpmbuild/BUILD

+

%_builddir

+

Build directory.

+

The source code package is decompressed and compiled in a subdirectory of the directory.

+

~/rpmbuild/RPMS

+

%_rpmdir

+

Standard RPM package directory.

+

The binary RPM package is generated and stored in this directory.

+

~/rpmbuild/SOURCES

+

%_sourcedir

+

Source code directory.

+

The source code package (for example, .tar package) and all patches are stored in this directory.

+

~/rpmbuild/SPECS

+

%_specdir

+

Spec file directory.

+

The RPM package configuration file (.spec) is stored in this directory.

+

~/rpmbuild/SRPMS

+

%_srcrpmdir

+

Source code RPM package directory.

+

The source code RPM package (SRPM) is stored in this directory.

+
+ +The **\~/rpmbuild/SPECS** directory contains the configuration file of the RPM package, which is the drawing of the RPM package. This file tells the **rpmbuild** command how to build the RPM package. The **Macro Code** column contains the corresponding directories in the .spec file, which is similar to the macro or global variable in the programming language. + +### Packaging Process +The packaging process is as follows: + +1. Place the source code in **%\_sourcedir**. +2. Compile the source code in **%\_builddir**. Generally, the source code is compressed and needs to be decompressed first. +3. Install the RPM package. The installation is similar to pre-assembling the software package. Copy the contents \(such as binary files, configuration files, and man files\) that should be contained in the software package to **%\_buildrootdir** and assemble the contents based on the actual directory structure after installation. For example, if binary commands are stored in **/usr/bin**, copy the directory structure to **%\_buildrootdir**. +4. Perform necessary configurations, such as preparations before installation and cleanup after installation. These are configured in the SPEC file to tell the **rpmbuild** command how to build. +5. Check whether the software is running properly. +6. The generated RPM package is stored in **%\_rpmdir**, and the source code package is stored in **%\_srpmdir**. + +In the SPEC file, each phase is described as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Phase

+

Directory to Be Read

+

Directory to Which Data Is Written

+

Action

+

%prep

+

%_sourcedir

+

%_builddir

+

Read the source code and patch in the %_sourcedir directory. Then, decompress the source code to the %_builddir subdirectory and apply all patches.

+

%build

+

%_builddir

+

%_builddir

+

Compile files in the %_builddir build directory. Run a command similar to ./configure && make.

+

%install

+

%_builddir

+

%_buildrootdir

+

Read files in the %_builddir build directory and install them to the %_buildrootdir directory. These files are generated after the RPM is installed.

+

%check

+

%_builddir

+

%_builddir

+

Check whether the software is running properly. Run a command similar to make test.

+

bin

+

%_buildrootdir

+

%_rpmdir

+

Read files in the %_buildrootdir final installation directory to create RPM packages in the %_rpmdir directory. In this directory, RPM packages of different architectures are stored in different subdirectories. The noarch directory stores RPM packages applicable to all architectures. These RPM files are the RPM packages that are finally installed by users.

+

src

+

%_sourcedir

+

%_srcrpmdir

+

Create the source code RPM package (SRPM for short, with the file name extension .src.rpm) and save it to the %_srcrpmdir directory. The SRPM package is usually used to review and upgrade software packages.

+
+ +### Packaging Options + +Run the **rpmbuild** command to build the software package. The **rpmbuild** command can be used to build software packages by building .spec, .tar, and source files. + +The format of the **rpmbuild** command is rpmbuild \[_option_...\] + +[Table 1](#table1342946175212) describes the common rpmbuild packaging options. + +**Table 1** rpmbuild Packaging Options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

option Value

+

Description

+

-bp specfile

+

Starts build from the %prep phase of the specfile (decompress the source code package and install the patch).

+

-bc specfile

+

Starts build from the %build phase of the specfile.

+

-bi specfile

+

Starts build from the %install phase of the specfile.

+

-bl specfile

+

Starts check from the %file phase of the specfile.

+

-ba specfile

+

Uses the specfile to build the source code package and binary package.

+

-bb specfile

+

Uses the specfile to build the binary package.

+

-bs specfile

+

Uses the specfile to build the source code package.

+

-rp sourcefile

+

Starts build from the %prep phase of the sourcefile (decompress the source code package and install the patch).

+

-rc sourcefile

+

Starts build from the %build phase of the sourcefile.

+

-ri sourcefile

+

Starts build from the %install phase of the sourcefile.

+

-rl sourcefile

+

Starts build from the %file phase of the sourcefile.

+

-ra sourcefile

+

Uses the sourcefile to build the source code package and binary package.

+

-rb sourcefile

+

Uses the sourcefile to build the binary package.

+

-rs sourcefile

+

Uses the sourcefile to build the source code package.

+

-tp tarfile

+

Starts build from the %prep phase of the tarfile (decompress the source code package and install the patch).

+

-tc tarfile

+

Starts build from the %build phase of the tarfile.

+

-ti tarfile

+

Starts build from the %install phase of the tarfile.

+

-ta tarfile

+

Uses the tarfile to build the source code package and binary package.

+

-tb tarfile

+

Uses the tarfile to build the binary package.

+

-ts tarfile

+

Uses the tarfile to build the source code package.

+

\-\-buildroot=DIRECTORY

+

During the build, uses DIRECTORY to overwrite the default /root directory.

+

\-\-clean

+

Deletes the files in the BUILD directory.

+

\-\-nobuild

+

No actual build steps are performed. It can be used to test the .spec file.

+

\-\-noclean

+

Skips the %clean phase of the .spec file (even if it does exist).

+

\-\-nocheck

+

Skips the %check phase of the .spec file (even if it does exist).

+

\-\-dbpath DIRECTORY

+

Uses the database in DIRECTORY instead of the default directory /var/lib/rpm.

+

\-\-root DIRECTORY

+

Sets DIRECTORY to the highest level. The default value is /, indicating the highest level.

+

\-\-rebuild sourcefile

+

Installs the specified source code package sourcefile, that is, start preparation, compilation, and installation of the source code package.

+

\-\-recompile sourcefile

+

Builds a new binary package based on \-\-recompile. When the build is complete, the build directory, source code, and .spec file are deleted.

+

The deletion effect is the same as that of \-\-clean.

+

-?, \-\-help

+

Displays detailed help information.

+

\-\-version

+

Displays detailed version information.

+
+ +## Building an RPM Package Locally + +This section uses an example to describe how to build an RPM software package locally. + + + +### Setting Up the Development Environment + +#### Prerequisites +You have obtained the **root** permission, and have configured a repo source for openEuler. + +#### Procedure +You can use the DNF tool to install rpmdevtools, including the **rpm-build** command and related dependencies \(such as make and gdb\). Run the following command: + +``` +# dnf install rpmdevtools* +``` + +### Creating a Hello World RPM Package + +The following uses the packaging process of the GNU Hello World project as an example. The package contains the most common peripheral components related to the typical Free and Open Source Software \(FOSS\) project, including the configuration, compilation, and installation environments, documents, and internationalization \(i18n\) information. + + + +#### Obtaining the Source Code + +Run the following command to download the source code of the official example: + +``` +# cd ~/rpmbuild/SOURCES +# wget http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz +``` + +#### Editing the SPEC File + +Run the following command to create the .spec file: + +``` +# vi hello.spec +``` + +Write the corresponding content to the file and save the file. The following is an example of the file content. Modify the corresponding fields based on the actual requirements. + +``` +Name: hello +Version: 2.10 +Release: 1%{?dist} +Summary: The "Hello World" program from GNU +Summary(zh_CN): GNU Hello World program +License: GPLv3+ +URL: http://ftp.gnu.org/gnu/hello +Source0: http://ftp.gnu.org/gnu/hello/%{name}-%{version}.tar.gz + +BuildRequires: gettext +Requires(post): info +Requires(preun): info + +%description +The "Hello World" program, done with all bells and whistles of a proper FOSS +project, including configuration, build, internationalization, help files, etc. + +%description -l zh_CN +The Hello World program contains all parts required by the FOSS project, including configuration, build, i18n, and help files. + +%prep +%setup -q + +%build +%configure +make %{?_smp_mflags} + +%install +make install DESTDIR=%{buildroot} +%find_lang %{name} +rm -f %{buildroot}/%{_infodir}/dir + +%post +/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || : + +%preun +if [ $1 = 0 ] ; then +/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || : +fi + +%files -f %{name}.lang +%doc AUTHORS ChangeLog NEWS README THANKS TODO +%license COPYING +%{_mandir}/man1/hello.1.* +%{_infodir}/hello.info.* +%{_bindir}/hello + +%changelog +* Thu Dec 26 2019 Your Name - 2.10-1 +- Update to 2.10 +* Sat Dec 3 2016 Your Name - 2.9-1 +- Update to 2.9 +``` + +- The **Name** tag indicates the software name, the **Version** tag indicates the version number, and the **Release** tag indicates the release number. +- The **Summary** tag is a brief description. The first letter of the tag must be capitalized to prevent the rpmlint tool \(packaging check tool\) from generating alarms. +- The **License** tag describes the protocol version of the software package. The packager is responsible for checking the license status of the software, which can be implemented by checking the source code or license file or communicating with the author. +- The **Group** tag is used to classify software packages by **/usr/share/doc/rpm-/GROUPS**. Currently, this tag has been discarded. However, the VIM template still has this tag. You can delete it. However, adding this tag does not affect the system. The **%changelog** tag should contain the log of changes made for each release, especially the description of the upstream security/vulnerability patches. The **%changelog** tag should contain the version string to avoid the rpmlint tool from generating alarms. +- If multiple lines are involved, such as %changelog or %description, start from the next line of the instruction and end with a blank line. +- Some unnecessary lines \(such as BuildRequires and Requires\) can be commented out with a number sign \(\#\) at the beginning of the lines. +- The default values of **%prep**, **%build**, **%install**, and **%file** are retained. + +#### Building an RPM Package + +Run the following command in the directory where the .spec file is located to build the source code, binary files, and software packages that contain debugging information: + +``` +# rpmbuild -ba hello.spec +``` + +Run the following command to view the execution result: + +``` +# tree ~/rpmbuild/*RPMS + +/home/testUser/rpmbuild/RPMS +└── aarch64 + ├── hello-2.10-1.aarch64.rpm + ├── hello-debuginfo-2.10-1.aarch64.rpm + └── hello-debugsource-2.10-1.aarch64.rpm +/home/testUser/rpmbuild/SRPMS +└── hello-2.10-1.src.rpm +``` + +## Building an RPM Package Using the OBS + +This section describes how to build RPM software packages using the OBS on the web page or with OSC. There are two methods: + +- Modifying an existing software package: Modify the source code of an existing software package and build the modified source code into an RPM software package. +- Adding a software package: A new software source file is developed from scratch, and the newly developed source file is used to build an RPM software package. + + + +### OBS Overview + +OBS is a general compilation framework based on the openSUSE distribution. It is used to build source code packages into RPM software packages or Linux images. OBS uses the automatic distributed compilation mode and supports the compilation of images and installation packages of multiple Linux OS distributions \(such as openEuler, SUSE, and Debian\) on multiple architecture platforms \(such as x86 and ARM64\). + +OBS consists of the backend and frontend. The backend implements all core functions. The frontend provides web applications and APIs for interaction with the backend. In addition, OBS provides an API command line client OSC, which is developed in an independent repository. + +OBS uses the project organization software package. Basic permission control, related repository, and build targets \(OS and architecture\) can be defined in the project. A project can contain multiple subprojects. Each subproject can be configured independently to complete a task. + +### Building an RPM Software Package Online + +This section describes how to build an RPM software package online on OBS. + + + +#### Building an Existing Software Package + +>![](public_sys-resources/icon-note.gif) **NOTE:** +>- If you use OBS for the first time, register an individual account on the OBS web page. +>- With this method, you must copy the modified code and commit it to the code directory before performing the following operations. The code directory is specified in the **\_service** file. + +To modify the source code of the existing software and build the modified source file into an RPM software package on the OBS web client, perform the following steps: + +1. Log in to OBS at [http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/). +2. Click **All Projects**. The **All Projects** page is displayed. +3. Click the project to be modified. The project details page is displayed. For example, click **openEuler:Mainline**. +4. On the project details page, search for the software package to be modified and click the software package name. The software package details page is displayed. +5. Click **Branch package**. In the displayed dialog box, click **Accept**, as shown in [Figure 1](#fig77646143214). + + **Figure 1** **Branch Confirmation** page + ![](figures/branch-confirmation-page.png "branch-confirmation-page") + +6. Click the **\_service** file to go to the editing page, modify the file content, and click **Save**. An example of the **\_service** file content is as follows. _userCodeURL_ and _userCommitID_ indicate the user code path and commission version number or branch, respectively. + + ``` + + + git + userCodeURL + userCommitID + + + bz2 + *.tar + + + ``` + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >Click **Save** to save the **\_service** file. OBS downloads the source code from the specified URL to the software directory of the corresponding OBS project based on the **\_service** file description and replaces the original file. For example, the **kernel** directory of the **openEuler:Mainline** project in the preceding example. + +7. After the files are copied and replaced, OBS automatically starts to build the RPM software package. Wait until the build is complete and view the build status in the status bar on the right. + - **succeeded**: The build is successful. You can click **succeeded** to view the build logs, as shown in [Figure 2](#fig10319114217337). + + **Figure 2** **Succeeded** page + ![](figures/succeeded-page.png "succeeded-page") + + - **failed**: The build failed. Click **failed** to view error logs, locate the fault, and rebuild again. + - **unresolvable**: The build is not performed. The possible cause is that the dependency is missing. + - **disabled**: The build is manually closed or is queuing for build. + - **excluded**: The build is prohibited. The possible cause is that the .spec file is missing or the compilation of the target architecture is prohibited in the .spec file. + + +#### Adding a Software Package + +To add a new software package on the OBS web page, perform the following steps: + +1. Log in to the OBS console. +2. Select a project based on the dependency of the new software package. That is, click **All Projects** and select the corresponding project, for example, **openEuler:Mainline**. +3. Click a software package in the project. The software package details page is displayed. +4. Click **Branch package**. On the confirmation page that is displayed, click **Accept**. +5. Click **Delete package** to delete the software package in the new subproject, as shown in [Figure 3](#fig18306181103615). + + **Figure 3** Deleting a software package from a subproject + ![](figures/deleting-a-software-package-from-a-subproject.png "deleting-a-software-package-from-a-subproject") + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >The purpose of creating a project by using existing software is to inherit the dependency such as the environment. Therefore, you need to delete these files. + +6. Click **Create Package**. On the page that is displayed, enter the software package name, title, and description, and click **Create** to create a software package, as shown in [Figure 4](#fig6762111693811) and [Figure 5](#fig18351153518389). + + **Figure 4** **Create Package** page + ![](figures/create-package-page.png "create-package-page") + + **Figure 5** Creating a software package + ![](figures/creating-a-software-package.png "creating-a-software-package") + +7. Click **Add file** to upload the .spec file and the file to be compiled \(specified in the .spec file\), as shown in [Figure 6](#fig1475845284011). + + **Figure 6** **Add file** page + ![](figures/add-file-page.png "add-file-page") + +8. After the file is uploaded, OBS automatically starts to build the RPM software package. Wait until the build is complete and view the build status in the status bar on the right. + - **succeeded**: The build is successful. You can click **succeeded** to view the build logs. + - **failed**: The build failed. Click **failed** to view error logs, locate the fault, and rebuild again. + - **unresolvable**: The build is not performed. The possible cause is that the dependency is missing. + - **disabled**: The build is manually closed or is queuing for build. + - **excluded**: The build is prohibited. The possible cause is that the .spec file is missing or the compilation of the target architecture is prohibited in the .spec file. + + +#### Obtaining the Software Package + +After the RPM software package is built, perform the following operations to obtain the RPM software package on the web page: + +1. Log in to the OBS console. +2. Click **All Projects** and find the project corresponding to the required software package, for example, **openEuler:Mainline**. +3. Click the name of the required software package in the project. The software package details page is displayed, for example, the **kernel** page in the preceding example. + +1. Click the **Repositories** tab. On the software repository management page that is displayed, click **Enable** in **Publish Flag** to enable the RPM software package download function \(the status changes from ![](figures/en-us_image_0229243704.png) to ![](figures/en-us_image_0229243702.png)\), as shown in [Figure 7](#fig17480830144217). + + **Figure 7** **Repositories** page + ![](figures/repositories-page.png "repositories-page") + +2. Click the project name in the **Repository** column. On the RPM software package download page that is displayed, click **Download** on the right of the RPM software package to download the RPM software package, as shown in [Figure 8](#fig12152145615438). + + **Figure 8** RPM software package download page + ![](figures/rpm-software-package-download-page.png "rpm-software-package-download-page") + + +### Building a Software Package Using OSC + +This section describes how to use the OBS command line tool OSC to create a project and build an RPM software package. + + + +#### Installing and Configuring the OSC + +##### Prerequisites +You have obtained the **root** permission, and have configured a repo source for openEuler. + +##### Procedure +1. Install the OSC command line tool and its dependency as the **root** user. + + ``` + # dnf install osc build + ``` + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >The compilation of RPM software packages depends on build. + +2. Configure the OSC. + 1. Run the following command to open the **\~/.oscrc** file: + + ``` + # vi ~/.oscrc + ``` + + 2. Add the **user** and **pass** fields to **\~/.oscrc**. The values of _userName_ and _passWord_ are the account and password registered on the OBS website \([http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/)\). + + ``` + [general] + apiurl = http://openeuler-build.huawei.com/ + no_verify = 1 + [http://openeuler-build.huawei.com/] + user=userName + pass=passWord + ``` + + +#### Building an Existing Software Package + +**Creating a Project** + +1. You can copy an existing project to create a subproject of your own. For example, to copy the **zlib** software package in the **openEuler:Mainline** project to the new branch, run the following command: + + ``` + # osc branch openEuler:Mainline zlib + ``` + + If the following information is displayed, a new branch project **home:testUser:branches:openEuler:Mainline** is created for user **testUser**. + + ``` + A working copy of the branched package can be checked out with: + osc co home:testUser:branches:openEuler:Mainline/zlib + ``` + +2. Download the configuration file \(for example, **\_service**\) of the software package to be modified to the local directory. In the preceding command, _testUser_ indicates the account name configured in the **\~/.oscrc** configuration file. Change it based on the actual requirements. + + ``` + # osc co home:testUser:branches:openEuler:Mainline/zlib + ``` + + Information similar to the following is displayed: + + ``` + A home:testUser:branches:openEuler:Mainline + A home:testUser:branches:openEuler:Mainline/zlib + A home:testUser:branches:openEuler:Mainline/zlib/_service + ``` + +3. Go to the local subproject directory and synchronize the remote code of the software package to the local host. + + ``` + # cd home:testUser:branches:openEuler:Mainline/zlib + # osc up -S + ``` + + Information similar to the following is displayed: + + ``` + A _service:tar_scm_kernel_repo:0001-Neon-Optimized-hash-chain-rebase.patch + A _service:tar_scm_kernel_repo:0002-Porting-optimized-longest_match.patch + A _service:tar_scm_kernel_repo:0003-arm64-specific-build-patch.patch + A _service:tar_scm_kernel_repo:zlib-1.2.11-optimized-s390.patch + A _service:tar_scm_kernel_repo:zlib-1.2.11.tar.xz + A _service:tar_scm_kernel_repo:zlib-1.2.5-minizip-fixuncrypt.patch + A _service:tar_scm_kernel_repo:zlib.spec + ``` + + +**Building an RPM Package** + +1. Rename the source file and add the renamed source file to the temporary storage of OBS. + + ``` + # rm -f _service;for file in `ls | grep -v .osc`;do new_file=${file##*:};mv $file $new_file;done + # osc addremove * + ``` + +2. Modify the source code and .spec file, and synchronize all modifications of the corresponding software package to the OBS server. The following is a command example. The information after the **-m** parameter is the commission record. + + ``` + # osc ci -m "commit log" + ``` + +3. Run the following command to obtain the repository name and architecture of the current project: + + ``` + # osc repos home:testUser:branches:openEuler:Mainline + ``` + +4. After the modification is committed, OBS automatically compiles the software package. You can run the following command to view the compilation logs of the corresponding repository. In the command, *standard\_aarch64* and _aarch64_ indicate the repository name and architecture obtained in the command output. + + ``` + # osc buildlog standard_aarch64 aarch64 + ``` + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >You can also open the created project on the web client to view the build logs. + + +#### Adding a Software Package + +To use the OSC tool of OBS to add a new software package, perform the following steps: + +**Creating a Project** + +1. Create a project based on the dependency of the new software package and a proper project. For example, to create a project based on **zlib** of the **openEuler:Mainline** project, run the following command \(**zlib** is any software package in the project\): + + ``` + # osc branch openEuler:Mainline zlib + ``` + +2. Delete unnecessary software packages added during project creation. For example, to delete the **zlib** software package, run the following command: + + ``` + # cd home:testUser:branches:openEuler:Mainline + # osc rm zlib + # osc commit -m "commit log" + ``` + +3. Create a software package in your own project. For example, to add the **my-first-obs-package** software package, run the following command: + + ``` + # mkdir my-first-obs-package + # cd my-first-obs-package + ``` + + +**Building an RPM Package** + +1. Add the prepared source file and .spec file to the software package directory. +2. Modify the source code and .spec file, and upload all files of the corresponding software package to the OBS server. The following is a command example. The information after the **-m** parameter is the commission record. + + ``` + # cd home:testUser:branches:openEuler:Mainline + # osc add my-first-obs-package + # osc ci -m "commit log" + ``` + +3. Run the following command to obtain the repository name and architecture of the current project: + + ``` + # osc repos home:testUser:branches:openEuler:Mainline + ``` + +4. After the modification is committed, OBS automatically compiles the software package. You can run the following command to view the compilation logs of the corresponding repository. In the command, _standard\_aarch64_ and _aarch64_ indicate the repository name and architecture obtained in the command output. + + ``` + # cd home:testUser:branches:openEuler:Mainline/my-first-obs-package + # osc buildlog standard_aarch64 aarch64 + ``` + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >You can also open the created project on the web client to view the build logs. + + +#### Obtaining the Software Package + +After the RPM software package is built, run the following command to obtain the RPM software package using the OSC: + +``` +# osc getbinaries home:testUser:branches:openEuler:Mainline my-first-obs-package standard_aarch64 aarch64 +``` + +The parameters in the command are described as follows. You can modify the parameters according to the actual situation. + +- _home:testUser:branches:openEuler:Mainline_: name of the project to which the software package belongs. +- _my-first-obs-package_: name of the software package. +- _standard\_aarch64_: repository name. +- _aarch64_: repository architecture name. + +>![](public_sys-resources/icon-note.gif) **NOTE:** +>You can also obtain the software package built using OSC from the web page. For details, see [Obtaining the Software Package](#obtaining-the-software-package). diff --git a/content/en/docs/ApplicationDev/building-an-rpm-software-package-online.md b/content/en/docs/ApplicationDev/building-an-rpm-software-package-online.md deleted file mode 100644 index ef8ee2d13f77da3145c00cc7541b725a9cdc0150..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/building-an-rpm-software-package-online.md +++ /dev/null @@ -1,6 +0,0 @@ -# Building an RPM Software Package Online - -This section describes how to build an RPM software package online on OBS. - - - diff --git a/content/en/docs/ApplicationDev/class-library.md b/content/en/docs/ApplicationDev/class-library.md deleted file mode 100644 index 74271b894987de4615808c0eb184c4f5a63c2cc0..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/class-library.md +++ /dev/null @@ -1,51 +0,0 @@ -# Class Library - -The Java class library is implemented as a package, which is a collection of classes and interfaces. The Java compiler generates a bytecode file for each class, and the file name is the same as the class name. Therefore, conflicts may occur between classes with the same name. In the Java language, a group of classes and interfaces are encapsulated in a package. Class namespaces can be effectively managed by package. Classes in different packages do not conflict even if they have the same name. This solves the problem of conflicts between classes with the same name and facilitates the management of a large number of classes and interfaces. It also ensures the security of classes and interfaces. - -In addition to many packages provided by Java, developers can customize packages by collecting compiled classes and interfaces into a package for future use. - -Before using a custom package, you need to declare the package. - -## Package Declaration - -The declaration format of a package is package pkg1\[.pkg2\[.pkg3...\]\]. - -To declare a package, you must create a directory. The subdirectory name must be the same as the package name. Then declare the package at the beginning of the class file that needs to be placed in the package, indicating that all classes of the file belong to the package. The dot \(.\) in the package declaration indicates the directory hierarchy. If the source program file does not contain the package statement, the package is specified as an anonymous package. An anonymous package does not have a path. Generally, Java still stores the classes in the source file in the current working directory \(that is, the directory where the Java source files are stored\). - -The package declaration statement must be added to the beginning of the source program file and cannot be preceded by comments or spaces. If you use the same package declaration statement in different source program files, you can include the classes in different source program files in the same package. - -## Package Reference - -In Java, there are two methods to use the common classes in the package provided by Java or the classes in the custom package. - -- Add the package name before the name of the class to be referenced. - - For example, name.A obj=new name.A \(\) - - **name** indicates the package name, **A** indicates the class name, and **obj** indicates the object. This string indicates that class **A** in the **name** package is used to define an object **obj** in the program. - - Example: Create a test object of the Test class in the example package. - - ``` - example.Test test = new example.Test(); - ``` - -- Use **import** at the beginning of the file to import the classes in the package. - - The format of the **import** statement is import pkg1\[.pkg2\[.pkg3...\]\].\(classname | \*\). - - **pkg1\[.pkg2\[.pkg3...\]\]** indicates the package level, and **classname** indicates the class to be imported. If you want to import multiple classes from a package, you can use the wildcard \(\*\) instead. - - Example: Import the **Test** class in the **example** package. - - ``` - import example.Test; - ``` - - Example: Import the entire **example** package. - - ``` - import example.*; - ``` - - diff --git a/content/en/docs/ApplicationDev/common-jdk-options.md b/content/en/docs/ApplicationDev/common-jdk-options.md deleted file mode 100644 index 4cefe2a0c358e87d084c66c7c19589cb138cd516..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/common-jdk-options.md +++ /dev/null @@ -1,253 +0,0 @@ -# Common JDK Options - -## Javac Compilation Options - -The command format for javac compilation is as follows: **javac** \[_options_\] \[_sourcefiles_\] \[_classes_\] \[@_argfiles_\] - -In the preceding information: - -_options_: command options. - -_sourcefiles_: one or more source files to be compiled. - -_classes_: one or more classes to be processed as comments. - -@_argfiles_: one or more files that list options and source files. The **-J** option is not allowed in these files. - -Javac is a Java compiler. It has many _options_, but most of them are not commonly used. [Table 1](#table1342946175212) describes the common options values. - -**Table 1** Common javac options - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

options Value

-

Description

-

Example

-

-d path

-

Path for storing the generated class files.

-

By default, the class files generated after compilation are in the same path as the source file. You can use the -d option to export the class files to the specified path.

-

# Use the -d option to export all class files to the bin directory.

-

javac /src/*.java -d /bin

-

-s path

-

Path for storing the generated source files.

-

-

-

-cp path or -classpath path

-

Searches for the class files required for compilation and specifies the location of the class files.

-

# In the Demo, the getLine() method in the GetStringDemo class needs to be invoked. The .class file compiled by the GetStringDemo class is stored in the bin directory.

-

javac -cp bin Demo.java -d bin

-

-verbose

-

Outputs information about the operations being performed by the compiler, such as loaded class information and compiled source file information.

-

# Display information about the operations that are being performed by the compiler.

-

javac -verbose -cp bin Demo.java

-

-source sourceversion

-

Specifies the location of the input source files to be searched for.

-

-

-

-sourcepath path

-

Searches for source files (Java files) required for compilation and specifies the location of the source files to be searched for, for example, JAR, ZIP, or other directories that contain Java files.

-

-

-

-target targetversion

-

Generates class files of a specific JVM version. The value can be 1.1, 1.2, 1.3, 1.4, 1.5 (or 5), 1.6 (or 6), 1.7 (or 7), or 1.8 (or 8). The default value of targetversion is related to sourceversion of the -source option. The options of sourceversion are as follows:

-
  • 1.2, corresponding to target version 1.4
  • 1.3, corresponding to target version 1.4
  • 1.5, 1.6, 1.7, and unspecified, corresponding to target version 1.8
  • For other values, the values of targetversion and sourceversion are the same.
-

-

-
- -## Java Running Options - -The Java running format is as follows: - -Running class file: **java** \[_options_\] _classesname_ \[args\] - -Running Java file: **java** \[_options_\] -jar _filename_ \[args\] - -In the preceding information: - -_options_: command options, which are separated by spaces. - -_classname_: name of the running .class file. - -_filename_: name of the running .jar file. - -args: parameters transferred to the main\(\) function. The parameters are separated by spaces. - -Java is a tool for running Java applications. It has many _options_, but most of them are not commonly used. [Table 2](#table371918587238) describes the common options. - -**Table 2** Common Java running options - - - - - - - - - - - - - - - - -

options Value

-

Description

-

Example

-

-cp path or -classpath path

-

Specifies the location of the file to be run and the class path to be used, including the .jar, .zip, and class file directories.

-

If there are multiple paths, separate them with colons (:).

-

-

-

-verbose

-

Outputs information about the operations being performed by the compiler, such as loaded class information and compiled source file information.

-

# Display information about the operations that are being performed by the compiler.

-

java -verbose -cp bin Demo.java

-
- -## JAR Options - -The JAR command format is as follows: **jar** \{c | t | x | u\}\[vfm0M\] \[_jarfile_\] \[_manifest_\] \[-C _dir_\] _file_... - -[Table 3](#table3691718114817) describes the parameters in the **jar** command. - -**Table 3** JAR parameter description - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Parameter

-

Description

-

Example

-

c

-

Creates a JAR package.

-

# Compress the hello.class files in the current directory into Hello.jar. The compression process is not displayed. If the Hello.jar files do not exist, create them. Otherwise, clear the directory.

-

jar cf Hello.jar hello.class

-

t

-

Lists the contents of a JAR package.

-

# List the files contained in Hello.jar.

-

jar tf Hello.jar

-

x

-

Decompresses a JAR package.

-

# Decompress Hello.jar to the current directory. No information is displayed.

-

jar xf Hello.jar

-

u

-

Updates the existing JAR package, for example, add files to the JAR package.

-

-

-

v

-

Generates a detailed report and prints it to the standard output.

-

# Compress the hello.class files in the current directory into Hello.jar and display the compression process. If the Hello.jar files do not exist, create them. Otherwise, clear the directory.

-

jar cvf Hello.jar hello.class

-

f

-

Specifies the name of a JAR package. This parameter is mandatory.

-

-

-

m

-

Specifies the manifest file to be contained.

-

-

-

0

-

If this parameter is not set, the generated JAR package is larger but faster than that generated when this parameter is not set.

-

-

-

M

-

If the manifest file of all items is not generated, this parameter will be ignored.

-

# Compress the hello.class files in the current directory into Hello.jar and display the compression process. If the Hello.jar files do not exist, create them. Otherwise, clear the directory. However, the manifest file is not generated when Hello.jar is created.

-

jar cvfM Hello.jar hello.class

-

jarfile

-

JAR package, which is an auxiliary parameter of the f parameter.

-

-

-

manifest

-

Manifest file in .mf format, which is an auxiliary parameter of the m parameter.

-

-

-

-C dir

-

Runs the jar command in the specified dir. This command can be used only with parameters c and t.

-

-

-

file

-

Specifies the file or path list. All files in the file or path (including those in the recursive path) are compressed into the JAR package or the JAR package is decompressed to the path.

-

# Compress all class files in the current directory into Hello.jar and display the compression process. If the Hello.jar files do not exist, create them. Otherwise, clear the directory.

-

jar cvf Hello.jar *.class

-
- diff --git a/content/en/docs/ApplicationDev/compilation-options.md b/content/en/docs/ApplicationDev/compilation-options.md deleted file mode 100644 index 50c4a9dde35392b764f0a6979ea4dabb1c8ea6a2..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/compilation-options.md +++ /dev/null @@ -1,113 +0,0 @@ -# Compilation Options - -GCC compilation command format: **gcc** \[_options_\] \[_filenames_\] - -In the preceding information: - -_options_: compilation options. - -_filenames_: file name. - -GCC is a powerful compiler. It has many _options_, but most of them are not commonly used. [Table 1](#table1342946175212) describes the common _options_. - -**Table 1** Common GCC compilation options - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

options Value

-

Description

-

Example

-

-c

-

Compiles and assembles specified source files to generate target files without linking them. It is usually used to compile subprogram files.

-

# Use the -c option to compile the source files test1.c and test2.c.

-

gcc -c test1.c test2.c

-

-S

-

Compiles the specified source file to generate an assembly language file with the .s suffix but without assembling it.

-

# Use the compiler to preprocess circle.c, translate it into assembly language, and store the result in circle.s.

-

gcc -S circle.c

-

-E

-

Preprocesses specified source files without compiling them.

-

By default, the output of the preprocessor is imported to a standard output stream, such as a display. You can use the -o option to import it to an output file.

-

# Export the preprocessing result to the circle.i file.

-

gcc -E circle.c -o circle.i

-

-o file

-

Generates a specified output file when an executable file is generated. The name must be different from that of the source file. If this option is not given, GCC generates the preset executable file a.out.

-

# Use the source file as the input file and the executable file as the output file. That is, compile the entire program.

-

gcc main.c func.c -o app.out

-

-g

-

Contains standard debugging information in executable programs.

-

-

-

-L libary_path

-

Adds the library_path to the library file search path list.

-

-

-

-Ilibrary

-

Searches for the specified function library during linking.

-

When GCC is used to compile and link programs, GCC links libc.a or libc.so by default. However, other libraries (such as non-standard libraries and third-party libraries) need to be manually added.

-

# Use the -l option to link the math library.

-

gcc main.c -o main.out -lm

-
NOTE:

The file name of the math library is libm.a. The prefix lib and suffix .a are standard, and m is the basic name. GCC automatically adds these prefixes and suffixes to the basic name following the -l option. In this example, the basic name is m.

-
-

-I head_path

-

Adds the head_path to the search path list of the header file.

-

-

-

-static

-

Performs static compilation and links static libraries. Do not link dynamic libraries.

-

-

-

-shared

-

Default option, which can be omitted.

-
  • A dynamic library file can be generated.
  • During dynamic compilation, the dynamic library is preferentially linked. The static library with the same name is linked only when there is no dynamic library.
-

-

-

-fPIC (or -fpic)

-

Generates location-independent target code that uses a relative address. Generally, the -static option is used to generate a dynamic library file from the PIC target file.

-

-

-
- diff --git a/content/en/docs/ApplicationDev/compilation-process.md b/content/en/docs/ApplicationDev/compilation-process.md deleted file mode 100644 index e0a3b897437eb8877af17a3a4fe49d2216661a80..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/compilation-process.md +++ /dev/null @@ -1,11 +0,0 @@ -# Compilation Process - -Using GCC to generate executable files from source code files requires preprocessing, compilation, assembly, and linking. - -1. Preprocessing: Preprocess the source program \(such as a .c file\) to generate an .i file. -2. Compilation: Compile the preprocessed .i file into an assembly language to generate an .s file. -3. Assemble: Assemble the assembly language file to generate the target file .o. -4. Linking: Link the .o files of each module to generate an executable program file. - -The .i, .s, and .o files are intermediate or temporary files. If the GCC is used to compile programs in C language at a time, these files will be deleted. - diff --git a/content/en/docs/ApplicationDev/compiling-a-java-program-with-a-package.md b/content/en/docs/ApplicationDev/compiling-a-java-program-with-a-package.md deleted file mode 100644 index 8e2eba705483fceef6a08e72fd5d0c17b2061ce8..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/compiling-a-java-program-with-a-package.md +++ /dev/null @@ -1,95 +0,0 @@ -# Compiling a Java Program with a Package - -1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. Create the **/home/code/Test/my/example**, **/home/code/Hello/world/developers**, and **/home/code/Hi/openos/openeuler** subdirectories in the directory to store source files. - - ``` - cd /home/code - - mkdir -p Test/my/example - mkdir -p Hello/world/developers - mkdir -p Hi/openos/openeuler - ``` - -2. Run the **cd** command to go to the **/home/code/Test/my/example** directory and create **Test.java**. - - ``` - cd /home/code/Test/my/example - vi Test.java - ``` - - The following is an example of the Test.java code: - - ``` - package my.example; - import world.developers.Hello; - import openos.openeuler.Hi; - public class Test { - public static void main(String[] args) { - Hello me = new Hello(); - me.hello(); - Hi you = new Hi(); - you.hi(); - } - } - ``` - -3. Run the **cd** command to go to the **/home/code/Hello/world/developers** directory and create **Hello.java**. - - ``` - cd /home/code/Hello/world/developers - vi Hello.java - ``` - - The following is an example of the Hello.java code: - - ``` - package world.developers; - public class Hello { - public void hello(){ - System.out.println("Hello, openEuler."); - } - } - ``` - -4. Run the **cd** command to go to the **/home/code/Hi/openos/openeuler** directory and create **Hi.java**. - - ``` - cd /home/code/Hi/openos/openeuler - vi Hi.java - ``` - - The following is an example of the Hi.java code: - - ``` - package openos.openeuler; - public class Hi { - public void hi(){ - System.out.println("Hi, the global developers."); - } - } - ``` - -5. Run the **cd** command to go to the **/home/code** directory and use javac to compile the source file. - - ``` - cd /home/code - javac -classpath Hello:Hi Test/my/example/Test.java - ``` - - After the command is executed, the **Test.class**, **Hello.class**, and **Hi.class** files are generated in the **/home/code/Test/my/example**, **/home/code/Hello/world/developers**, and **/home/code/Hi/openos/openeuler** directories. - -6. Run the **cd** command to go to the **/home/code** directory and run the **Test** program using Java. - - ``` - cd /home/code - java -classpath Test:Hello:Hi my/example/Test - ``` - - The command output is as follows: - - ``` - Hello, openEuler. - Hi, the global developers. - ``` - - diff --git a/content/en/docs/ApplicationDev/compiling-a-java-program-without-a-package.md b/content/en/docs/ApplicationDev/compiling-a-java-program-without-a-package.md deleted file mode 100644 index e98337436fef0e4b754cf1efac00856f5efb588b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/compiling-a-java-program-without-a-package.md +++ /dev/null @@ -1,40 +0,0 @@ -# Compiling a Java Program Without a Package - -1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. The command is as follows: - - ``` - # cd /home/code - ``` - -2. Compile the Hello World program and save it as **HelloWorld.java**. The following uses the Hello World program as an example. The command is as follows: - - ``` - # vi HelloWorld.java - ``` - - Code example: - - ``` - public class HelloWorld { - public static void main(String[] args) { - System.out.println("Hello World"); - } - } - ``` - -3. Run the following command to compile the code in the code directory: - - ``` - # javac HelloWorld.java - ``` - - If no error is reported, the execution is successful. - -4. After the compilation is complete, the HelloWorld.class file is generated. You can run the **java** command to view the result. The following is an example: - - ``` - # java HelloWorld - Hello World - ``` - - diff --git a/content/en/docs/ApplicationDev/configuring-a-repo-source.md b/content/en/docs/ApplicationDev/configuring-a-repo-source.md deleted file mode 100644 index a0331dcbccd25214bafeac64be35b2a76e8e426a..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/configuring-a-repo-source.md +++ /dev/null @@ -1,156 +0,0 @@ -# Configuring a Repo Source - -You can configure a repo source by directly obtaining the repo source file or by mounting an ISO file. - -## Configuring a Repo Source by Directly Obtaining the Repo Source File - ->![](public_sys-resources/icon-note.gif) **NOTE:** ->openEuler provides multiple repo source files. This section uses the OS repo source file of the AArch64 architecture as an example. - -1. Go to the yum source directory. - - ``` - cd /etc/yum.repos.d - ``` - -2. Create and edit the **local.repo** file. Configure the repo source file as the yum source. - - ``` - vi local.repo - ``` - - Edit the **local.repo** file as follows: - - \[basiclocal\] - - name=basiclocal - - baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/OS/aarch64/ - - enabled=1 - - gpgcheck=0 - - -## Configuring a Repo Source by Mounting an ISO File - ->![](public_sys-resources/icon-note.gif) **NOTE:** ->This section uses the **openEuler-20.03-LTS-aarch64-dvd.iso** image file and **openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum** verification file as examples. Modify them based on the actual requirements. - -1. Download the ISO image. - - Download an ISO image using a cross-platform file transfer tool. - 1. Log in to the openEuler community at [https://openeuler.org](https://openeuler.org). - 2. Click **Download**. - 3. Click the link provided after **Download ISO**. The download list is displayed. - 4. Select the version to be downloaded, for example, openEuler 20.03 LTS. Then, click **openEuler-20.03-LTS**. The download list is displayed. - 5. Click **ISO**. The ISO download list is displayed. - - **aarch64**: ISO image file of the AArch64 architecture - - **x86\_64**: ISO image file of the x86\_64 architecture - - **source**: ISO image file of the openEuler source code - - 6. Click **aarch64**. - 7. Click **openEuler-20.03-LTS-aarch64-dvd.iso** to download the openEuler release package to the local host. - 8. Click **openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum** to download the openEuler verification file to the local host. - 9. Log in to the openEuler OS and create a directory for storing the release package and verification file, for example, **/home/iso**. - - ``` - mkdir /home/iso - ``` - - 10. Use a cross-platform file transfer tool \(such as WinSCP\) to upload the local openEuler release package and verification file to the target openEuler OS. - - - Run the **wget** command to download the ISO image. - 1. Log in to the openEuler community at [https://openeuler.org](https://openeuler.org). - 2. Click **Download**. - 3. Click the link provided after **Download ISO**. The download list is displayed. - 4. Select the version to be downloaded, for example, openEuler 20.03 LTS. Then, click **openEuler-20.03-LTS**. The download list is displayed. - 5. Click **ISO**. The ISO download list is displayed. - - **aarch64**: ISO image file of the AArch64 architecture - - **x86\_64**: ISO image file of the x86\_64 architecture - - **source**: ISO image file of the openEuler source code - - 6. Click **aarch64**. - 7. Right-click **openEuler-20.03-LTS-aarch64-dvd.iso** and choose **Copy URL** from the shortcut menu to copy the address of the openEuler release package. - 8. Right-click **openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum** and choose **Copy URL** from the shortcut menu to copy the address of the openEuler verification file. - 9. Log in to the openEuler OS, create a directory \(for example, **/home/iso**\) for storing the release package and verification file, and switch to the directory. - - ``` - mkdir /home/iso - cd /home/iso - ``` - - 10. Run the **wget** command to remotely download the release package and verification file. In the command, **ipaddriso** and **ipaddrisosum** are the addresses copied in [1.g](#li62369349505) and [1.h](#li9236203405015). - - ``` - wget ipaddriso - wget ipaddrisosum - ``` - - -2. Release Package Integrity Check - 1. Obtain the verification value in the verification file. - - ``` - cat openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum - ``` - - 2. Calculate the SHA256 verification value of the openEuler release package. - - ``` - sha256sum openEuler-20.03-LTS-aarch64-dvd.iso - ``` - - After the command is run, the verification value is displayed. - - 3. Check whether the values calculated in step 1 and step 2 are consistent. - - If the verification values are consistent, the .iso file is not damaged. If they are inconsistent, the file is damaged and you need to obtain the file again. - -3. Mount the ISO image file and configure it as a repo source. - - Run the **mount** command to mount the image file. - - The following is an example: - - ``` - # mount /home/iso/openEuler-20.03-LTS-aarch64-dvd.iso /mnt/ - ``` - - The mounted **mnt** directory is as follows: - - ``` - . - │── boot.catalog - │── docs - │── EFI - │── images - │── Packages - │── repodata - │── TRANS.TBL - └── RPM-GPG-KEY-openEuler - ``` - - In the preceding command, **Packages** indicates the directory where the RPM package is stored, **repodata** indicates the directory where the repo source metadata is stored, and **RPM-GPG-KEY-openEuler** indicates the public key for signing openEuler. - - The mounted directory can be configured as the yum source. Create the \*\*\*.repo configuration file \(with the extension .repo\) in the **/etc/yum.repos.d/** directory. - - The following is an example: - - Create the openEuler.repo file in the **/etc/yum.repos.d** directory and use the local image mounting directory as the yum source. The content of the openEuler.repo file is as follows: - - ``` - [base] - name=base - baseurl=file:///mnt - enabled=1 - gpgcheck=1 - gpgkey=file:///mnt/RPM-GPG-KEY-openEuler - ``` - - **** - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >- **gpgcheck** indicates whether to enable the GNU privacy guard \(GPG\) to check the validity and security of the source of RPM packages. **1** indicates that the GPG check is enabled. **0** indicates that the GPG check is disabled. If this option is not specified, the GPG check is enabled by default. - >- **gpgkey** is the storage path of the signed public key. - - diff --git a/content/en/docs/ApplicationDev/configuring-the-development-environment.md b/content/en/docs/ApplicationDev/configuring-the-development-environment.md deleted file mode 100644 index 7723e984ba0dcfcabc414ab42c7d94ae10e0536f..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/configuring-the-development-environment.md +++ /dev/null @@ -1,97 +0,0 @@ -# Configuring the Development Environment - -- If physical machines \(PMs\) are used, the minimum hardware requirements of the development environment are described in [Table 1](#table154419352610). - - **Table 1** Minimum hardware specifications - - - - - - - - - - - - - - - - - - - - - - - - -

Component

-

Minimum Hardware Specification

-

Description

-

Architecture

-
  • AArch64
  • x86_64
-
  • 64-bit Arm architecture
  • 64-bit Intel x86 architecture
-

CPU

-
  • Huawei Kunpeng 920 series
  • Intel ® Xeon® processor
-

-

-

Memory

-

≥ 4 GB (8 GB or higher recommended for better user experience)

-

-

-

Hard disk

-

≥ 120 GB (for better user experience)

-

IDE, SATA, SAS interfaces are supported.

-
- -- If virtual machines \(VMs\) are used, the minimum virtualization space required for the development environment is described in [Table 2](#table780410493819). - - **Table 2** Minimum virtualization space - - - - - - - - - - - - - - - - - - - - - - - - -

Component

-

Minimum Virtualization Space

-

Description

-

Architecture

-
  • AArch64
  • x86_64
-

-

-

CPU

-

Two CPUs

-

-

-

Memory

-

≥ 4 GB (8 GB or higher recommended for better user experience)

-

-

-

Hard disk

-

≥ 32 GB (120 GB or higher recommended for better user experience)

-

-

-
- - -## OS Requirements - -The openEuler OS is required. - -For details about how to install the openEuler OS, see the _openEuler 20.03 LTS Installation Guide_. On the **SOFTWARE SELECTION** page, select **Development Tools** in the **Add-Ons for Selected Environment** area. - diff --git a/content/en/docs/ApplicationDev/creating-a-hello-world-rpm-package.md b/content/en/docs/ApplicationDev/creating-a-hello-world-rpm-package.md deleted file mode 100644 index aa254397fe145f649102941d5b6be07302766fda..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/creating-a-hello-world-rpm-package.md +++ /dev/null @@ -1,6 +0,0 @@ -# Creating a Hello World RPM Package - -The following uses the packaging process of the GNU Hello World project as an example. The package contains the most common peripheral components related to the typical Free and Open Source Software \(FOSS\) project, including the configuration, compilation, and installation environments, documents, and internationalization \(i18n\) information. - - - diff --git a/content/en/docs/ApplicationDev/downloading-and-installing-the-gtk-library.md b/content/en/docs/ApplicationDev/downloading-and-installing-the-gtk-library.md deleted file mode 100644 index 1941d22d670fe4e3739a7b56d419d44d45050171..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/downloading-and-installing-the-gtk-library.md +++ /dev/null @@ -1,14 +0,0 @@ -# Downloading and Installing the GTK Library - -Ensure that you have the **root** permission and run the following command: - -``` -# dnf list installed | grep gtk -``` - -If **gtk2** or **gtk3** is displayed, the GTK library has been installed. In this case, skip this step. Otherwise, run the following command to automatically download and install the GTK library: - -``` -# dnf -y install gtk2 libXtst libXrender xauth -``` - diff --git a/content/en/docs/ApplicationDev/downloading-and-running-intellij-idea.md b/content/en/docs/ApplicationDev/downloading-and-running-intellij-idea.md deleted file mode 100644 index 244f5671a6cb521d86ab6c320040a440c7adb2c2..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/downloading-and-running-intellij-idea.md +++ /dev/null @@ -1,15 +0,0 @@ -# Downloading and Running IntelliJ IDEA - -After the preceding environment configuration is complete, you can download and run the IntelliJ IDEA. The latest version of IntelliJ IDEA is incompatible with openEuler in some functions. You are advised to click [here](https://www.jetbrains.com/idea/download/other.html) and download the Linux package of the 2018 version. Move the downloaded package to the directory where you want to install the software and decompress the package. - -``` -# tar xf ideaIC-2018.3.tar.gz -``` - -Decompress the package, switch to the IntelliJ IDEA directory, and run the IntelliJ IDEA. - -``` -# cd ./idea-IC-183.4284.148 -# bin/idea.sh & -``` - diff --git a/content/en/docs/ApplicationDev/dynamic-link-library.md b/content/en/docs/ApplicationDev/dynamic-link-library.md deleted file mode 100644 index eb675fd6437959a03684626afa18eae112a745f4..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/dynamic-link-library.md +++ /dev/null @@ -1,44 +0,0 @@ -# Dynamic Link Library - -You can use the **-shared** and **-fPIC** options to create a dynamic link library \(DLL\) with the source file, assembly file, or target file. The **-fPIC** option is used in the compilation phase. This option is used when the target file is generated, so as to generate location-independent code. - -Example 1: Generate a DLL from the source file. - -``` -gcc -fPIC -shared test.c -o libtest.so -``` - -Example 2: Generate a DLL from the target file. - -``` -gcc -fPIC -c test.c -o test.o -gcc -shared test.o -o libtest.so -``` - -To link a DLL to an executable file, you need to list the name of the DLL in the command line. - -Example: Compile **main.c** and **libtest.so** into **app.out**. When **app.out** is running, the link library **libtest.so** is dynamically loaded. - -``` -gcc main.c libtest.so -o app.out -``` - -In this mode, the **libtest.so** file in the current directory is used. - -If you choose to search for a DLL, to ensure that the DLL can be linked when the program is running, you must implement by using one of the following methods: - -- Save the DLL to a standard directory, for example, **/usr/lib**. -- Add the DLL path **libaryDIR** to the environment variable **LD\_LIBRARY\_PATH**. - - export LD\_LIBRARY\_PATH=libraryDIR:$LD\_LIBRARY\_PATH - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >**LD\_LIBRARY\_PATH** is an environment variable of the DLL. If the DLL is not in the default directories \(**/lib** and **/usr/lib**\), you need to specify the environment variable **LD\_LIBRARY\_PATH**. - -- Add the DLL path **libaryDIR** to **/etc/ld.so.conf** and run **ldconfig**, or use the DLL path **libaryDIR** as a parameter to run **ldconfig**. - -``` -gcc main.c -L libraryDIR -ltest -o app.out -export LD_LIBRARY_PATH=libraryDIR:$LD_LIBRARY_PATH -``` - diff --git a/content/en/docs/ApplicationDev/editing-the-spec-file.md b/content/en/docs/ApplicationDev/editing-the-spec-file.md deleted file mode 100644 index dfcc24bda30a819f1a5a82900758c62205275791..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/editing-the-spec-file.md +++ /dev/null @@ -1,73 +0,0 @@ -# Editing the SPEC File - -Run the following command to create the .spec file: - -``` -# vi hello.spec -``` - -Write the corresponding content to the file and save the file. The following is an example of the file content. Modify the corresponding fields based on the actual requirements. - -``` -Name: hello -Version: 2.10 -Release: 1%{?dist} -Summary: The "Hello World" program from GNU -Summary(zh_CN): GNU Hello World program -License: GPLv3+ -URL: http://ftp.gnu.org/gnu/hello -Source0: http://ftp.gnu.org/gnu/hello/%{name}-%{version}.tar.gz - -BuildRequires: gettext -Requires(post): info -Requires(preun): info - -%description -The "Hello World" program, done with all bells and whistles of a proper FOSS -project, including configuration, build, internationalization, help files, etc. - -%description -l zh_CN -The Hello World program contains all parts required by the FOSS project, including configuration, build, i18n, and help files. - -%prep -%setup -q - -%build -%configure -make %{?_smp_mflags} - -%install -make install DESTDIR=%{buildroot} -%find_lang %{name} -rm -f %{buildroot}/%{_infodir}/dir - -%post -/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || : - -%preun -if [ $1 = 0 ] ; then -/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || : -fi - -%files -f %{name}.lang -%doc AUTHORS ChangeLog NEWS README THANKS TODO -%license COPYING -%{_mandir}/man1/hello.1.* -%{_infodir}/hello.info.* -%{_bindir}/hello - -%changelog -* Thu Dec 26 2019 Your Name - 2.10-1 -- Update to 2.10 -* Sat Dec 3 2016 Your Name - 2.9-1 -- Update to 2.9 -``` - -- The **Name** tag indicates the software name, the **Version** tag indicates the version number, and the **Release** tag indicates the release number. -- The **Summary** tag is a brief description. The first letter of the tag must be capitalized to prevent the rpmlint tool \(packaging check tool\) from generating alarms. -- The **License** tag describes the protocol version of the software package. The packager is responsible for checking the license status of the software, which can be implemented by checking the source code or license file or communicating with the author. -- The **Group** tag is used to classify software packages by **/usr/share/doc/rpm-/GROUPS**. Currently, this tag has been discarded. However, the VIM template still has this tag. You can delete it. However, adding this tag does not affect the system. The **%changelog** tag should contain the log of changes made for each release, especially the description of the upstream security/vulnerability patches. The **%changelog** tag should contain the version string to avoid the rpmlint tool from generating alarms. -- If multiple lines are involved, such as %changelog or %description, start from the next line of the instruction and end with a blank line. -- Some unnecessary lines \(such as BuildRequires and Requires\) can be commented out with a number sign \(\#\) at the beginning of the lines. -- The default values of **%prep**, **%build**, **%install**, and **%file** are retained. - diff --git a/content/en/docs/ApplicationDev/en-us_bookmap_0229243731.md b/content/en/docs/ApplicationDev/en-us_bookmap_0229243731.md deleted file mode 100644 index fffffa3534f09fa30fb58e267f5bfd47bdb30d39..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/en-us_bookmap_0229243731.md +++ /dev/null @@ -1,89 +0,0 @@ -# Application Development Guide - -- [Terms of Use](terms-of-use.md) -- [About This Document ](about-this-document.md) -- [Preparation](preparation.md) - - [Configuring the Development Environment](configuring-the-development-environment.md) - - [Configuring a Repo Source](configuring-a-repo-source.md) - - [Installing the Software Package](installing-the-software-package.md) - - [Installing the JDK Software Package](installing-the-jdk-software-package.md) - - [Installing the rpm-build Software Package](installing-the-rpm-build-software-package.md) - - - [Using the IDE for Java Development](using-the-ide-for-java-development.md) - - [Overview](overview.md) - - [Logging In to the Server Using MobaXterm](logging-in-to-the-server-using-mobaxterm.md) - - [Setting the JDK Environment](setting-the-jdk-environment.md) - - [Downloading and Installing the GTK Library](downloading-and-installing-the-gtk-library.md) - - [Setting X11 Forwarding](setting-x11-forwarding.md) - - [Downloading and Running IntelliJ IDEA](downloading-and-running-intellij-idea.md) - - -- [Using GCC for Compilation](using-gcc-for-compilation.md) - - [Overview](overview-0.md) - - [Basics](basics.md) - - [File Type](file-type.md) - - [Compilation Process](compilation-process.md) - - [Compilation Options](compilation-options.md) - - [Multi-file Compilation](multi-file-compilation.md) - - - [Libraries](libraries.md) - - [Dynamic Link Library](dynamic-link-library.md) - - [Static Link Library](static-link-library.md) - - - [Examples](examples.md) - - [Example for Using GCC to Compile C Programs](example-for-using-gcc-to-compile-c-programs.md) - - [Example for Creating and Using a DLL Using GCC](example-for-creating-and-using-a-dll-using-gcc.md) - - [Example for Creating and Using an SLL Using GCC](example-for-creating-and-using-an-sll-using-gcc.md) - - -- [Using Make for Compilation](using-make-for-compilation.md) - - [Overview](overview-1.md) - - [Basics](basics-2.md) - - [File Type](file-type-3.md) - - [make Work Process](make-work-process.md) - - [make Options](make-options.md) - - - [Makefiles](makefiles.md) - - [Examples](examples-4.md) - - [Example of Using Makefile to Implement Compilation](example-of-using-makefile-to-implement-compilation.md) - - -- [Using JDK for Compilation](using-jdk-for-compilation.md) - - [Overview](overview-5.md) - - [Basics](basics-6.md) - - [File Type and Tool](file-type-and-tool.md) - - [Java Program Generation Process](java-program-generation-process.md) - - [Common JDK Options](common-jdk-options.md) - - - [Class Library](class-library.md) - - [Examples](examples-7.md) - - [Compiling a Java Program Without a Package](compiling-a-java-program-without-a-package.md) - - [Compiling a Java Program with a Package](compiling-a-java-program-with-a-package.md) - - -- [Building an RPM Package](building-an-rpm-package.md) - - [Packaging Description](packaging-description.md) - - [Building an RPM Package Locally](building-an-rpm-package-locally.md) - - [Setting Up the Development Environment](setting-up-the-development-environment.md) - - [Creating a Hello World RPM Package](creating-a-hello-world-rpm-package.md) - - [Obtaining the Source Code](obtaining-the-source-code.md) - - [Editing the SPEC File](editing-the-spec-file.md) - - [Building an RPM Package](building-an-rpm-package-8.md) - - - - [Building an RPM Package Using the OBS](building-an-rpm-package-using-the-obs.md) - - [OBS Overview](obs-overview.md) - - [Building an RPM Software Package Online](building-an-rpm-software-package-online.md) - - [Building an Existing Software Package](building-an-existing-software-package.md) - - [Adding a Software Package](adding-a-software-package.md) - - [Obtaining the Software Package](obtaining-the-software-package.md) - - - [Building a Software Package Using OSC](building-a-software-package-using-osc.md) - - [Installing and Configuring the OSC](installing-and-configuring-the-osc.md) - - [Building an Existing Software Package](building-an-existing-software-package-9.md) - - [Adding a Software Package](adding-a-software-package-10.md) - - [Obtaining the Software Package](obtaining-the-software-package-11.md) - - - - diff --git a/content/en/docs/ApplicationDev/example-for-creating-and-using-a-dll-using-gcc.md b/content/en/docs/ApplicationDev/example-for-creating-and-using-a-dll-using-gcc.md deleted file mode 100644 index 9b647ae64416bcccbc46afa5cb21afe4725fc0f4..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/example-for-creating-and-using-a-dll-using-gcc.md +++ /dev/null @@ -1,113 +0,0 @@ -# Example for Creating and Using a DLL Using GCC - -1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. Create the **src**, **lib**, and **include** subdirectories in the directory to store the source file, DLL file, and header file, respectively. - - ``` - cd /home/code - mkdir src - mkdir lib - mkdir include - ``` - -2. Run the **cd** command to go to the **/home/code/src** directory and create two functions **add.c** and **sub.c** to implement addition and subtraction, respectively. - - ``` - cd /home/code/src - vi add.c - vi sub.c - ``` - - The following is an example of the **add.c** code: - - ``` - #include "math.h" - int add(int a, int b) - { - return a+b; - } - ``` - - The following is an example of the **sub.c** code: - - ``` - #include "math.h" - int sub(int a, int b) - { - return a-b; - } - ``` - -3. Compile the source files add.c and sub.c into the DLL libmath.so, and store the DLL in the **/home/code/lib** directory. - - ``` - gcc -fPIC -shared add.c sub.c -o /home/code/lib/libmath.so - ``` - -4. Go to the **/home/code/include** directory, create a header file **math.h**, and declare the header file of the function. - - ``` - cd /home/code/include - vi math.h - ``` - - The following is an example of the **math.h** code: - - ``` - #ifndef __MATH_H_ - #define __MATH_H_ - int add(int a, int b); - int sub(int a, int b); - #endif - ``` - -5. Run the **cd** command to go to the **/home/code/src** directory and create a **main.c** function that invokes add\(\) and sub\(\). - - ``` - cd /home/code/src - vi main.c - ``` - - The following is an example of the **math.c** code: - - ``` - #include - #include "math.h" - int main() - { - int a, b; - printf("Please input a and b:\n"); - scanf("%d %d", &a, &b); - printf("The add: %d\n", add(a,b)); - printf("The sub: %d\n", sub(a,b)); - return 0; - } - ``` - -6. Compile **main.c** and **libmath.so** into **math.out**. - - ``` - gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out - ``` - -7. Add the path of the DLL to the environment variable. - - ``` - export LD_LIBRARY_PATH=/home/code/lib:$LD_LIBRARY_PATH - ``` - -8. Run the following command to execute **math.out**: - - ``` - ./math.out - ``` - - The command output is as follows: - - ``` - Please input a and b: - 9 2 - The add: 11 - The sub: 7 - ``` - - diff --git a/content/en/docs/ApplicationDev/example-for-creating-and-using-an-sll-using-gcc.md b/content/en/docs/ApplicationDev/example-for-creating-and-using-an-sll-using-gcc.md deleted file mode 100644 index 1795ed2beaa6f707ecba67d8ab5e8a75a18219f5..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/example-for-creating-and-using-an-sll-using-gcc.md +++ /dev/null @@ -1,113 +0,0 @@ -# Example for Creating and Using an SLL Using GCC - -1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. Create the **src**, **lib**, and **include** subdirectories in the directory to store the source file, SLL file, and header file respectively. - - ``` - cd /home/code - mkdir src - mkdir lib - mkdir include - ``` - -2. Run the **cd** command to go to the **/home/code/src** directory and create two functions **add.c** and **sub.c** to implement addition and subtraction, respectively. - - ``` - cd /home/code/src - vi add.c - vi sub.c - ``` - - The following is an example of the **add.c** code: - - ``` - #include "math.h" - int add(int a, int b) - { - return a+b; - } - ``` - - The following is an example of the **sub.c** code: - - ``` - #include "math.h" - int sub(int a, int b) - { - return a-b; - } - ``` - -3. Compile the source files **add.c** and **sub.c** into the target files **add.o** and **sub.o**. - - ``` - gcc -c add.c sub.c - ``` - -4. Run the **ar** command to compress the **add.o** and **sub.o** target files into the SLL **libmath.a** and save the SLL to the **/home/code/lib** directory. - - ``` - ar rcs /home/code/lib/libmath.a add.o sub.o - ``` - -5. Go to the **/home/code/include** directory, create a header file **math.h**, and declare the header file of the function. - - ``` - cd /home/code/include - vi math.h - ``` - - The following is an example of the **math.h** code: - - ``` - #ifndef __MATH_H_ - #define __MATH_H_ - int add(int a, int b); - int sub(int a, int b); - #endif - ``` - -6. Run the **cd** command to go to the **/home/code/src** directory and create a **main.c** function that invokes add\(\) and sub\(\). - - ``` - cd /home/code/src - vi main.c - ``` - - The following is an example of the **math.c** code: - - ``` - #include - #include "math.h" - int main() - { - int a, b; - printf("Please input a and b:\n"); - scanf("%d %d", &a, &b); - printf("The add: %d\n", add(a,b)); - printf("The sub: %d\n", sub(a,b)); - return 0; - } - ``` - -7. Compile **main.c** and **libmath.a** into **math.out**. - - ``` - gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out - ``` - -8. Run the following command to execute **math.out**: - - ``` - ./math.out - ``` - - The command output is as follows: - - ``` - Please input a and b: - 9 2 - The add: 11 - The sub: 7 - ``` - - diff --git a/content/en/docs/ApplicationDev/example-for-using-gcc-to-compile-c-programs.md b/content/en/docs/ApplicationDev/example-for-using-gcc-to-compile-c-programs.md deleted file mode 100644 index e048508e309700eb65419adccef445770b24a6c9..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/example-for-using-gcc-to-compile-c-programs.md +++ /dev/null @@ -1,41 +0,0 @@ -# Example for Using GCC to Compile C Programs - -1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. The command is as follows: - - ``` - cd /home/code - ``` - -2. Compile the Hello World program and save it as **helloworld.c**. The following uses the Hello World program as an example. The command is as follows: - - ``` - vi helloworld.c - ``` - - Code example: - - ``` - #include - int main() - { - printf("Hello World!\n"); - return 0; - } - ``` - -3. Run the following command to compile the code in the code directory: - - ``` - gcc helloworld.c -o helloworld - ``` - - If no error is reported, the execution is successful. - -4. After the compilation is complete, the helloworld file is generated. Check the compilation result. The following is an example: - - ``` - # ./helloworld - Hello World! - ``` - - diff --git a/content/en/docs/ApplicationDev/example-of-using-makefile-to-implement-compilation.md b/content/en/docs/ApplicationDev/example-of-using-makefile-to-implement-compilation.md deleted file mode 100644 index a0ba03129a424ef9c44981abd884931d54c24850..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/example-of-using-makefile-to-implement-compilation.md +++ /dev/null @@ -1,100 +0,0 @@ -# Example of Using Makefile to Implement Compilation - -1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. - - ``` - cd /home/code - ``` - -2. Create a header file **hello.h** and two functions **hello.c** and **main.c**. - - ``` - cd /home/code/ - ``` - - The following is an example of the **hello.h** code: - - ``` - #pragma once - #include - void hello(); - ``` - - The following is an example of the **hello.c** code: - - ``` - #include "hello.h" - void hello() - { - int i=1; - while(i<5) - { - printf("The %dth say hello.\n", i); - i++; - } - } - - ``` - - The following is an example of the **main.c** code: - - ``` - #include "hello.h" - #include - int main() - { - hello(); - return 0; - } - ``` - -3. Create the makefile. - - ``` - vi Makefile - ``` - - The following provides an example of the makefile content: - - ``` - main:main.o hello.o - gcc -o main main.o hello.o - main.o:main.c - gcc -c main.c - hello.o:hello.c - gcc -c hello.c - clean: - rm -f hello.o main.o main - ``` - -4. Run the **make** command. - - ``` - make - ``` - - After the command is executed, the commands executed in makefile are printed. If you do not need to print the information, add the **-s** option to the **make** command. - - gcc -c main.c - - gcc -c hello.c - - gcc -o main main.o hello.o - -5. Execute the ./main target. - - ``` - ./main - ``` - - After the command is executed, the following information is displayed: - - The 1th say hello. - - The 2th say hello. - - The 3th say hello. - - The 4th say hello. - - diff --git a/content/en/docs/ApplicationDev/examples-4.md b/content/en/docs/ApplicationDev/examples-4.md deleted file mode 100644 index cd7ebbac8a757120ef65f243abc10cec8cd42b90..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/examples-4.md +++ /dev/null @@ -1,4 +0,0 @@ -# Examples - - - diff --git a/content/en/docs/ApplicationDev/examples-7.md b/content/en/docs/ApplicationDev/examples-7.md deleted file mode 100644 index 6b24ed38cbc4936c4adb56ca9863b4448e6fe89c..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/examples-7.md +++ /dev/null @@ -1,4 +0,0 @@ -# Examples - - - diff --git a/content/en/docs/ApplicationDev/examples.md b/content/en/docs/ApplicationDev/examples.md deleted file mode 100644 index 3653c88ec318c1fa7a90640da65ba84b0e8e4bb1..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/examples.md +++ /dev/null @@ -1,4 +0,0 @@ -# Examples - - - diff --git a/content/en/docs/ApplicationDev/figures/en-us_image_0229243671.png b/content/en/docs/ApplicationDev/figures/en-us_image_0229243671.png index a32856aa08e459ed0f51f8fcf4c2f51511c12095..ad5ed3f7beeb01e6a48707c4806606b41d687e22 100644 Binary files a/content/en/docs/ApplicationDev/figures/en-us_image_0229243671.png and b/content/en/docs/ApplicationDev/figures/en-us_image_0229243671.png differ diff --git a/content/en/docs/ApplicationDev/figures/en-us_image_0229243712.png b/content/en/docs/ApplicationDev/figures/en-us_image_0229243712.png index 8d5a343524e14d11a3e2a94be4066fbb2d20599e..62ef0decdf6f1e591059904001d712a54f727e68 100644 Binary files a/content/en/docs/ApplicationDev/figures/en-us_image_0229243712.png and b/content/en/docs/ApplicationDev/figures/en-us_image_0229243712.png differ diff --git a/content/en/docs/ApplicationDev/figures/repositories-page.png b/content/en/docs/ApplicationDev/figures/repositories-page.png index c64bfdd1bca838c5b72fa7bb7d73b525e8be79f6..b7c04eedf9dd32cf4a9d024a05f5c8b294c76934 100644 Binary files a/content/en/docs/ApplicationDev/figures/repositories-page.png and b/content/en/docs/ApplicationDev/figures/repositories-page.png differ diff --git a/content/en/docs/ApplicationDev/figures/rpm-software-package-download-page.png b/content/en/docs/ApplicationDev/figures/rpm-software-package-download-page.png index e5663b6259982541ae9350701326665f3dee43f6..9f32d6c16d344df6951fc4e6aa027d02dfb9ccb5 100644 Binary files a/content/en/docs/ApplicationDev/figures/rpm-software-package-download-page.png and b/content/en/docs/ApplicationDev/figures/rpm-software-package-download-page.png differ diff --git a/content/en/docs/ApplicationDev/file-type-3.md b/content/en/docs/ApplicationDev/file-type-3.md deleted file mode 100644 index dfb9775f7c36f698039d57879a5bacd52fc9ba92..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/file-type-3.md +++ /dev/null @@ -1,76 +0,0 @@ -# File Type - -[Table 1](#table634145764320) describes the file types that may be used in the makefiles file. - -**Table 1** 文件类型 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Extension (Suffix)

-

Description

-

.c

-

C source code file.

-

.C, .cc, or .cxx

-

C++ source code file.

-

.m

-

Objective-C source code file.

-

.s

-

Assembly language source code file.

-

.i

-

Preprocessed C source code file.

-

.ii

-

Preprocessed C++ source code file.

-

.S

-

Pre-processed assembly language source code file.

-

.h

-

Header file contained in the program.

-

.o

-

Target file after compilation.

-

.so

-

Dynamic link library, which is a special target file.

-

.a

-

Static link library.

-

.out

-

Executable files, which do not have a fixed suffix. The system distinguishes executable files from unexecutable files based on file attributes. If the name of an executable file is not given, GCC generates a file named a.out.

-
- diff --git a/content/en/docs/ApplicationDev/file-type-and-tool.md b/content/en/docs/ApplicationDev/file-type-and-tool.md deleted file mode 100644 index 2d74b7b23fc2652e49ccf376273514620b151b10..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/file-type-and-tool.md +++ /dev/null @@ -1,58 +0,0 @@ -# File Type and Tool - -For any given input file, the file type determines which tool to use for processing. The common file types and tools are described in [Table 1](#table634145764320) and [Table 2](#table103504146433). - -**Table 1** Common JDK file types - - - - - - - - - - - - - - - - -

Extension (Suffix)

-

Description

-

.java

-

Java source code file.

-

.class

-

Java bytecode file, which is intermediate code irrelevant to any specific machine or OS environment. It is a binary file, which is the target code file generated after the Java source file is compiled by the Java compiler.

-

.jar

-

JAR package of Java files.

-
- -**Table 2** Common JDK tools - - - - - - - - - - - - - - - - -

Name

-

Description

-

java

-

Java running tool, which is used to run .class bytecode files or .jar files.

-

javac

-

Compiles Java source code files into .class bytecode files.

-

jar

-

Creates and manages JAR files.

-
- diff --git a/content/en/docs/ApplicationDev/file-type.md b/content/en/docs/ApplicationDev/file-type.md deleted file mode 100644 index 30849bf1b1c7e508939baa06ae55ff75aea11c20..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/file-type.md +++ /dev/null @@ -1,76 +0,0 @@ -# File Type - -For any given input file, the file type determines which compilation to perform. [Table 1](#table634145764320) describes the common GCC file types. - -**Table 1** Common GCC file types - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Extension (Suffix)

-

Description

-

.c

-

C source code file.

-

.C, .cc, or .cxx

-

C++ source code file.

-

.m

-

Objective-C source code file.

-

.s

-

Assembly language source code file.

-

.i

-

Preprocessed C source code file.

-

.ii

-

Preprocessed C++ source code file.

-

.S

-

Pre-processed assembly language source code file.

-

.h

-

Header file contained in the program.

-

.o

-

Target file after compilation.

-

.so

-

Dynamic link library, which is a special target file.

-

.a

-

Static link library.

-

.out

-

Executable files, which do not have a fixed suffix. The system distinguishes executable files from unexecutable files based on file attributes. If the name of an executable file is not given, GCC generates a file named a.out.

-
- diff --git a/content/en/docs/ApplicationDev/installing-and-configuring-the-osc.md b/content/en/docs/ApplicationDev/installing-and-configuring-the-osc.md deleted file mode 100644 index b67d276a6d923c2666728a3f0d7c2e0e2b5dc97a..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/installing-and-configuring-the-osc.md +++ /dev/null @@ -1,43 +0,0 @@ -# Installing and Configuring the OSC - -## Prerequisites - -You have obtained the **root** permission, and have configured a repo source for openEuler. - -## Procedure - -1. Install the OSC command line tool and its dependency as the **root** user. - - ``` - # dnf install osc build - ``` - - >![](public_sys-resources/icon-note.gif) **NOTE:** - >The compilation of RPM software packages depends on build. - -2. Configure the OSC. - 1. Run the following command to open the **\~/.oscrc** file: - - ``` - # vi ~/.oscrc - ``` - - 2. Add the **user** and **pass** fields to **\~/.oscrc**. The values of _userName_ and _passWord_ are the account and password registered on the OBS website \([http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/)\). - - ``` - [general] - apiurl = http://openeuler-build.huawei.com/ - no_verify = 1 - [http://openeuler-build.huawei.com/] - user=userName - pass=passWord - ``` - - 3. If the domain name **openeuler-build.openeuler.org** cannot be resolved, manually add the following line to the **/etc/hosts** file: _ip-address_ indicates the IP address of OBS, which is http://117.78.1.88/. - - ``` - ip-address openeuler-build.openeuler.org - ``` - - - diff --git a/content/en/docs/ApplicationDev/installing-the-jdk-software-package.md b/content/en/docs/ApplicationDev/installing-the-jdk-software-package.md deleted file mode 100644 index 1c3e3e927f9dfc4d764c9b2642b76ad2036844a5..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/installing-the-jdk-software-package.md +++ /dev/null @@ -1,45 +0,0 @@ -# Installing the JDK Software Package - -1. Run the **dnf list installed | grep jdk** command to check whether the JDK software is installed. - - ``` - dnf list installed | grep jdk - ``` - - Check the command output. If the command output contains "jdk", the JDK has been installed. If no such information is displayed, the software is not installed. - -2. Clear the cache. - - ``` - dnf clean all - ``` - -3. Create a cache. - - ``` - dnf makecache - ``` - -4. Query the JDK software package that can be installed. - - ``` - dnf search jdk | grep jdk - ``` - - View the command output and install the **java-x.x.x-openjdk-devel.aarch64** software package. **x.x.x** indicates the version number. - -5. Install the JDK software package. The following uses the **java-1.8.0-openjdk-devel** software package as an example. - - ``` - dnf install java-1.8.0-openjdk-devel.aarch64 - ``` - -6. Query information about the JDK software. - - ``` - java -version - ``` - - Check the command output. If the command output contains "openjdk version "1.8.0\_232"", the JDK has been correctly installed. In the command output, **1.8.0\_232** indicates the JDK version. - - diff --git a/content/en/docs/ApplicationDev/installing-the-rpm-build-software-package.md b/content/en/docs/ApplicationDev/installing-the-rpm-build-software-package.md deleted file mode 100644 index fb946041ead7cc0deb96106fbc179eb0a00bab3d..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/installing-the-rpm-build-software-package.md +++ /dev/null @@ -1,35 +0,0 @@ -# Installing the rpm-build Software Package - -1. Run the **dnf list installed | grep rpm-build** command to check whether the rpm-build software is installed. - - ``` - dnf list installed | grep rpm-build - ``` - - Check the command output. If the command output contains "rpm-build", the software has been installed. If no such information is displayed, the software is not installed. - -2. Clear the cache. - - ``` - dnf clean all - ``` - -3. Create a cache. - - ``` - dnf makecache - ``` - -4. Install the rpm-build package. - - ``` - dnf install rpm-build - ``` - -5. Query the rpm-build software version. - - ``` - rpmbuild --version - ``` - - diff --git a/content/en/docs/ApplicationDev/installing-the-software-package.md b/content/en/docs/ApplicationDev/installing-the-software-package.md deleted file mode 100644 index 490e955ff93130d03cdd2f151efa21e0cb5b2744..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/installing-the-software-package.md +++ /dev/null @@ -1,6 +0,0 @@ -# Installing the Software Package - -Install the software required for development. The software required varies in different development environments. However, the installation methods are the same. This section describes how to install common software packages \(such as JDK and rpm-build\). Some development software, such as GCC and GNU make, is provided by the openEuler OS by default. - - - diff --git a/content/en/docs/ApplicationDev/java-program-generation-process.md b/content/en/docs/ApplicationDev/java-program-generation-process.md deleted file mode 100644 index 4194ad4abb962df08006d180fc92db46a51857fe..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/java-program-generation-process.md +++ /dev/null @@ -1,7 +0,0 @@ -# Java Program Generation Process - -To generate a program from Java source code files and run the program using Java, compilation and run are required. - -1. Compilation: Use the Java compiler \(javac\) to compile Java source code files \(.java files\) into .class bytecode files. -2. Run: Execute the bytecode files on the Java virtual machine \(JVM\). - diff --git a/content/en/docs/ApplicationDev/libraries.md b/content/en/docs/ApplicationDev/libraries.md deleted file mode 100644 index 6301afcd9a0805c0f15db6a65cb839f2a5734440..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/libraries.md +++ /dev/null @@ -1,26 +0,0 @@ -# Libraries - -A library is mature and reusable code that has been written for use. Each program depends on many basic underlying libraries. - -The library file name is prefixed with lib and suffixed with .so \(dynamic library\) or .a \(static library\). The middle part is the user-defined library file name, for example, libfoo.so or libfoo.a. Because all library files comply with the same specifications, the **lib** prefix can be omitted when the **-l** option specifies the name of the linked library file. That is, when GCC processes **-lfoo**, the library file **libfoo.so** or **libfoo.a** is automatically linked. When creating a library, you must specify the full file name **libfoo.so** or **libfoo.a**. - -Libraries are classified into static libraries and dynamic libraries based on the linking time. The static library links and packs the target file .o generated by assembly and the referenced library into an executable file in the linking phase. The dynamic library is not linked to the target code when the program is compiled, but is loaded when the program is run. The differences are as follows: - -- The resource usage is different. - - The static library is a part of the generated executable file, while the dynamic library is a separate file. Therefore, the sizes and occupied disk space of the executable files of the static library and dynamic library are different, which leads to different resource usage. - -- The scalability and compatibility are different. - - If the implementation of a function in the static library changes, the executable file must be recompiled. For the executable file generated by dynamic linking, only the dynamic library needs to be updated, and the executable file does not need to be recompiled. - -- The dependency is different. - - The executable file of the static library can run without depending on any other contents, while the executable file of the dynamic library must depend on the dynamic library. Therefore, the static library is convenient to migrate. - -- The loading speeds are different. - - Static libraries are linked together with executable files, while dynamic libraries are linked only when they are loaded or run. Therefore, for the same program, static linking is faster than dynamic linking. - - - diff --git a/content/en/docs/ApplicationDev/logging-in-to-the-server-using-mobaxterm.md b/content/en/docs/ApplicationDev/logging-in-to-the-server-using-mobaxterm.md deleted file mode 100644 index b76c4a98796e4ed239b880269f3213519628c5f3..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/logging-in-to-the-server-using-mobaxterm.md +++ /dev/null @@ -1,6 +0,0 @@ -# Logging In to the Server Using MobaXterm - -MobaXterm is an excellent SSH client. It has an X Server and can easily solve remote GUI display problems. - -You need to download, install, and start MobaXterm in advance, and then log in to your server in SSH mode to perform the following operations: - diff --git a/content/en/docs/ApplicationDev/make-options.md b/content/en/docs/ApplicationDev/make-options.md deleted file mode 100644 index 8fea1b75a6438b59ebb0b4d7997db836d82476d9..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/make-options.md +++ /dev/null @@ -1,106 +0,0 @@ -# make Options - -make command format: **make** \[_option_\]... \[_targe_t\]... - -In the preceding command: - -_option_: parameter option. - -_target_: target specified in Makefile. - -[Table 1](#table261872312343) describes the common make options. - -**Table 1** Common make options - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

options Value

-

Description

-

-C dir, --directory=dir

-

Specifies dir as the working directory after the make command starts to run.

-

When there are multiple -C options, the final working directory of make is the relative path of the first directory.

-

-d

-

Displays all debugging information during execution of the make command. You can use the -d option to display all the information during the construction of the dependency chain and the reconstruction of the target.

-

-e, --environment-overrides

-

Overwrites the variable definition with the same name in Makefile with the environment variable definition.

-

-f file, --file=file,

-

--makefile=file

-

Specifies the file as the Makefile for the make command.

-

-p, --help

-

Displays help information.

-

-i, --ignore-errors

-

Ignores the errors occurred during the execution.

-

-k, --keep-going

-

When an error occurs during command execution, the make command is not terminated. The make command executes all commands as many as possible until a known error occurs.

-

-n, --just-print, --dry-run

-

Simulates the execution of commands (including the commands starting with @) in the actual execution sequence. This command is used only to display the execution process and has no actual execution effect.

-

-o file, --old-file=file, --assume-old=file

-

The specified file does not need to be rebuilt even if its dependency has expired, and no target of this dependency file is rebuilt.

-

-p, --print-date-base

-

Before the command is executed, all data of Makefile read by make and the version information of make are printed. If you only need to print the data, run the make -qp command to view the preset rules and variables before the make command is executed. You can run the make -p -f /dev/null command.

-

-r, --no-builtin-rules

-

Ignores the use of embedded implicit rules and the implicit suffix list of all suffix rules.

-

-R, --no-builtin-variabes

-

Ignores embedded hidden variables.

-

-s, --silent, --quiet

-

Cancels the printing during the command execution.

-

-S, --no-keep-going, --stop

-

Cancels the -k option. In the recursive make process, the sub-make inherits the upper-layer command line option through the MAKEFLAGS variable. You can use the -S option in the sub-make to cancel the -k option transferred by the upper-layer command, or cancel the -k option in the system environment variable MAKEFLAGS.

-

-t, --touch

-

Updates the timestamp of all target files to the current system time. Prevents make from rebuilding all outdated target files.

-

-v, version

-

Displays the make version.

-
- diff --git a/content/en/docs/ApplicationDev/make-work-process.md b/content/en/docs/ApplicationDev/make-work-process.md deleted file mode 100644 index d742d7b34bc2046d77b31ae92500533cf6b6ddd8..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/make-work-process.md +++ /dev/null @@ -1,10 +0,0 @@ -# make Work Process - -The process of deploying make to generate an executable file from the source code file is described as follows: - -1. The make command reads the Makefiles, including the files named GNUmakefile, makefile, and Makefile in the current directory, the included makefile, and the rule files specified by the **-f**, **--file**, and **--makefile** options. -2. Initialize variables. -3. Derive implicit rules, analyze dependencies, and create a dependency chain. -4. Determine which targets need to be regenerated based on the dependency chain. -5. Run a command to generate the final file. - diff --git a/content/en/docs/ApplicationDev/makefiles.md b/content/en/docs/ApplicationDev/makefiles.md deleted file mode 100644 index c52aa64ce00d6f029f19285a0faa7fe5b304a906..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/makefiles.md +++ /dev/null @@ -1,55 +0,0 @@ -# Makefiles - -Make is a tool that uses makefiles for compilation, linking, installation, and cleanup, so as to generate executable files and other related files from source code files. Therefore, makefiles describe the compilation and linking rules of the entire project, including which files need to be compiled, which files do not need to be compiled, which files need to be compiled first, which files need to be compiled later, and which files need to be rebuilt. The makefiles automate project compilation. You do not need to manually enter a large number of source files and parameters each time. - -This chapter describes the structure and main contents of makefiles. For more information about makefiles, run the **info make** command. - -## Makefile Structure - -The makefile file structure is as follows: - -_targets_:_prereguisites_ - -_command_ - -or - -_targets_:_prerequisites_;_command_ - -_command_ - -In the preceding information: - -- _targets_: targets, which can be target files, executable files, or tags. -- _prerequisites_: dependency files, which are the files or targets required for generating the _targets_. There can be multiple or none of them. -- _command_: command \(any shell command\) to be executed by make. Multiple commands are allowed, and each command occupies a line. -- Use colons \(:\) to separate the target files from the dependency files. Press **Tab** at the beginning of each command line. - -The makefile file structure indicates the output target, the object on which the output target depends, and the command to be executed for generating the target. - -## Makefile Contents - -A makefile file consists of the following contents: - -- Explicit rule - - Specify the dependency, such as the file to be generated, dependency file, and generated command. - -- Implicit rule - - Specify the rule that is automatically derived by make. The make command supports the automatic derivation function. - -- Variable definition -- File indicator - - The file indicator consists of three parts: - - - Inclusion of other makefiles, for example, include xx.md - - Selective execution, for example, \#ifdef - - Definition of multiple command lines, for example, define...endef. \(define ... endef\) - -- Comment - - The comment starts with a number sign \(\#\). - - diff --git a/content/en/docs/ApplicationDev/multi-file-compilation.md b/content/en/docs/ApplicationDev/multi-file-compilation.md deleted file mode 100644 index 15ef8724595f703a93165e84802200d96932957b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/multi-file-compilation.md +++ /dev/null @@ -1,23 +0,0 @@ -# Multi-file Compilation - -There are two methods provided for compiling multiple source files. - -- Multiple source files are compiled at the same time. All files need to be recompiled during compilation. - - Example: Compile **test1.c** and **test2.c** and link them to the executable file **test**. - - ``` - gcc test1.c test2.c -o test - ``` - -- Compile each source file, and then link the target files generated after compilation. During compilation, only modified files need to be recompiled. - - For example, compile **test1.c** and **test2.c**, and link the target files **test1.o** and **test2.o** to the executable file **test**. - - ``` - gcc -c test1.c - gcc -c test2.c - gcc -o test1.o test2.o -o test - ``` - - diff --git a/content/en/docs/ApplicationDev/obs-overview.md b/content/en/docs/ApplicationDev/obs-overview.md deleted file mode 100644 index 8ba224d58bce601a17ad55aa619e833b4dfdbb58..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/obs-overview.md +++ /dev/null @@ -1,8 +0,0 @@ -# OBS Overview - -OBS is a general compilation framework based on the openSUSE distribution. It is used to build source code packages into RPM software packages or Linux images. OBS uses the automatic distributed compilation mode and supports the compilation of images and installation packages of multiple Linux OS distributions \(such as openEuler, SUSE, and Debian\) on multiple architecture platforms \(such as x86 and ARM64\). - -OBS consists of the backend and frontend. The backend implements all core functions. The frontend provides web applications and APIs for interaction with the backend. In addition, OBS provides an API command line client OSC, which is developed in an independent repository. - -OBS uses the project organization software package. Basic permission control, related repository, and build targets \(OS and architecture\) can be defined in the project. A project can contain multiple subprojects. Each subproject can be configured independently to complete a task. - diff --git a/content/en/docs/ApplicationDev/obtaining-the-software-package-11.md b/content/en/docs/ApplicationDev/obtaining-the-software-package-11.md deleted file mode 100644 index 5aab88422535c532dc51959c22a228a023585638..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/obtaining-the-software-package-11.md +++ /dev/null @@ -1,18 +0,0 @@ -# Obtaining the Software Package - -After the RPM software package is built, run the following command to obtain the RPM software package using the OSC: - -``` -# osc getbinaries home:testUser:branches:openEuler:Mainline my-first-obs-package standard_aarch64 aarch64 -``` - -The parameters in the command are described as follows. You can modify the parameters according to the actual situation. - -- _home:testUser:branches:openEuler:Mainline_: name of the project to which the software package belongs. -- _my-first-obs-package_: name of the software package. -- _standard\_aarch64_: repository name. -- _aarch64_: repository architecture name. - ->![](public_sys-resources/icon-note.gif) **NOTE:** ->You can also obtain the software package built using OSC from the web page. For details, see [Building an RPM Package](building-an-rpm-package-8.md). - diff --git a/content/en/docs/ApplicationDev/obtaining-the-software-package.md b/content/en/docs/ApplicationDev/obtaining-the-software-package.md deleted file mode 100644 index 967506a0d776a8b5eaae8d7681b220f2c3882b72..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/obtaining-the-software-package.md +++ /dev/null @@ -1,19 +0,0 @@ -# Obtaining the Software Package - -After the RPM software package is built, perform the following operations to obtain the RPM software package on the web page: - -1. Log in to the OBS console. -2. Click **All Projects** and find the project corresponding to the required software package, for example, **openEuler:Mainline**. -3. Click the name of the required software package in the project. The software package details page is displayed, for example, the **kernel** page in the preceding example. - -1. Click the **Repositories** tab. On the software repository management page that is displayed, click **Enable** in **Publish Flag** to enable the RPM software package download function \(the status changes from ![](figures/en-us_image_0229243704.png) to ![](figures/en-us_image_0229243702.png)\), as shown in [Figure 1](#fig17480830144217). - - **Figure 1** **Repositories** page - ![](figures/repositories-page.png "repositories-page") - -2. Click the project name in the **Repository** column. On the RPM software package download page that is displayed, click **Download** on the right of the RPM software package to download the RPM software package, as shown in [Figure 2](#fig12152145615438). - - **Figure 2** RPM software package download page - ![](figures/rpm-software-package-download-page.png "rpm-software-package-download-page") - - diff --git a/content/en/docs/ApplicationDev/obtaining-the-source-code.md b/content/en/docs/ApplicationDev/obtaining-the-source-code.md deleted file mode 100644 index 090fc053cd458fc00831e8ee422120dd3526d2d4..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/obtaining-the-source-code.md +++ /dev/null @@ -1,9 +0,0 @@ -# Obtaining the Source Code - -Run the following command to download the source code of the official example: - -``` -# cd ~/rpmbuild/SOURCES -# wget http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz -``` - diff --git a/content/en/docs/ApplicationDev/overview-0.md b/content/en/docs/ApplicationDev/overview-0.md deleted file mode 100644 index 22434aa50099bf77d1c2db6eff633fcd5defe72b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/overview-0.md +++ /dev/null @@ -1,4 +0,0 @@ -# Overview - -The GNU Compiler Collection \(GCC\) is a powerful and high-performance multi-platform compiler developed by GNU. The GCC compiler can compile and link source programs, assemblers, and target programs of C and C++ into executable files. By default, the GCC software package is installed in the openEuler OS. - diff --git a/content/en/docs/ApplicationDev/overview-1.md b/content/en/docs/ApplicationDev/overview-1.md deleted file mode 100644 index faf505f0aad82f2ce8c76849105406605d74686c..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/overview-1.md +++ /dev/null @@ -1,4 +0,0 @@ -# Overview - -The GNU make utility \(usually abbreviated as make\) is a tool for controlling the generation of executable files from source files. make automatically identifies which parts of the complex program have changed and need to be recompiled. Make uses a configuration file called makefiles to control how the program is built. - diff --git a/content/en/docs/ApplicationDev/overview-5.md b/content/en/docs/ApplicationDev/overview-5.md deleted file mode 100644 index 99572286672c51dd6b312d1e6a6a377a573fe6a0..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/overview-5.md +++ /dev/null @@ -1,4 +0,0 @@ -# Overview - -A Java Development Kit \(JDK\) is a software package required for Java development. It contains the Java Runtime Environment \(JRE\) and compilation and commissioning tools. On the basis of OpenJDK, openEuler optimizes GC, enhances concurrency stability, and enhances security, improving the performance and stability of Java applications on ARM. - diff --git a/content/en/docs/ApplicationDev/overview.md b/content/en/docs/ApplicationDev/overview.md deleted file mode 100644 index 044a8ebc820f8ff96f524fb69f2d36c2ba28393b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/overview.md +++ /dev/null @@ -1,4 +0,0 @@ -# Overview - -IntelliJ IDEA is a popular Java IDE. You can download the community edition of IntelliJ IDEA for free. Currently, openEuler supports Java development in the IntelliJ IDEA integrated development environment \(IDE\), improving the work efficiency of developers. - diff --git a/content/en/docs/ApplicationDev/packaging-description.md b/content/en/docs/ApplicationDev/packaging-description.md deleted file mode 100644 index 0a9ae1e82474276a49cc2eb8a5b74ee815170a51..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/packaging-description.md +++ /dev/null @@ -1,342 +0,0 @@ -# Packaging Description - -## Principles - -During RPM packaging, the source code needs to be compiled. The compiled configuration files and binary command files need to be placed in proper positions. The RPM packages need to be tested as required. A workspace is required for these operations. The **rpmbuild** command uses a set of standard workspaces. - -``` -# rpmdev-setuptree -``` - -The **rpmdev-setuptree** command is used to install rpmdevtools. After the command is executed, the **rpmbuild** folder is generated in the **/root** directory \(or the **/home/**_username_ directory for non-root users\). The directory structure is as follows: - -``` -# tree rpmbuild -rpmbuild -├── BUILD -├── RPMS -├── SOURCES -├── SPECS -└── SRPMS -``` - -The content is described as follows: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Content

-

Macro Code

-

Name

-

Function

-

~/rpmbuild/BUILD

-

%_builddir

-

Build directory.

-

The source code package is decompressed and compiled in a subdirectory of the directory.

-

~/rpmbuild/RPMS

-

%_rpmdir

-

Standard RPM package directory.

-

The binary RPM package is generated and stored in this directory.

-

~/rpmbuild/SOURCES

-

%_sourcedir

-

Source code directory.

-

The source code package (for example, .tar package) and all patches are stored in this directory.

-

~/rpmbuild/SPECS

-

%_specdir

-

Spec file directory.

-

The RPM package configuration file (.spec) is stored in this directory.

-

~/rpmbuild/SRPMS

-

%_srcrpmdir

-

Source code RPM package directory.

-

The source code RPM package (SRPM) is stored in this directory.

-
- -The **\~/rpmbuild/SPECS** directory contains the configuration file of the RPM package, which is the drawing of the RPM package. This file tells the **rpmbuild** command how to build the RPM package. The **Macro Code** column contains the corresponding directories in the .spec file, which is similar to the macro or global variable in the programming language. - -## Packaging Process - -The packaging process is as follows: - -1. Place the source code in **%\_sourcedir**. -2. Compile the source code in **%\_builddir**. Generally, the source code is compressed and needs to be decompressed first. -3. Install the RPM package. The installation is similar to pre-assembling the software package. Copy the contents \(such as binary files, configuration files, and man files\) that should be contained in the software package to **%\_buildrootdir** and assemble the contents based on the actual directory structure after installation. For example, if binary commands are stored in **/usr/bin**, copy the directory structure to **%\_buildrootdir**. -4. Perform necessary configurations, such as preparations before installation and cleanup after installation. These are configured in the SPEC file to tell the **rpmbuild** command how to build. -5. Check whether the software is running properly. -6. The generated RPM package is stored in **%\_rpmdir**, and the source code package is stored in **%\_srpmdir**. - -In the SPEC file, each phase is described as follows: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Phase

-

Directory to Be Read

-

Directory to Which Data Is Written

-

Action

-

%prep

-

%_sourcedir

-

%_builddir

-

Read the source code and patch in the %_sourcedir directory. Then, decompress the source code to the %_builddir subdirectory and apply all patches.

-

%build

-

%_builddir

-

%_builddir

-

Compile files in the %_builddir build directory. Run a command similar to ./configure && make.

-

%install

-

%_builddir

-

%_buildrootdir

-

Read files in the %_builddir build directory and install them to the %_buildrootdir directory. These files are generated after the RPM is installed.

-

%check

-

%_builddir

-

%_builddir

-

Check whether the software is running properly. Run a command similar to make test.

-

bin

-

%_buildrootdir

-

%_rpmdir

-

Read files in the %_buildrootdir final installation directory to create RPM packages in the %_rpmdir directory. In this directory, RPM packages of different architectures are stored in different subdirectories. The noarch directory stores RPM packages applicable to all architectures. These RPM files are the RPM packages that are finally installed by users.

-

src

-

%_sourcedir

-

%_srcrpmdir

-

Create the source code RPM package (SRPM for short, with the file name extension .src.rpm) and save it to the %_srcrpmdir directory. The SRPM package is usually used to review and upgrade software packages.

-
- -## Packaging Options - -Run the **rpmbuild** command to build the software package. The **rpmbuild** command can be used to build software packages by building .spec, .tar, and source files. - -The format of the **rpmbuild** command is rpmbuild \[_option_...\] - -[Table 1](#table1342946175212) describes the common rpmbuild packaging options. - -**Table 1** rpmbuild Packaging Options - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

option Value

-

Description

-

-bp specfile

-

Starts build from the %prep phase of the specfile (decompress the source code package and install the patch).

-

-bc specfile

-

Starts build from the %build phase of the specfile.

-

-bi specfile

-

Starts build from the %install phase of the specfile.

-

-bl specfile

-

Starts check from the %file phase of the specfile.

-

-ba specfile

-

Uses the specfile to build the source code package and binary package.

-

-bb specfile

-

Uses the specfile to build the binary package.

-

-bs specfile

-

Uses the specfile to build the source code package.

-

-rp sourcefile

-

Starts build from the %prep phase of the sourcefile (decompress the source code package and install the patch).

-

-rc sourcefile

-

Starts build from the %build phase of the sourcefile.

-

-ri sourcefile

-

Starts build from the %install phase of the sourcefile.

-

-rl sourcefile

-

Starts build from the %file phase of the sourcefile.

-

-ra sourcefile

-

Uses the sourcefile to build the source code package and binary package.

-

-rb sourcefile

-

Uses the sourcefile to build the binary package.

-

-rs sourcefile

-

Uses the sourcefile to build the source code package.

-

-tp tarfile

-

Starts build from the %prep phase of the tarfile (decompress the source code package and install the patch).

-

-tc tarfile

-

Starts build from the %build phase of the tarfile.

-

-ti tarfile

-

Starts build from the %install phase of the tarfile.

-

-ta tarfile

-

Uses the tarfile to build the source code package and binary package.

-

-tb tarfile

-

Uses the tarfile to build the binary package.

-

-ts tarfile

-

Uses the tarfile to build the source code package.

-

--buildroot=DIRECTORY

-

During the build, uses DIRECTORY to overwrite the default /root directory.

-

--clean

-

Deletes the files in the BUILD directory.

-

--nobuild

-

No actual build steps are performed. It can be used to test the .spec file.

-

--noclean

-

Skips the %clean phase of the .spec file (even if it does exist).

-

--nocheck

-

Skips the %check phase of the .spec file (even if it does exist).

-

--dbpath DIRECTORY

-

Uses the database in DIRECTORY instead of the default directory /var/lib/rpm.

-

--root DIRECTORY

-

Sets DIRECTORY to the highest level. The default value is /, indicating the highest level.

-

--rebuild sourcefile

-

Installs the specified source code package sourcefile, that is, start preparation, compilation, and installation of the source code package.

-

--recompile sourcefile

-

Builds a new binary package based on --recompile. When the build is complete, the build directory, source code, and .spec file are deleted.

-

The deletion effect is the same as that of --clean.

-

-?, --help

-

Displays detailed help information.

-

--version

-

Displays detailed version information.

-
- diff --git a/content/en/docs/ApplicationDev/preparation.md b/content/en/docs/ApplicationDev/preparation.md index 5e1cadbffa3aa829ff197dd19c26ddded92c6ecc..f2772258557074c5f7c7a8496156477848a05710 100644 --- a/content/en/docs/ApplicationDev/preparation.md +++ b/content/en/docs/ApplicationDev/preparation.md @@ -1,4 +1,464 @@ -# Preparation +# Preparation + +- [Preparation](#preparation) + - [Configuring the Development Environment](#configuring-the-development-environment) + - [OS Requirements](#os-requirements) + - [Configuring a Repo Source](#configuring-a-repo-source) + - [Configuring a Repo Source by Directly Obtaining the Repo Source File](#configuring-a-repo-source-by-directly-obtaining-the-repo-source-file) + - [Configuring a Repo Source by Mounting an ISO File](#configuring-a-repo-source-by-mounting-an-iso-file) + - [Installing the Software Package](#installing-the-software-package) + - [Installing the JDK Software Package](#installing-the-jdk-software-package) + - [Installing the rpm-build Software Package](#installing-the-rpm-build-software-package) + - [Using the IDE for Java Development](#using-the-ide-for-java-development) + - [Overview](#overview) + - [Logging In to the Server Using MobaXterm](#logging-in-to-the-server-using-mobaxterm) + - [Setting the JDK Environment](#setting-the-jdk-environment) + - [Downloading and Installing the GTK Library](#downloading-and-installing-the-gtk-library) + - [Setting X11 Forwarding](#setting-x11-forwarding) + - [Downloading and Running IntelliJ IDEA](#downloading-and-running-intellij-idea) + + +## Configuring the Development Environment + +- If physical machines \(PMs\) are used, the minimum hardware requirements of the development environment are described in [Table 1](#table154419352610). + + **Table 1** Minimum hardware specifications + + + + + + + + + + + + + + + + + + + + + + + + +

Component

+

Minimum Hardware Specification

+

Description

+

Architecture

+
  • AArch64
  • x86_64
+
  • 64-bit Arm architecture
  • 64-bit Intel x86 architecture
+

CPU

+
  • Huawei Kunpeng 920 series
  • Intel ® Xeon® processor
+

-

+

Memory

+

≥ 4 GB (8 GB or higher recommended for better user experience)

+

-

+

Hard disk

+

≥ 120 GB (for better user experience)

+

IDE, SATA, SAS interfaces are supported.

+
+ +- If virtual machines \(VMs\) are used, the minimum virtualization space required for the development environment is described in [Table 2](#table780410493819). + + **Table 2** Minimum virtualization space + + + + + + + + + + + + + + + + + + + + + + + + +

Component

+

Minimum Virtualization Space

+

Description

+

Architecture

+
  • AArch64
  • x86_64
+

-

+

CPU

+

Two CPUs

+

-

+

Memory

+

≥ 4 GB (8 GB or higher recommended for better user experience)

+

-

+

Hard disk

+

≥ 32 GB (120 GB or higher recommended for better user experience)

+

-

+
+ + +### OS Requirements + +The openEuler OS is required. + +For details about how to install the openEuler OS, see the _openEuler 20.03 LTS Installation Guide_. On the **SOFTWARE SELECTION** page, select **Development Tools** in the **Add-Ons for Selected Environment** area. + +## Configuring a Repo Source + +You can configure a repo source by directly obtaining the repo source file or by mounting an ISO file. + +### Configuring a Repo Source by Directly Obtaining the Repo Source File + +>![](public_sys-resources/icon-note.gif) **NOTE:** +>openEuler provides multiple repo source files. This section uses the OS repo source file of the AArch64 architecture as an example. + +1. Go to the yum source directory. + + ``` + cd /etc/yum.repos.d + ``` + +2. Create and edit the **local.repo** file. Configure the repo source file as the yum source. + + ``` + vi local.repo + ``` + + Edit the **local.repo** file as follows: + + \[basiclocal\] + + name=basiclocal + + baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/OS/aarch64/ + + enabled=1 + + gpgcheck=0 + + +### Configuring a Repo Source by Mounting an ISO File + +>![](public_sys-resources/icon-note.gif) **NOTE:** +>This section uses the **openEuler-20.03-LTS-aarch64-dvd.iso** image file and **openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum** verification file as examples. Modify them based on the actual requirements. + +1. Download the ISO image. + - Download an ISO image using a cross-platform file transfer tool. + 1. Log in to the openEuler community at [https://openeuler.org](https://openeuler.org). + 2. Click **Download**. + 3. Click the link provided after **Download ISO**. The download list is displayed. + 4. Select the version to be downloaded, for example, openEuler 20.03 LTS. Then, click **openEuler-20.03-LTS**. The download list is displayed. + 5. Click **ISO**. The ISO download list is displayed. + - **aarch64**: ISO image file of the AArch64 architecture + - **x86\_64**: ISO image file of the x86\_64 architecture + - **source**: ISO image file of the openEuler source code + + 6. Click **aarch64**. + 7. Click **openEuler-20.03-LTS-aarch64-dvd.iso** to download the openEuler release package to the local host. + 8. Click **openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum** to download the openEuler verification file to the local host. + 9. Log in to the openEuler OS and create a directory for storing the release package and verification file, for example, **/home/iso**. + + ``` + mkdir /home/iso + ``` + + 10. Use a cross-platform file transfer tool \(such as WinSCP\) to upload the local openEuler release package and verification file to the target openEuler OS. + + - Run the **wget** command to download the ISO image. + 1. Log in to the openEuler community at [https://openeuler.org](https://openeuler.org). + 2. Click **Download**. + 3. Click the link provided after **Download ISO**. The download list is displayed. + 4. Select the version to be downloaded, for example, openEuler 20.03 LTS. Then, click **openEuler-20.03-LTS**. The download list is displayed. + 5. Click **ISO**. The ISO download list is displayed. + - **aarch64**: ISO image file of the AArch64 architecture + - **x86\_64**: ISO image file of the x86\_64 architecture + - **source**: ISO image file of the openEuler source code + + 6. Click **aarch64**. + 7. Right-click **openEuler-20.03-LTS-aarch64-dvd.iso** and choose **Copy URL** from the shortcut menu to copy the address of the openEuler release package. + 8. Right-click **openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum** and choose **Copy URL** from the shortcut menu to copy the address of the openEuler verification file. + 9. Log in to the openEuler OS, create a directory \(for example, **/home/iso**\) for storing the release package and verification file, and switch to the directory. + + ``` + mkdir /home/iso + cd /home/iso + ``` + + 10. Run the **wget** command to remotely download the release package and verification file. In the command, **ipaddriso** and **ipaddrisosum** are the addresses copied in [1.g](#li62369349505) and [1.h](#li9236203405015). + + ``` + wget ipaddriso + wget ipaddrisosum + ``` + + +2. Release Package Integrity Check + 1. Obtain the verification value in the verification file. + + ``` + cat openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum + ``` + + 2. Calculate the SHA256 verification value of the openEuler release package. + + ``` + sha256sum openEuler-20.03-LTS-aarch64-dvd.iso + ``` + + After the command is run, the verification value is displayed. + + 3. Check whether the values calculated in step 1 and step 2 are consistent. + + If the verification values are consistent, the .iso file is not damaged. If they are inconsistent, the file is damaged and you need to obtain the file again. + +3. Mount the ISO image file and configure it as a repo source. + + Run the **mount** command to mount the image file. + + The following is an example: + + ``` + # mount /home/iso/openEuler-20.03-LTS-aarch64-dvd.iso /mnt/ + ``` + + The mounted **mnt** directory is as follows: + + ``` + . + │── boot.catalog + │── docs + │── EFI + │── images + │── Packages + │── repodata + │── TRANS.TBL + └── RPM-GPG-KEY-openEuler + ``` + + In the preceding command, **Packages** indicates the directory where the RPM package is stored, **repodata** indicates the directory where the repo source metadata is stored, and **RPM-GPG-KEY-openEuler** indicates the public key for signing openEuler. + + The mounted directory can be configured as the yum source. Create the \*\*\*.repo configuration file \(with the extension .repo\) in the **/etc/yum.repos.d/** directory. + + The following is an example: + + Create the openEuler.repo file in the **/etc/yum.repos.d** directory and use the local image mounting directory as the yum source. The content of the openEuler.repo file is as follows: + + ``` + [base] + name=base + baseurl=file:///mnt + enabled=1 + gpgcheck=1 + gpgkey=file:///mnt/RPM-GPG-KEY-openEuler + ``` + + **** + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >- **gpgcheck** indicates whether to enable the GNU privacy guard \(GPG\) to check the validity and security of the source of RPM packages. **1** indicates that the GPG check is enabled. **0** indicates that the GPG check is disabled. If this option is not specified, the GPG check is enabled by default. + >- **gpgkey** is the storage path of the signed public key. + + +## Installing the Software Package + +Install the software required for development. The software required varies in different development environments. However, the installation methods are the same. This section describes how to install common software packages \(such as JDK and rpm-build\). Some development software, such as GCC and GNU make, is provided by the openEuler OS by default. + + + +### Installing the JDK Software Package + +1. Run the **dnf list installed | grep jdk** command to check whether the JDK software is installed. + + ``` + dnf list installed | grep jdk + ``` + + Check the command output. If the command output contains "jdk", the JDK has been installed. If no such information is displayed, the software is not installed. + +2. Clear the cache. + + ``` + dnf clean all + ``` + +3. Create a cache. + + ``` + dnf makecache + ``` + +4. Query the JDK software package that can be installed. + + ``` + dnf search jdk | grep jdk + ``` + + View the command output and install the **java-x.x.x-openjdk-devel.aarch64** software package. **x.x.x** indicates the version number. + +5. Install the JDK software package. The following uses the **java-1.8.0-openjdk-devel** software package as an example. + + ``` + dnf install java-1.8.0-openjdk-devel.aarch64 + ``` + +6. Query information about the JDK software. + + ``` + java -version + ``` + + Check the command output. If the command output contains "openjdk version "1.8.0\_232"", the JDK has been correctly installed. In the command output, **1.8.0\_232** indicates the JDK version. + + +### Installing the rpm-build Software Package + +1. Run the **dnf list installed | grep rpm-build** command to check whether the rpm-build software is installed. + + ``` + dnf list installed | grep rpm-build + ``` + + Check the command output. If the command output contains "rpm-build", the software has been installed. If no such information is displayed, the software is not installed. + +2. Clear the cache. + + ``` + dnf clean all + ``` + +3. Create a cache. + + ``` + dnf makecache + ``` + +4. Install the rpm-build package. + + ``` + dnf install rpm-build + ``` + +5. Query the rpm-build software version. + + ``` + rpmbuild --version + ``` + + +## Using the IDE for Java Development + +For small-sized Java applications, you can directly use JDK to compile them to run Java applications. However, for medium- and large-sized Java applications, this method cannot meet the development requirements. You can perform the following steps to install and use the IDE to facilitate Java development on the openEuler OS. + + + +### Overview + +IntelliJ IDEA is a popular Java IDE. You can download the community edition of IntelliJ IDEA for free. Currently, openEuler supports Java development in the IntelliJ IDEA integrated development environment \(IDE\), improving the work efficiency of developers. + +### Logging In to the Server Using MobaXterm + +MobaXterm is an excellent SSH client. It has an X Server and can easily solve remote GUI display problems. + +You need to download, install, and start MobaXterm in advance, and then log in to your server in SSH mode to perform the following operations: + +### Setting the JDK Environment + +Before setting JAVA\_HOME, you need to find the installation path of the JDK. You are supported to have installed the JDK. If you have not installed the JDK, install it by referring to Preparation \> Installing the Software Package \> Installing the JDK Software Package. + +Run the following command to view the Java path: + +``` +# which java +/usr/bin/java +``` + +Run the following command to check the directory to which the soft link points: + +``` +# ls -la /usr/bin/java +lrwxrwxrwx. 1 root root 22 Mar 6 20:28 /usr/bin/java -> /etc/alternatives/java +# ls -la /etc/alternatives/java +lrwxrwxrwx. 1 root root 83 Mar 6 20:28 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64/jre/bin/java +``` + +The actual path is **/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64**. Run the following command to set **JAVA\_HOME** and **PATH**: + +``` +# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64 +# export PATH=$JAVA_HOME/bin:$PATH +``` + +### Downloading and Installing the GTK Library + +Ensure that you have the **root** permission and run the following command: + +``` +# dnf list installed | grep gtk +``` + +If **gtk2** or **gtk3** is displayed, the GTK library has been installed. In this case, skip this step. Otherwise, run the following command to automatically download and install the GTK library: + +``` +# dnf -y install gtk2 libXtst libXrender xauth +``` + +### Setting X11 Forwarding + +Switch to the SSHD configuration directory. + +``` +# cd ~/.ssh +``` + +If the directory does not exist, run the following command to create the directory and then switch to the directory: + +``` +# mkdir ~/.ssh +``` + +Edit the configuration file in the **.ssh** directory and save the file. + +1. Run the **vim** command to open the configuration file. + + ``` + # vim config + ``` + +2. Add the following content to the end of the file and save the file: + + ``` + Host * + ForwardAgent yes + ForwardX11 yes + ``` + + +### Downloading and Running IntelliJ IDEA + +After the preceding environment configuration is complete, you can download and run the IntelliJ IDEA. The latest version of IntelliJ IDEA is incompatible with openEuler in some functions. You are advised to click [here](https://www.jetbrains.com/idea/download/other.html) and download the Linux package of the 2018 version. Move the downloaded package to the directory where you want to install the software and decompress the package. + +``` +# tar xf ideaIC-2018.3.tar.gz +``` + +Decompress the package, switch to the IntelliJ IDEA directory, and run the IntelliJ IDEA. + +``` +# cd ./idea-IC-183.4284.148 +# bin/idea.sh & +``` diff --git a/content/en/docs/ApplicationDev/setting-the-jdk-environment.md b/content/en/docs/ApplicationDev/setting-the-jdk-environment.md deleted file mode 100644 index c3e53937de1669de5081d4558902c3de447de0f3..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/setting-the-jdk-environment.md +++ /dev/null @@ -1,27 +0,0 @@ -# Setting the JDK Environment - -Before setting JAVA\_HOME, you need to find the installation path of the JDK. You are supported to have installed the JDK. If you have not installed the JDK, install it by referring to Preparation \> Installing the Software Package \> Installing the JDK Software Package. - -Run the following command to view the Java path: - -``` -# which java -/usr/bin/java -``` - -Run the following command to check the directory to which the soft link points: - -``` -# ls -la /usr/bin/java -lrwxrwxrwx. 1 root root 22 Mar 6 20:28 /usr/bin/java -> /etc/alternatives/java -# ls -la /etc/alternatives/java -lrwxrwxrwx. 1 root root 83 Mar 6 20:28 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64/jre/bin/java -``` - -The actual path is **/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64**. Run the following command to set **JAVA\_HOME** and **PATH**: - -``` -# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64 -# export PATH=$JAVA_HOME/bin:$PATH -``` - diff --git a/content/en/docs/ApplicationDev/setting-up-the-development-environment.md b/content/en/docs/ApplicationDev/setting-up-the-development-environment.md deleted file mode 100644 index 7a0eac3c618eadbd21e33493411fb2fd15e9bc45..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/setting-up-the-development-environment.md +++ /dev/null @@ -1,14 +0,0 @@ -# Setting Up the Development Environment - -## Prerequisites - -You have obtained the **root** permission, and have configured a repo source for openEuler. - -## Procedure - -You can use the DNF tool to install rpmdevtools, including the **rpm-build** command and related dependencies \(such as make and gdb\). Run the following command: - -``` -# dnf install rpmdevtools* -``` - diff --git a/content/en/docs/ApplicationDev/setting-x11-forwarding.md b/content/en/docs/ApplicationDev/setting-x11-forwarding.md deleted file mode 100644 index 8e7005e2bffd7e8f7d5e075947a8329b38c89e3b..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/setting-x11-forwarding.md +++ /dev/null @@ -1,31 +0,0 @@ -# Setting X11 Forwarding - -Switch to the SSHD configuration directory. - -``` -# cd ~/.ssh -``` - -If the directory does not exist, run the following command to create the directory and then switch to the directory: - -``` -# mkdir ~/.ssh -``` - -Edit the configuration file in the **.ssh** directory and save the file. - -1. Run the **vim** command to open the configuration file. - - ``` - # vim config - ``` - -2. Add the following content to the end of the file and save the file: - - ``` - Host * - ForwardAgent yes - ForwardX11 yes - ``` - - diff --git a/content/en/docs/ApplicationDev/static-link-library.md b/content/en/docs/ApplicationDev/static-link-library.md deleted file mode 100644 index 2db3583a80977e52a204ab2d6151ead721757d92..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/static-link-library.md +++ /dev/null @@ -1,31 +0,0 @@ -# Static Link Library - -To create a static link library \(SLL\), you need to compile the source file to the target file, and then run the **ar** command to compress the target file into an SLL. - -Example: Compile and compress source files **test1.c**, **test2.c**, and **test3.c** into an SLL. - -``` -gcc -c test1.c test2.c test3.c -ar rcs libtest.a test1.o test2.o test3.o -``` - -The **ar** command is a backup compression command. You can compress multiple files into a backup file \(also called an archive file\) or extract member files from the backup file. The most common use of **ar** is to compress the target files into an SLL. - -The format of the **ar** command to compress the target files into an SLL is as follows: - -ar rcs _Sllfilename_ _Targetfilelist_ - -- _Sllfilename_: Name of the static library file. -- _Targetfilelist_: Target file list. -- **r**: replaces the existing target file in the library or adds a new target file. -- **c**: creates a library regardless of whether the library exists. -- **s**: creates the index of the target file. The speed can be improved when a large library is created. - -Example: Create a main.c file to use the SLL. - -``` -gcc main.c -L libraryDIR -ltest -o test.out -``` - -In the preceding command, **libraryDIR** indicates the path of the libtest.a library. - diff --git a/content/en/docs/ApplicationDev/terms-of-use.md b/content/en/docs/ApplicationDev/terms-of-use.md deleted file mode 100644 index cc1b4840e3240264bb36bd7f1cdce0db32547dc4..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/terms-of-use.md +++ /dev/null @@ -1,14 +0,0 @@ -# Terms of Use - -**Copyright © Huawei Technologies Co., Ltd. 2020. All rights reserved.** - -Your replication, use, modification, and distribution of this document are governed by the Creative Commons License Attribution-ShareAlike 4.0 International Public License \(CC BY-SA 4.0\). You can visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/) to view a human-readable summary of \(and not a substitute for\) CC BY-SA 4.0. For the complete CC BY-SA 4.0, visit [https://creativecommons.org/licenses/by-sa/4.0/legalcode](https://creativecommons.org/licenses/by-sa/4.0/legalcode). - -**Trademarks and Permissions** - -openEuler is a trademark or registered trademark of Huawei Technologies Co., Ltd. All other trademarks and registered trademarks mentioned in this document are the property of their respective holders. - -**Disclaimer** - -This document is used only as a guide. Unless otherwise specified by applicable laws or agreed by both parties in written form, all statements, information, and recommendations in this document are provided "AS IS" without warranties, guarantees or representations of any kind, including but not limited to non-infringement, timeliness, and specific purposes. - diff --git a/content/en/docs/ApplicationDev/using-gcc-for-compilation.md b/content/en/docs/ApplicationDev/using-gcc-for-compilation.md index 539ad01f9a46e2681a88edd90fca271831e6b94c..eb596a947c73e9e1c72b613d161887c32ddf958a 100644 --- a/content/en/docs/ApplicationDev/using-gcc-for-compilation.md +++ b/content/en/docs/ApplicationDev/using-gcc-for-compilation.md @@ -1,6 +1,624 @@ -# Using GCC for Compilation +# Using GCC for Compilation This chapter describes the basic knowledge of GCC compilation and provides examples for demonstration. For more information about GCC, run the **man gcc** command. + +- [Using GCC for Compilation](#using-gcc-for-compilation) + - [Overview](#overview) + - [Basics](#basics) + - [File Type](#file-type) + - [Compilation Process](#compilation-process) + - [Compilation Options](#compilation-options) + - [Multi-file Compilation](#multi-file-compilation) + - [Libraries](#libraries) + - [Dynamic Link Library](#dynamic-link-library) + - [Static Link Library](#static-link-library) + - [Examples](#examples) + - [Example for Using GCC to Compile C Programs](#example-for-using-gcc-to-compile-c-programs) + - [Example for Creating and Using a DLL Using GCC](#example-for-creating-and-using-a-dll-using-gcc) + - [Example for Creating and Using an SLL Using GCC](#example-for-creating-and-using-an-sll-using-gcc) + + +## Overview + +The GNU Compiler Collection \(GCC\) is a powerful and high-performance multi-platform compiler developed by GNU. The GCC compiler can compile and link source programs, assemblers, and target programs of C and C++ into executable files. By default, the GCC software package is installed in the openEuler OS. + +## Basics + + + +### File Type + +For any given input file, the file type determines which compilation to perform. [Table 1](#table634145764320) describes the common GCC file types. + +**Table 1** Common GCC file types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Extension (Suffix)

+

Description

+

.c

+

C source code file.

+

.C, .cc, or .cxx

+

C++ source code file.

+

.m

+

Objective-C source code file.

+

.s

+

Assembly language source code file.

+

.i

+

Preprocessed C source code file.

+

.ii

+

Preprocessed C++ source code file.

+

.S

+

Pre-processed assembly language source code file.

+

.h

+

Header file contained in the program.

+

.o

+

Target file after compilation.

+

.so

+

Dynamic link library, which is a special target file.

+

.a

+

Static link library.

+

.out

+

Executable files, which do not have a fixed suffix. The system distinguishes executable files from unexecutable files based on file attributes. If the name of an executable file is not given, GCC generates a file named a.out.

+
+ +### Compilation Process + +Using GCC to generate executable files from source code files requires preprocessing, compilation, assembly, and linking. + +1. Preprocessing: Preprocess the source program \(such as a **.c** file\) to generate an **.i** file. +2. Compilation: Compile the preprocessed **.i** file into an assembly language to generate an **.s** file. +3. Assemble: Assemble the assembly language file to generate the target file **.o**. +4. Linking: Link the **.o** files of each module to generate an executable program file. + +The **.i**, **.s**, and **.o** files are intermediate or temporary files. If the GCC is used to compile programs in C language at a time, these files will be deleted. + +### Compilation Options + +GCC compilation command format: **gcc** \[_options_\] \[_filenames_\] + +In the preceding information: + +_options_ : compilation options. + +_filenames_ : file name. + +GCC is a powerful compiler. It has many _options_, but most of them are not commonly used. [Table 2](#table1342946175212) describes the common _options_. + +**Table 2** Common GCC compilation options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

options Value

+

Description

+

Example

+

-c

+

Compiles and assembles specified source files to generate target files without linking them. It is usually used to compile subprogram files.

+

# Use the -c option to compile the source files test1.c and test2.c.

+

gcc -c test1.c test2.c

+

-S

+

Compiles the specified source file to generate an assembly language file with the .s suffix but without assembling it.

+

# Use the compiler to preprocess circle.c, translate it into assembly language, and store the result in circle.s.

+

gcc -S circle.c

+

-E

+

Preprocesses specified source files without compiling them.

+

By default, the output of the preprocessor is imported to a standard output stream, such as a display. You can use the -o option to import it to an output file.

+

# Export the preprocessing result to the circle.i file.

+

gcc -E circle.c -o circle.i

+

-o file

+

Generates a specified output file when an executable file is generated. The name must be different from that of the source file. If this option is not given, GCC generates the preset executable file a.out.

+

# Use the source file as the input file and the executable file as the output file. That is, compile the entire program.

+

gcc main.c func.c -o app.out

+

-g

+

Contains standard debugging information in executable programs.

+

-

+

-L libary_path

+

Adds the library_path to the library file search path list.

+

-

+

-Ilibrary

+

Searches for the specified function library during linking.

+

When GCC is used to compile and link programs, GCC links libc.a or libc.so by default. However, other libraries (such as non-standard libraries and third-party libraries) need to be manually added.

+

# Use the -l option to link the math library.

+

gcc main.c -o main.out -lm

+
NOTE:

The file name of the math library is libm.a. The prefix lib and suffix .a are standard, and m is the basic name. GCC automatically adds these prefixes and suffixes to the basic name following the -l option. In this example, the basic name is m.

+
+

-I head_path

+

Adds the head_path to the search path list of the header file.

+

-

+

-static

+

Performs static compilation and links static libraries. Do not link dynamic libraries.

+

-

+

-shared

+

Default option, which can be omitted.

+
  • A dynamic library file can be generated.
  • During dynamic compilation, the dynamic library is preferentially linked. The static library with the same name is linked only when there is no dynamic library.
+

-

+

-fPIC (or -fpic)

+

Generates location-independent target code that uses a relative address. Generally, the -static option is used to generate a dynamic library file from the PIC target file.

+

-

+
+ +### Multi-file Compilation + +There are two methods provided for compiling multiple source files. + +- Multiple source files are compiled at the same time. All files need to be recompiled during compilation. + + Example: Compile **test1.c** and **test2.c** and link them to the executable file **test**. + + ``` + gcc test1.c test2.c -o test + ``` + +- Compile each source file, and then link the target files generated after compilation. During compilation, only modified files need to be recompiled. + + For example, compile **test1.c** and **test2.c**, and link the target files **test1.o** and **test2.o** to the executable file **test**. + + ``` + gcc -c test1.c + gcc -c test2.c + gcc -o test1.o test2.o -o test + ``` + + +## Libraries + +A library is mature and reusable code that has been written for use. Each program depends on many basic underlying libraries. + +The library file name is prefixed with lib and suffixed with .so \(dynamic library\) or .a \(static library\). The middle part is the user-defined library file name, for example, libfoo.so or libfoo.a. Because all library files comply with the same specifications, the **lib** prefix can be omitted when the **-l** option specifies the name of the linked library file. That is, when GCC processes **-lfoo**, the library file **libfoo.so** or **libfoo.a** is automatically linked. When creating a library, you must specify the full file name **libfoo.so** or **libfoo.a**. + +Libraries are classified into static libraries and dynamic libraries based on the linking time. The static library links and packs the target file .o generated by assembly and the referenced library into an executable file in the linking phase. The dynamic library is not linked to the target code when the program is compiled, but is loaded when the program is run. The differences are as follows: + +- The resource usage is different. + + The static library is a part of the generated executable file, while the dynamic library is a separate file. Therefore, the sizes and occupied disk space of the executable files of the static library and dynamic library are different, which leads to different resource usage. + +- The scalability and compatibility are different. + + If the implementation of a function in the static library changes, the executable file must be recompiled. For the executable file generated by dynamic linking, only the dynamic library needs to be updated, and the executable file does not need to be recompiled. + +- The dependency is different. + + The executable file of the static library can run without depending on any other contents, while the executable file of the dynamic library must depend on the dynamic library. Therefore, the static library is convenient to migrate. + +- The loading speeds are different. + + Static libraries are linked together with executable files, while dynamic libraries are linked only when they are loaded or run. Therefore, for the same program, static linking is faster than dynamic linking. + + + +### Dynamic Link Library + +You can use the **-shared** and **-fPIC** options to create a dynamic link library \(DLL\) with the source file, assembly file, or target file. The **-fPIC** option is used in the compilation phase. This option is used when the target file is generated, so as to generate location-independent code. + +Example 1: Generate a DLL from the source file. + +``` +gcc -fPIC -shared test.c -o libtest.so +``` + +Example 2: Generate a DLL from the target file. + +``` +gcc -fPIC -c test.c -o test.o +gcc -shared test.o -o libtest.so +``` + +To link a DLL to an executable file, you need to list the name of the DLL in the command line. + +Example: Compile **main.c** and **libtest.so** into **app.out**. When **app.out** is running, the link library **libtest.so** is dynamically loaded. + +``` +gcc main.c libtest.so -o app.out +``` + +In this mode, the **libtest.so** file in the current directory is used. + +If you choose to search for a DLL, to ensure that the DLL can be linked when the program is running, you must implement by using one of the following methods: + +- Save the DLL to a standard directory, for example, **/usr/lib**. +- Add the DLL path **libaryDIR** to the environment variable **LD\_LIBRARY\_PATH**. + + export LD\_LIBRARY\_PATH=libraryDIR:$LD\_LIBRARY\_PATH + + >![](public_sys-resources/icon-note.gif) **NOTE:** + >**LD\_LIBRARY\_PATH** is an environment variable of the DLL. If the DLL is not in the default directories \(**/lib** and **/usr/lib**\), you need to specify the environment variable **LD\_LIBRARY\_PATH**. + +- Add the DLL path **libaryDIR** to **/etc/ld.so.conf** and run **ldconfig**, or use the DLL path **libaryDIR** as a parameter to run **ldconfig**. + +``` +gcc main.c -L libraryDIR -ltest -o app.out +export LD_LIBRARY_PATH=libraryDIR:$LD_LIBRARY_PATH +``` + +### Static Link Library + +To create a static link library \(SLL\), you need to compile the source file to the target file, and then run the **ar** command to compress the target file into an SLL. + +Example: Compile and compress source files **test1.c**, **test2.c**, and **test3.c** into an SLL. + +``` +gcc -c test1.c test2.c test3.c +ar rcs libtest.a test1.o test2.o test3.o +``` + +The **ar** command is a backup compression command. You can compress multiple files into a backup file \(also called an archive file\) or extract member files from the backup file. The most common use of **ar** is to compress the target files into an SLL. + +The format of the **ar** command to compress the target files into an SLL is as follows: + +ar rcs _Sllfilename_ _Targetfilelist_ + +- _Sllfilename_ : Name of the static library file. +- _Targetfilelist_ : Target file list. +- **r**: replaces the existing target file in the library or adds a new target file. +- **c**: creates a library regardless of whether the library exists. +- **s**: creates the index of the target file. The speed can be improved when a large library is created. + +Example: Create a main.c file to use the SLL. + +``` +gcc main.c -L libraryDIR -ltest -o test.out +``` + +In the preceding command, **libraryDIR** indicates the path of the libtest.a library. + +## Examples + + + +### Example for Using GCC to Compile C Programs + +1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. The command is as follows: + + ``` + cd /home/code + ``` + +2. Compile the Hello World program and save it as **helloworld.c**. The following uses the Hello World program as an example. The command is as follows: + + ``` + vi helloworld.c + ``` + + Code example: + + ``` + #include + int main() + { + printf("Hello World!\n"); + return 0; + } + ``` + +3. Run the following command to compile the code in the code directory: + + ``` + gcc helloworld.c -o helloworld + ``` + + If no error is reported, the execution is successful. + +4. After the compilation is complete, the helloworld file is generated. Check the compilation result. The following is an example: + + ``` + # ./helloworld + Hello World! + ``` + + +### Example for Creating and Using a DLL Using GCC + +1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. Create the **src**, **lib**, and **include** subdirectories in the directory to store the source file, DLL file, and header file, respectively. + + ``` + cd /home/code + mkdir src + mkdir lib + mkdir include + ``` + +2. Run the **cd** command to go to the **/home/code/src** directory and create two functions **add.c** and **sub.c** to implement addition and subtraction, respectively. + + ``` + cd /home/code/src + vi add.c + vi sub.c + ``` + + The following is an example of the **add.c** code: + + ``` + #include "math.h" + int add(int a, int b) + { + return a+b; + } + ``` + + The following is an example of the **sub.c** code: + + ``` + #include "math.h" + int sub(int a, int b) + { + return a-b; + } + ``` + +3. Compile the source files add.c and sub.c into the DLL libmath.so, and store the DLL in the **/home/code/lib** directory. + + ``` + gcc -fPIC -shared add.c sub.c -o /home/code/lib/libmath.so + ``` + +4. Go to the **/home/code/include** directory, create a header file **math.h**, and declare the header file of the function. + + ``` + cd /home/code/include + vi math.h + ``` + + The following is an example of the **math.h** code: + + ``` + #ifndef __MATH_H_ + #define __MATH_H_ + int add(int a, int b); + int sub(int a, int b); + #endif + ``` + +5. Run the **cd** command to go to the **/home/code/src** directory and create a **main.c** function that invokes add\(\) and sub\(\). + + ``` + cd /home/code/src + vi main.c + ``` + + The following is an example of the **math.c** code: + + ``` + #include + #include "math.h" + int main() + { + int a, b; + printf("Please input a and b:\n"); + scanf("%d %d", &a, &b); + printf("The add: %d\n", add(a,b)); + printf("The sub: %d\n", sub(a,b)); + return 0; + } + ``` + +6. Compile **main.c** and **libmath.so** into **math.out**. + + ``` + gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out + ``` + +7. Add the path of the DLL to the environment variable. + + ``` + export LD_LIBRARY_PATH=/home/code/lib:$LD_LIBRARY_PATH + ``` + +8. Run the following command to execute **math.out**: + + ``` + ./math.out + ``` + + The command output is as follows: + + ``` + Please input a and b: + 9 2 + The add: 11 + The sub: 7 + ``` + + +### Example for Creating and Using an SLL Using GCC + +1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. Create the **src**, **lib**, and **include** subdirectories in the directory to store the source file, SLL file, and header file respectively. + + ``` + cd /home/code + mkdir src + mkdir lib + mkdir include + ``` + +2. Run the **cd** command to go to the **/home/code/src** directory and create two functions **add.c** and **sub.c** to implement addition and subtraction, respectively. + + ``` + cd /home/code/src + vi add.c + vi sub.c + ``` + + The following is an example of the **add.c** code: + + ``` + #include "math.h" + int add(int a, int b) + { + return a+b; + } + ``` + + The following is an example of the **sub.c** code: + + ``` + #include "math.h" + int sub(int a, int b) + { + return a-b; + } + ``` + +3. Compile the source files **add.c** and **sub.c** into the target files **add.o** and **sub.o**. + + ``` + gcc -c add.c sub.c + ``` + +4. Run the **ar** command to compress the **add.o** and **sub.o** target files into the SLL **libmath.a** and save the SLL to the **/home/code/lib** directory. + + ``` + ar rcs /home/code/lib/libmath.a add.o sub.o + ``` + +5. Go to the **/home/code/include** directory, create a header file **math.h**, and declare the header file of the function. + + ``` + cd /home/code/include + vi math.h + ``` + + The following is an example of the **math.h** code: + + ``` + #ifndef __MATH_H_ + #define __MATH_H_ + int add(int a, int b); + int sub(int a, int b); + #endif + ``` + +6. Run the **cd** command to go to the **/home/code/src** directory and create a **main.c** function that invokes add\(\) and sub\(\). + + ``` + cd /home/code/src + vi main.c + ``` + + The following is an example of the **math.c** code: + + ``` + #include + #include "math.h" + int main() + { + int a, b; + printf("Please input a and b:\n"); + scanf("%d %d", &a, &b); + printf("The add: %d\n", add(a,b)); + printf("The sub: %d\n", sub(a,b)); + return 0; + } + ``` + +7. Compile **main.c** and **libmath.a** into **math.out**. + + ``` + gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out + ``` + +8. Run the following command to execute **math.out**: + + ``` + ./math.out + ``` + + The command output is as follows: + + ``` + Please input a and b: + 9 2 + The add: 11 + The sub: 7 + ``` diff --git a/content/en/docs/ApplicationDev/using-jdk-for-compilation.md b/content/en/docs/ApplicationDev/using-jdk-for-compilation.md index 2d3b7505c37a11aaafff1ff2c07bb7ae5cb94fde..be343ae87cac30b5833e6f0944d1f3e07ee197db 100644 --- a/content/en/docs/ApplicationDev/using-jdk-for-compilation.md +++ b/content/en/docs/ApplicationDev/using-jdk-for-compilation.md @@ -1,3 +1,532 @@ -# Using JDK for Compilation +# Using JDK for Compilation + +- [Using JDK for Compilation](#using-jdk-for-compilation) + - [Overview](#overview) + - [Basics](#basics) + - [File Type and Tool](#file-type-and-tool) + - [Java Program Generation Process](#java-program-generation-process) + - [Common JDK Options](#common-jdk-options) + - [Class Library](#class-library) + - [Package Declaration](#package-declaration) + - [Package Reference](#package-reference) + - [Examples](#examples) + - [Compiling a Java Program Without a Package](#compiling-a-java-program-without-a-package) + - [Compiling a Java Program with a Package](#compiling-a-java-program-with-a-package) + + +## Overview + +A Java Development Kit \(JDK\) is a software package required for Java development. It contains the Java Runtime Environment \(JRE\) and compilation and commissioning tools. On the basis of OpenJDK, openEuler optimizes GC, enhances concurrency stability, and enhances security, improving the performance and stability of Java applications on ARM. + +## Basics + + + +### File Type and Tool + +For any given input file, the file type determines which tool to use for processing. The common file types and tools are described in [Table 1](#table634145764320) and [Table 2](#table103504146433). + +**Table 1** Common JDK file types + + + + + + + + + + + + + + + + +

Extension (Suffix)

+

Description

+

.java

+

Java source code file.

+

.class

+

Java bytecode file, which is intermediate code irrelevant to any specific machine or OS environment. It is a binary file, which is the target code file generated after the Java source file is compiled by the Java compiler.

+

.jar

+

JAR package of Java files.

+
+ +**Table 2** Common JDK tools + + + + + + + + + + + + + + + + +

Name

+

Description

+

java

+

Java running tool, which is used to run .class bytecode files or .jar files.

+

javac

+

Compiles Java source code files into .class bytecode files.

+

jar

+

Creates and manages JAR files.

+
+ +### Java Program Generation Process + +To generate a program from Java source code files and run the program using Java, compilation and run are required. + +1. Compilation: Use the Java compiler \(javac\) to compile Java source code files \(.java files\) into .class bytecode files. +2. Run: Execute the bytecode files on the Java virtual machine \(JVM\). + +### Common JDK Options + +#### Javac Compilation Options + +The command format for javac compilation is as follows: **javac** \[_options_\] \[_sourcefiles_\] \[_classes_\] \[@_argfiles_\] + +In the preceding information: + +_options_: command options. + +_sourcefiles_: one or more source files to be compiled. + +_classes_: one or more classes to be processed as comments. + +@_argfiles_: one or more files that list options and source files. The **-J** option is not allowed in these files. + +Javac is a Java compiler. It has many _options_, but most of them are not commonly used. [Table 3](#table1342946175212) describes the common options values. + +**Table 3** Common javac options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

options Value

+

Description

+

Example

+

-d path

+

Path for storing the generated class files.

+

By default, the class files generated after compilation are in the same path as the source file. You can use the -d option to export the class files to the specified path.

+

# Use the -d option to export all class files to the bin directory.

+

javac /src/*.java -d /bin

+

-s path

+

Path for storing the generated source files.

+

-

+

-cp path or -classpath path

+

Searches for the class files required for compilation and specifies the location of the class files.

+

# In the Demo, the getLine() method in the GetStringDemo class needs to be invoked. The .class file compiled by the GetStringDemo class is stored in the bin directory.

+

javac -cp bin Demo.java -d bin

+

-verbose

+

Outputs information about the operations being performed by the compiler, such as loaded class information and compiled source file information.

+

# Display information about the operations that are being performed by the compiler.

+

javac -verbose -cp bin Demo.java

+

-source sourceversion

+

Specifies the location of the input source files to be searched for.

+

-

+

-sourcepath path

+

Searches for source files (Java files) required for compilation and specifies the location of the source files to be searched for, for example, JAR, ZIP, or other directories that contain Java files.

+

-

+

-target targetversion

+

Generates class files of a specific JVM version. The value can be 1.1, 1.2, 1.3, 1.4, 1.5 (or 5), 1.6 (or 6), 1.7 (or 7), or 1.8 (or 8). The default value of targetversion is related to sourceversion of the -source option. The options of sourceversion are as follows:

+
  • 1.2, corresponding to target version 1.4
  • 1.3, corresponding to target version 1.4
  • 1.5, 1.6, 1.7, and unspecified, corresponding to target version 1.8
  • For other values, the values of targetversion and sourceversion are the same.
+

-

+
+ +#### Java Running Options + +The Java running format is as follows: + +Running class file: **java** \[_options_\] _classesname_ \[args\] + +Running Java file: **java** \[_options_\] -jar _filename_ \[args\] + +In the preceding information: + +_options_: command options, which are separated by spaces. + +_classname_: name of the running .class file. + +_filename_: name of the running .jar file. + +args: parameters transferred to the main\(\) function. The parameters are separated by spaces. + +Java is a tool for running Java applications. It has many _options_, but most of them are not commonly used. [Table 4](#table371918587238) describes the common options. + +**Table 4** Common Java running options + + + + + + + + + + + + + + + + +

options Value

+

Description

+

Example

+

-cp path or -classpath path

+

Specifies the location of the file to be run and the class path to be used, including the .jar, .zip, and class file directories.

+

If there are multiple paths, separate them with colons (:).

+

-

+

-verbose

+

Outputs information about the operations being performed by the compiler, such as loaded class information and compiled source file information.

+

# Display information about the operations that are being performed by the compiler.

+

java -verbose -cp bin Demo.java

+
+ +#### JAR Options + +The JAR command format is as follows: **jar** \{c | t | x | u\}\[vfm0M\] \[_jarfile_\] \[_manifest_\] \[-C _dir_\] _file_... + +[Table 5](#table3691718114817) describes the parameters in the **jar** command. + +**Table 5** JAR parameter description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Parameter

+

Description

+

Example

+

c

+

Creates a JAR package.

+

# Compress the hello.class files in the current directory into Hello.jar. The compression process is not displayed. If the Hello.jar files do not exist, create them. Otherwise, clear the directory.

+

jar cf Hello.jar hello.class

+

t

+

Lists the contents of a JAR package.

+

# List the files contained in Hello.jar.

+

jar tf Hello.jar

+

x

+

Decompresses a JAR package.

+

# Decompress Hello.jar to the current directory. No information is displayed.

+

jar xf Hello.jar

+

u

+

Updates the existing JAR package, for example, add files to the JAR package.

+

-

+

v

+

Generates a detailed report and prints it to the standard output.

+

# Compress the hello.class files in the current directory into Hello.jar and display the compression process. If the Hello.jar files do not exist, create them. Otherwise, clear the directory.

+

jar cvf Hello.jar hello.class

+

f

+

Specifies the name of a JAR package. This parameter is mandatory.

+

-

+

m

+

Specifies the manifest file to be contained.

+

-

+

0

+

If this parameter is not set, the generated JAR package is larger but faster than that generated when this parameter is not set.

+

-

+

M

+

If the manifest file of all items is not generated, this parameter will be ignored.

+

# Compress the hello.class files in the current directory into Hello.jar and display the compression process. If the Hello.jar files do not exist, create them. Otherwise, clear the directory. However, the manifest file is not generated when Hello.jar is created.

+

jar cvfM Hello.jar hello.class

+

jarfile

+

JAR package, which is an auxiliary parameter of the f parameter.

+

-

+

manifest

+

Manifest file in .mf format, which is an auxiliary parameter of the m parameter.

+

-

+

-C dir

+

Runs the jar command in the specified dir. This command can be used only with parameters c and t.

+

-

+

file

+

Specifies the file or path list. All files in the file or path (including those in the recursive path) are compressed into the JAR package or the JAR package is decompressed to the path.

+

# Compress all class files in the current directory into Hello.jar and display the compression process. If the Hello.jar files do not exist, create them. Otherwise, clear the directory.

+

jar cvf Hello.jar *.class

+
+ +## Class Library + +The Java class library is implemented as a package, which is a collection of classes and interfaces. The Java compiler generates a bytecode file for each class, and the file name is the same as the class name. Therefore, conflicts may occur between classes with the same name. In the Java language, a group of classes and interfaces are encapsulated in a package. Class namespaces can be effectively managed by package. Classes in different packages do not conflict even if they have the same name. This solves the problem of conflicts between classes with the same name and facilitates the management of a large number of classes and interfaces. It also ensures the security of classes and interfaces. + +In addition to many packages provided by Java, developers can customize packages by collecting compiled classes and interfaces into a package for future use. + +Before using a custom package, you need to declare the package. + +### Package Declaration + +The declaration format of a package is package pkg1\[.pkg2\[.pkg3...\]\]. + +To declare a package, you must create a directory. The subdirectory name must be the same as the package name. Then declare the package at the beginning of the class file that needs to be placed in the package, indicating that all classes of the file belong to the package. The dot \(.\) in the package declaration indicates the directory hierarchy. If the source program file does not contain the package statement, the package is specified as an anonymous package. An anonymous package does not have a path. Generally, Java still stores the classes in the source file in the current working directory \(that is, the directory where the Java source files are stored\). + +The package declaration statement must be added to the beginning of the source program file and cannot be preceded by comments or spaces. If you use the same package declaration statement in different source program files, you can include the classes in different source program files in the same package. + +### Package Reference + +In Java, there are two methods to use the common classes in the package provided by Java or the classes in the custom package. + +- Add the package name before the name of the class to be referenced. + + For example, name.A obj=new name.A \(\) + + **name** indicates the package name, **A** indicates the class name, and **obj** indicates the object. This string indicates that class **A** in the **name** package is used to define an object **obj** in the program. + + Example: Create a test object of the Test class in the example package. + + ``` + example.Test test = new example.Test(); + ``` + +- Use **import** at the beginning of the file to import the classes in the package. + + The format of the **import** statement is import pkg1\[.pkg2\[.pkg3...\]\].\(classname | \*\). + + **pkg1\[.pkg2\[.pkg3...\]\]** indicates the package level, and **classname** indicates the class to be imported. If you want to import multiple classes from a package, you can use the wildcard \(\*\) instead. + + Example: Import the **Test** class in the **example** package. + + ``` + import example.Test; + ``` + + Example: Import the entire **example** package. + + ``` + import example.*; + ``` + + +## Examples + + + +### Compiling a Java Program Without a Package + +1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. The command is as follows: + + ``` + # cd /home/code + ``` + +2. Compile the Hello World program and save it as **HelloWorld.java**. The following uses the Hello World program as an example. The command is as follows: + + ``` + # vi HelloWorld.java + ``` + + Code example: + + ``` + public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello World"); + } + } + ``` + +3. Run the following command to compile the code in the code directory: + + ``` + # javac HelloWorld.java + ``` + + If no error is reported, the execution is successful. + +4. After the compilation is complete, the HelloWorld.class file is generated. You can run the **java** command to view the result. The following is an example: + + ``` + # java HelloWorld + Hello World + ``` + + +### Compiling a Java Program with a Package + +1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. Create the **/home/code/Test/my/example**, **/home/code/Hello/world/developers**, and **/home/code/Hi/openos/openeuler** subdirectories in the directory to store source files. + + ``` + cd /home/code + + mkdir -p Test/my/example + mkdir -p Hello/world/developers + mkdir -p Hi/openos/openeuler + ``` + +2. Run the **cd** command to go to the **/home/code/Test/my/example** directory and create **Test.java**. + + ``` + cd /home/code/Test/my/example + vi Test.java + ``` + + The following is an example of the Test.java code: + + ``` + package my.example; + import world.developers.Hello; + import openos.openeuler.Hi; + public class Test { + public static void main(String[] args) { + Hello me = new Hello(); + me.hello(); + Hi you = new Hi(); + you.hi(); + } + } + ``` + +3. Run the **cd** command to go to the **/home/code/Hello/world/developers** directory and create **Hello.java**. + + ``` + cd /home/code/Hello/world/developers + vi Hello.java + ``` + + The following is an example of the Hello.java code: + + ``` + package world.developers; + public class Hello { + public void hello(){ + System.out.println("Hello, openEuler."); + } + } + ``` + +4. Run the **cd** command to go to the **/home/code/Hi/openos/openeuler** directory and create **Hi.java**. + + ``` + cd /home/code/Hi/openos/openeuler + vi Hi.java + ``` + + The following is an example of the Hi.java code: + + ``` + package openos.openeuler; + public class Hi { + public void hi(){ + System.out.println("Hi, the global developers."); + } + } + ``` + +5. Run the **cd** command to go to the **/home/code** directory and use javac to compile the source file. + + ``` + cd /home/code + javac -classpath Hello:Hi Test/my/example/Test.java + ``` + + After the command is executed, the **Test.class**, **Hello.class**, and **Hi.class** files are generated in the **/home/code/Test/my/example**, **/home/code/Hello/world/developers**, and **/home/code/Hi/openos/openeuler** directories. + +6. Run the **cd** command to go to the **/home/code** directory and run the **Test** program using Java. + + ``` + cd /home/code + java -classpath Test:Hello:Hi my/example/Test + ``` + + The command output is as follows: + + ``` + Hello, openEuler. + Hi, the global developers. + ``` diff --git a/content/en/docs/ApplicationDev/using-make-for-compilation.md b/content/en/docs/ApplicationDev/using-make-for-compilation.md index 471a6de7fd78ac4be0127a736881cc78cd17624e..9c2f7dc16277f54b1cd7e0ec4507321f3eb91447 100644 --- a/content/en/docs/ApplicationDev/using-make-for-compilation.md +++ b/content/en/docs/ApplicationDev/using-make-for-compilation.md @@ -1,5 +1,375 @@ -# Using Make for Compilation +# Using Make for Compilation This chapter describes the basic knowledge of make compilation and provides examples for demonstration. For more information about Make, run the **man make** command. + +- [Using Make for Compilation](#using-make-for-compilation) + - [Overview](#overview) + - [Basics](#basics) + - [File Type](#file-type) + - [make Work Process](#make-work-process) + - [make Options](#make-options) + - [Makefiles](#makefiles) + - [Makefile Structure](#makefile-structure) + - [Makefile Contents](#makefile-contents) + - [Examples](#examples) + - [Example of Using Makefile to Implement Compilation](#example-of-using-makefile-to-implement-compilation) + + +## Overview + +The GNU make utility \(usually abbreviated as make\) is a tool for controlling the generation of executable files from source files. make automatically identifies which parts of the complex program have changed and need to be recompiled. Make uses a configuration file called makefiles to control how the program is built. + +## Basics + + +### File Type + +[Table 1](#table634145764320) describes the file types that may be used in the makefiles file. + +**Table 1** File types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Extension (Suffix)

+

Description

+

.c

+

C source code file.

+

.C, .cc, or .cxx

+

C++ source code file.

+

.m

+

Objective-C source code file.

+

.s

+

Assembly language source code file.

+

.i

+

Preprocessed C source code file.

+

.ii

+

Preprocessed C++ source code file.

+

.S

+

Pre-processed assembly language source code file.

+

.h

+

Header file contained in the program.

+

.o

+

Target file after compilation.

+

.so

+

Dynamic link library, which is a special target file.

+

.a

+

Static link library.

+

.out

+

Executable files, which do not have a fixed suffix. The system distinguishes executable files from unexecutable files based on file attributes. If the name of an executable file is not given, GCC generates a file named a.out.

+
+ +### make Work Process + +The process of deploying make to generate an executable file from the source code file is described as follows: + +1. The make command reads the Makefiles, including the files named GNUmakefile, makefile, and Makefile in the current directory, the included makefile, and the rule files specified by the **-f**, **\-\-file**, and **\-\-makefile** options. +2. Initialize variables. +3. Derive implicit rules, analyze dependencies, and create a dependency chain. +4. Determine which targets need to be regenerated based on the dependency chain. +5. Run a command to generate the final file. + +### make Options + +make command format: **make** \[_option_\]... \[_target_\]... + +In the preceding command: + +_option_ : parameter option. + +_target_ : target specified in Makefile. + +[Table 2](#table261872312343) describes the common make options. + +**Table 2** Common make options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

options Value

+

Description

+

-C dir, \-\-directory=dir

+

Specifies dir as the working directory after the make command starts to run.

+

When there are multiple -C options, the final working directory of make is the relative path of the first directory.

+

-d

+

Displays all debugging information during execution of the make command. You can use the -d option to display all the information during the construction of the dependency chain and the reconstruction of the target.

+

-e, \-\-environment-overrides

+

Overwrites the variable definition with the same name in Makefile with the environment variable definition.

+

-f file, \-\-file=file,

+

\-\-makefile=file

+

Specifies the file as the Makefile for the make command.

+

-p, \-\-help

+

Displays help information.

+

-i, \-\-ignore-errors

+

Ignores the errors occurred during the execution.

+

-k, \-\-keep-going

+

When an error occurs during command execution, the make command is not terminated. The make command executes all commands as many as possible until a known error occurs.

+

-n, \-\-just-print, \-\-dry-run

+

Simulates the execution of commands (including the commands starting with @) in the actual execution sequence. This command is used only to display the execution process and has no actual execution effect.

+

-o file, \-\-old-file=file, \-\-assume-old=file

+

The specified file does not need to be rebuilt even if its dependency has expired, and no target of this dependency file is rebuilt.

+

-p, \-\-print-date-base

+

Before the command is executed, all data of Makefile read by make and the version information of make are printed. If you only need to print the data, run the make -qp command to view the preset rules and variables before the make command is executed. You can run the make -p -f /dev/null command.

+

-r, \-\-no-builtin-rules

+

Ignores the use of embedded implicit rules and the implicit suffix list of all suffix rules.

+

-R, \-\-no-builtin-variabes

+

Ignores embedded hidden variables.

+

-s, \-\-silent, \-\-quiet

+

Cancels the printing during the command execution.

+

-S, \-\-no-keep-going, \-\-stop

+

Cancels the -k option. In the recursive make process, the sub-make inherits the upper-layer command line option through the MAKEFLAGS variable. You can use the -S option in the sub-make to cancel the -k option transferred by the upper-layer command, or cancel the -k option in the system environment variable MAKEFLAGS.

+

-t, \-\-touch

+

Updates the timestamp of all target files to the current system time. Prevents make from rebuilding all outdated target files.

+

-v, version

+

Displays the make version.

+
+ +## Makefiles + +Make is a tool that uses makefiles for compilation, linking, installation, and cleanup, so as to generate executable files and other related files from source code files. Therefore, makefiles describe the compilation and linking rules of the entire project, including which files need to be compiled, which files do not need to be compiled, which files need to be compiled first, which files need to be compiled later, and which files need to be rebuilt. The makefiles automate project compilation. You do not need to manually enter a large number of source files and parameters each time. + +This chapter describes the structure and main contents of makefiles. For more information about makefiles, run the **info make** command. + +### Makefile Structure + +The makefile file structure is as follows: + +_targets_:_prereguisites_ + +_command_ + +or + +_targets_:_prerequisites_;_command_ + +_command_ + +In the preceding information: + +- _targets_ : targets, which can be target files, executable files, or tags. +- _prerequisites_ : dependency files, which are the files or targets required for generating the _targets_. There can be multiple or none of them. +- _command_ : command \(any shell command\) to be executed by make. Multiple commands are allowed, and each command occupies a line. +- Use colons \(:\) to separate the target files from the dependency files. Press **Tab** at the beginning of each command line. + +The makefile file structure indicates the output target, the object on which the output target depends, and the command to be executed for generating the target. + +### Makefile Contents + +A makefile file consists of the following contents: + +- Explicit rule + + Specify the dependency, such as the file to be generated, dependency file, and generated command. + +- Implicit rule + + Specify the rule that is automatically derived by make. The make command supports the automatic derivation function. + +- Variable definition +- File indicator + + The file indicator consists of three parts: + + - Inclusion of other makefiles, for example, include xx.md + - Selective execution, for example, \#ifdef + - Definition of multiple command lines, for example, define...endef. \(define ... endef\) + +- Comment + + The comment starts with a number sign \(\#\). + + +## Examples + + + +### Example of Using Makefile to Implement Compilation + +1. Run the **cd** command to go to the code directory. The **/home/code** directory is used as an example. + + ``` + cd /home/code + ``` + +2. Create a header file **hello.h** and two functions **hello.c** and **main.c**. + + ``` + cd /home/code/ + ``` + + The following is an example of the **hello.h** code: + + ``` + #pragma once + #include + void hello(); + ``` + + The following is an example of the **hello.c** code: + + ``` + #include "hello.h" + void hello() + { + int i=1; + while(i<5) + { + printf("The %dth say hello.\n", i); + i++; + } + } + + ``` + + The following is an example of the **main.c** code: + + ``` + #include "hello.h" + #include + int main() + { + hello(); + return 0; + } + ``` + +3. Create the makefile. + + ``` + vi Makefile + ``` + + The following provides an example of the makefile content: + + ``` + main:main.o hello.o + gcc -o main main.o hello.o + main.o:main.c + gcc -c main.c + hello.o:hello.c + gcc -c hello.c + clean: + rm -f hello.o main.o main + ``` + +4. Run the **make** command. + + ``` + make + ``` + + After the command is executed, the commands executed in makefile are printed. If you do not need to print the information, add the **-s** option to the **make** command. + + gcc -c main.c + + gcc -c hello.c + + gcc -o main main.o hello.o + +5. Execute the ./main target. + + ``` + ./main + ``` + + After the command is executed, the following information is displayed: + + The 1th say hello. + + The 2th say hello. + + The 3th say hello. + + The 4th say hello. diff --git a/content/en/docs/ApplicationDev/using-the-ide-for-java-development.md b/content/en/docs/ApplicationDev/using-the-ide-for-java-development.md deleted file mode 100644 index 2a95e6aab8d881a8b18877b1ad9569cf8eb8ac53..0000000000000000000000000000000000000000 --- a/content/en/docs/ApplicationDev/using-the-ide-for-java-development.md +++ /dev/null @@ -1,6 +0,0 @@ -# Using the IDE for Java Development - -For small-sized Java applications, you can directly use JDK to compile them to run Java applications. However, for medium- and large-sized Java applications, this method cannot meet the development requirements. You can perform the following steps to install and use the IDE to facilitate Java development on the openEuler OS. - - - diff --git a/content/en/menu/index.md b/content/en/menu/index.md index e65139d6c5e8d027d37f83d59af26c7e38601edf..e5fa8da14016c701bf021077e8defe6447871869 100644 --- a/content/en/menu/index.md +++ b/content/en/menu/index.md @@ -562,69 +562,8 @@ headless: true - [Application Development Guide]({{< relref "./docs/ApplicationDev/application-development.md" >}}) - - [About This Document]({{< relref "./docs/ApplicationDev/about-this-document.md" >}}) - [Preparation]({{< relref "./docs/ApplicationDev/preparation.md" >}}) - - [Configuring the Development Environment]({{< relref "./docs/ApplicationDev/configuring-the-development-environment.md" >}}) - - [Configuring a Repo Source]({{< relref "./docs/ApplicationDev/configuring-a-repo-source.md" >}}) - - [Installing the Software Package]({{< relref "./docs/ApplicationDev/installing-the-software-package.md" >}}) - - [Installing the JDK Software Package]({{< relref "./docs/ApplicationDev/installing-the-jdk-software-package.md" >}}) - - [Installing the rpm-build Software Package]({{< relref "./docs/ApplicationDev/installing-the-rpm-build-software-package.md" >}}) - - [Using the IDE for Java Development]({{< relref "./docs/ApplicationDev/using-the-ide-for-java-development.md" >}}) - - [Overview]({{< relref "./docs/ApplicationDev/overview.md" >}}) - - [Logging In to the Server Using MobaXterm]({{< relref "./docs/ApplicationDev/logging-in-to-the-server-using-mobaxterm.md" >}}) - - [Setting the JDK Environment]({{< relref "./docs/ApplicationDev/setting-the-jdk-environment.md" >}}) - - [Downloading and Installing the GTK Library]({{< relref "./docs/ApplicationDev/downloading-and-installing-the-gtk-library.md" >}}) - - [Setting X11 Forwarding]({{< relref "./docs/ApplicationDev/setting-x11-forwarding.md" >}}) - - [Downloading and Running IntelliJ IDEA]({{< relref "./docs/ApplicationDev/downloading-and-running-intellij-idea.md" >}}) - [Using GCC for Compilation]({{< relref "./docs/ApplicationDev/using-gcc-for-compilation.md" >}}) - - [Overview]({{< relref "./docs/ApplicationDev/overview-0.md" >}}) - - [Basics]({{< relref "./docs/ApplicationDev/basics.md" >}}) - - [File Type]({{< relref "./docs/ApplicationDev/file-type.md" >}}) - - [Compilation Process]({{< relref "./docs/ApplicationDev/compilation-process.md" >}}) - - [Compilation Options]({{< relref "./docs/ApplicationDev/compilation-options.md" >}}) - - [Multi-file Compilation]({{< relref "./docs/ApplicationDev/multi-file-compilation.md" >}}) - - [Libraries]({{< relref "./docs/ApplicationDev/libraries.md" >}}) - - [Dynamic Link Library]({{< relref "./docs/ApplicationDev/dynamic-link-library.md" >}}) - - [Static Link Library]({{< relref "./docs/ApplicationDev/static-link-library.md" >}}) - - [Examples]({{< relref "./docs/ApplicationDev/examples.md" >}}) - - [Example for Using GCC to Compile C Programs]({{< relref "./docs/ApplicationDev/example-for-using-gcc-to-compile-c-programs.md" >}}) - - [Example for Creating and Using a DLL Using GCC]({{< relref "./docs/ApplicationDev/example-for-creating-and-using-a-dll-using-gcc.md" >}}) - - [Example for Creating and Using an SLL Using GCC]({{< relref "./docs/ApplicationDev/example-for-creating-and-using-an-sll-using-gcc.md" >}}) - [Using Make for Compilation]({{< relref "./docs/ApplicationDev/using-make-for-compilation.md" >}}) - - [Overview]({{< relref "./docs/ApplicationDev/overview-1.md" >}}) - - [Basics]({{< relref "./docs/ApplicationDev/basics-2.md" >}}) - - [File Type]({{< relref "./docs/ApplicationDev/file-type-3.md" >}}) - - [make Work Process]({{< relref "./docs/ApplicationDev/make-work-process.md" >}}) - - [make Options]({{< relref "./docs/ApplicationDev/make-options.md" >}}) - - [Makefiles]({{< relref "./docs/ApplicationDev/makefiles.md" >}}) - - [Examples]({{< relref "./docs/ApplicationDev/examples-4.md" >}}) - - [Example of Using Makefile to Implement Compilation]({{< relref "./docs/ApplicationDev/example-of-using-makefile-to-implement-compilation.md" >}}) - [Using JDK for Compilation]({{< relref "./docs/ApplicationDev/using-jdk-for-compilation.md" >}}) - - [Overview]({{< relref "./docs/ApplicationDev/overview-5.md" >}}) - - [Basics]({{< relref "./docs/ApplicationDev/basics-6.md" >}}) - - [File Type and Tool]({{< relref "./docs/ApplicationDev/file-type-and-tool.md" >}}) - - [Java Program Generation Process]({{< relref "./docs/ApplicationDev/java-program-generation-process.md" >}}) - - [Common JDK Options]({{< relref "./docs/ApplicationDev/common-jdk-options.md" >}}) - - [Class Library]({{< relref "./docs/ApplicationDev/class-library.md" >}}) - - [Examples]({{< relref "./docs/ApplicationDev/examples-7.md" >}}) - - [Compiling a Java Program Without a Package]({{< relref "./docs/ApplicationDev/compiling-a-java-program-without-a-package.md" >}}) - - [Compiling a Java Program with a Package]({{< relref "./docs/ApplicationDev/compiling-a-java-program-with-a-package.md" >}}) - - [Building an RPM Package]({{< relref "./docs/ApplicationDev/building-an-rpm-package.md" >}}) - - [Packaging Description]({{< relref "./docs/ApplicationDev/packaging-description.md" >}}) - - [Building an RPM Package Locally]({{< relref "./docs/ApplicationDev/building-an-rpm-package-locally.md" >}}) - - [Setting Up the Development Environment]({{< relref "./docs/ApplicationDev/setting-up-the-development-environment.md" >}}) - - [Creating a Hello World RPM Package]({{< relref "./docs/ApplicationDev/creating-a-hello-world-rpm-package.md" >}}) - - [Obtaining the Source Code]({{< relref "./docs/ApplicationDev/obtaining-the-source-code.md" >}}) - - [Editing the SPEC File]({{< relref "./docs/ApplicationDev/editing-the-spec-file.md" >}}) - - [Building an RPM Package]({{< relref "./docs/ApplicationDev/building-an-rpm-package-8.md" >}}) - - [Building an RPM Package Using the OBS]({{< relref "./docs/ApplicationDev/building-an-rpm-package-using-the-obs.md" >}}) - - [OBS Overview]({{< relref "./docs/ApplicationDev/obs-overview.md" >}}) - - [Building an RPM Software Package Online]({{< relref "./docs/ApplicationDev/building-an-rpm-software-package-online.md" >}}) - - [Building an Existing Software Package]({{< relref "./docs/ApplicationDev/building-an-existing-software-package.md" >}}) - - [Adding a Software Package]({{< relref "./docs/ApplicationDev/adding-a-software-package.md" >}}) - - [Obtaining the Software Package]({{< relref "./docs/ApplicationDev/obtaining-the-software-package.md" >}}) - - [Building a Software Package Using OSC]({{< relref "./docs/ApplicationDev/building-a-software-package-using-osc.md" >}}) - - [Installing and Configuring the OSC]({{< relref "./docs/ApplicationDev/installing-and-configuring-the-osc.md" >}}) - - [Building an Existing Software Package]({{< relref "./docs/ApplicationDev/building-an-existing-software-package-9.md" >}}) - - [Adding a Software Package]({{< relref "./docs/ApplicationDev/adding-a-software-package-10.md" >}}) - - [Obtaining the Software Package]({{< relref "./docs/ApplicationDev/obtaining-the-software-package-11.md" >}}) + - [Building an RPM Package]({{< relref "./docs/ApplicationDev/building-an-rpm-package.md" >}}) \ No newline at end of file diff --git "a/content/zh/docs/Administration/\344\275\277\347\224\250DNF\347\256\241\347\220\206\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/Administration/\344\275\277\347\224\250DNF\347\256\241\347\220\206\350\275\257\344\273\266\345\214\205.md" index 9d5737974b215e18f871cdd4c27f594532d16998..276fa75b261de5e2dd40c550dc42364792bbce0f 100644 --- "a/content/zh/docs/Administration/\344\275\277\347\224\250DNF\347\256\241\347\220\206\350\275\257\344\273\266\345\214\205.md" +++ "b/content/zh/docs/Administration/\344\275\277\347\224\250DNF\347\256\241\347\220\206\350\275\257\344\273\266\345\214\205.md" @@ -275,7 +275,7 @@ dnf list all 要列出系统中特定的RPM包信息,使用命令如下: ``` -dnf list glob_expression… +dnf list glob_expression... ``` 示例如下: @@ -291,7 +291,7 @@ httpd.aarch64 2.4.34-8.h5.oe1 Local 要显示一个或者多个RPM包信息,使用命令如下: ``` -dnf info package_name… +dnf info package_name... ``` 例如搜索,命令如下: @@ -323,7 +323,7 @@ dnf install package_name 您也可以通过添加软件包名字同时安装多个软件包。配置文件/etc/dnf/dnf.conf添加参数strict=False,运行dnf命令参数添加\-\-setopt=strict=0。请在root权限下执行如下命令: ``` -dnf install package_name package_name… --setopt=strict=0 +dnf install package_name package_name... --setopt=strict=0 ``` 示例如下: @@ -360,7 +360,7 @@ dnf download --resolve package_name 要卸载软件包以及相关的依赖软件包,请在root权限下执行如下命令: ``` -dnf remove package_name… +dnf remove package_name... ``` 示例如下: @@ -421,7 +421,7 @@ Available Groups: 要列出包含在一个软件包组中必须安装的包和可选包,使用命令如下: ``` -dnf group info glob_expression… +dnf group info glob_expression... ``` 例如显示Development Tools信息,示例如下: diff --git "a/content/zh/docs/Administration/\344\275\277\347\224\250KAE\345\212\240\351\200\237\345\274\225\346\223\216.md" "b/content/zh/docs/Administration/\344\275\277\347\224\250KAE\345\212\240\351\200\237\345\274\225\346\223\216.md" index 4a445e64800ae0e3f2e544bb79926b119ba4ea69..da7e0e65396e5d3b6ec0186f2d591df1fd2e27ff 100644 --- "a/content/zh/docs/Administration/\344\275\277\347\224\250KAE\345\212\240\351\200\237\345\274\225\346\223\216.md" +++ "b/content/zh/docs/Administration/\344\275\277\347\224\250KAE\345\212\240\351\200\237\345\274\225\346\223\216.md" @@ -246,7 +246,7 @@ export OPENSSL_ENGINES=/usr/local/lib/engines-1.1 执行**rpm -qa**命令查看加速器引擎软件包是否安装成功。 -打印信息中包含“_软件包名_-_版本号-_”表示该软件包安装成功。示例如下。 +打印信息中包含“ _软件包名-版本号-_ ”表示该软件包安装成功。示例如下。 ``` rpm -qa|grep -E "hisi|uacce|libwd|libkae" diff --git "a/content/zh/docs/Administration/\345\237\272\347\241\200\351\205\215\347\275\256.md" "b/content/zh/docs/Administration/\345\237\272\347\241\200\351\205\215\347\275\256.md" index 78771c36b3a69cf334a096094484c34635f8a32d..e453d4f45e6bcaa1bce0bbd45c7301263dc3668e 100644 --- "a/content/zh/docs/Administration/\345\237\272\347\241\200\351\205\215\347\275\256.md" +++ "b/content/zh/docs/Administration/\345\237\272\347\241\200\351\205\215\347\275\256.md" @@ -70,9 +70,10 @@ localectl set-locale LANG=locale >![](public_sys-resources/icon-note.gif) **说明:** >修改后需要重新登录或者执行如下命令刷新配置文件,使修改生效。 ->``` ->source /etc/locale.conf ->``` +``` +source /etc/locale.conf +``` + ## 设置键盘 diff --git "a/content/zh/docs/Administration/\346\220\255\345\273\272\346\225\260\346\215\256\345\272\223\346\234\215\345\212\241\345\231\250.md" "b/content/zh/docs/Administration/\346\220\255\345\273\272\346\225\260\346\215\256\345\272\223\346\234\215\345\212\241\345\231\250.md" index 5cafb62665914ad29cf3cdfc8d87eaa964ee8ecb..fb17745d75c91fd913e0cac89fd0bc3f6eef062f 100644 --- "a/content/zh/docs/Administration/\346\220\255\345\273\272\346\225\260\346\215\256\345\272\223\346\234\215\345\212\241\345\231\250.md" +++ "b/content/zh/docs/Administration/\346\220\255\345\273\272\346\225\260\346\215\256\345\272\223\346\234\215\345\212\241\345\231\250.md" @@ -740,7 +740,7 @@ pg_dump [option]... [databasename] > outfile - databasename:数据库名称。如果没有声明这个参数,那么使用环境变量 PGDATABASE 。如果那个环境变量也没声明,那么使用发起连接的用户名。 - outfile:数据库备份的文件。 - option:pg\_dump命令参数选项,多个参数之间可以使用空格分隔。常用的pg\_dump命令参数选项如下: - - -f filename,\-\-file= _filename_ :指输出到指定的文件。如果忽略,则使用标准输出。 + - -f,\-\-file= _filename_ :指输出到指定的文件。如果忽略,则使用标准输出。 - -d,\-\-dbname= _databasename_ :指定转储的数据库。 - -h,\-\-host= _hostname_ :指定主机名。 - -p,\-\-port= _portnumber_ :指定端口。 @@ -770,7 +770,7 @@ psql [option]... [databasename [username]] < infile - username:用户名。 - infile:pg\_dump命令中的outfile参数。 - option:psql命令参数选项,多个参数之间可以使用空格分隔。常用的psql命令参数选项如下: - - -f filename,\-\-file=filename:指输出到指定的文件。如果忽略,则使用标准输出。 + - -f,\-\-file=filename:指输出到指定的文件。如果忽略,则使用标准输出。 - -d,\-\-dbname=databasename:指定转储的数据库。 - -h,\-\-host=hostname:指定主机名。 - -p,\-\-port=portnumber:指定端口。 diff --git "a/content/zh/docs/Administration/\347\256\241\347\220\206\346\234\215\345\212\241.md" "b/content/zh/docs/Administration/\347\256\241\347\220\206\346\234\215\345\212\241.md" index ea80aed04db02c6139faedbc7b5945596debd0e0..4ad3fba84371272ea948a9ef2a52d4af97faf311 100644 --- "a/content/zh/docs/Administration/\347\256\241\347\220\206\346\234\215\345\212\241.md" +++ "b/content/zh/docs/Administration/\347\256\241\347\220\206\346\234\215\345\212\241.md" @@ -372,21 +372,21 @@ systemd提供systemctl命令与sysvinit命令的功能类似。当前版本中

用来检查一个服务在当前环境下被配置为启用还是禁用。

-

chkconfig --list

+

chkconfig \-\-list

-

systemctl list-unit-files --type=service

+

systemctl list-unit-files \-\-type=service

输出在各个运行级别下服务的启用和禁用情况。

-

chkconfig network --list

+

chkconfig network \-\-list

ls /etc/systemd/system/*.wants/network.service

用来列出该服务在哪些运行级别下启用和禁用。

-

chkconfig network --add

+

chkconfig network \-\-add

systemctl daemon-reload

diff --git "a/content/zh/docs/Administration/\351\205\215\347\275\256\347\275\221\347\273\234.md" "b/content/zh/docs/Administration/\351\205\215\347\275\256\347\275\221\347\273\234.md" index 646f21dd7dd38c6dfd59a54f83447865ff318ef7..e8a94dc8d346d2d52a29025852fea74fa1bf4efb 100644 --- "a/content/zh/docs/Administration/\351\205\215\347\275\256\347\275\221\347\273\234.md" +++ "b/content/zh/docs/Administration/\351\205\215\347\275\256\347\275\221\347\273\234.md" @@ -1275,7 +1275,7 @@ NetworkManager服务使用ifup/ifdown的逻辑接口定义进行高级网络设 如果使用格式如“iscsiadm -m node -p fe80::xxxx%enp3s0 -l”登录时,iscsi\_addr\_match函数会将地址“fe80::xxxx%enp3s0”与服务端返回的node信息中的地址“fe80::xxxx”对比,对比结果不匹配,导致登录失败。 -因此,**iscsi-initiator-utils目前机制还不支持用链路本地地址(link-local address)地址登录iscsi服务端**。 +因此,**iscsi-initiator-utils目前机制还不支持用链路本地地址(link-local address)登录iscsi服务端**。 #### 网卡down掉之后,IPv6地址丢失 diff --git "a/content/zh/docs/ApplicationDev/JDK\345\270\270\347\224\250\345\267\245\345\205\267\351\200\211\351\241\271.md" "b/content/zh/docs/ApplicationDev/JDK\345\270\270\347\224\250\345\267\245\345\205\267\351\200\211\351\241\271.md" deleted file mode 100644 index 1007bfd1cfcec4bf48e8db2d556962fca5b259d8..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/JDK\345\270\270\347\224\250\345\267\245\345\205\267\351\200\211\351\241\271.md" +++ /dev/null @@ -1,253 +0,0 @@ -# JDK常用工具选项 - -## javac编译选项 - -javac编译的命令格式为:**javac** \[_options_\] \[_sourcefiles_\] \[_classes_\] \[@_argfiles_\] - -其中: - -_options_:命令选项。 - -_sourcefiles_:一个或多个需要编译的源文件。 - -_classes_:一个或多个要为注释处理的类。 - -@_argfiles_:一个或多个列出选项和源文件的文件。这些文件中不允许有-J选项。 - -javac是java编译器,其_options_参数取值很多,但有些大部分并不常用,常用的_options_取值如[表1](#table1342946175212)所示。 - -**表 1** javac常用的编译选项 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

options取值

-

说明

-

示例

-

-d path

-

指定存放生成的类文件的路径

-

默认情况下,编译生成的类文件与源文件在同一路径下。使用-d选项可以将类文件输出到指定路径。

-

#使用-d选项将所有类文件输出到bin路径下

-

javac /src/*.java -d /bin

-

-s path

-

指定存放生成的源文件的路径

-

-

-

-cp path或-classpath path

-

搜索编译所需的class文件,指出编译所用到的class文件的位置。

-

#在Demo中要调用GetStringDemo类中的getLine()方法,而GetStringDemo类编译后的文件,即.class文件在bin目录下。

-

javac -cp bin Demo.java -d bin

-

-verbose

-

输出关于编译器正在执行的操作的消息,如加载的类信息和编译的源文件信息。

-

#输出关于编译器正在执行的操作的消息。

-

javac -verbose -cp bin Demo.java

-

-source sourceversion

-

指定查找输入源文件的位置。

-

-

-

-sourcepath path

-

用于搜索编译所需的源文件(即java文件),指定要搜索的源文件的位置,如jar、zip或其他包含java文件的目录。

-

-

-

-target targetversion

-

生成特定JVM版本的类文件。取值为1.1,1.2,1.3,1.4,1.5(或5),1.6(或6),1.7(或7),1.8(或8)。targetversion的默认取值与-source选项的sourceversion有关。sourceversion取值:

-
  • 1.2,targetversion为1.4;
  • 1.3,targetversion为1.4;
  • 1.5、1.6、1.7、未指定,targetversion为1.8。
  • 其他值,targetversionsourceversion取值相同。
-

-

-
- -## java运行选项 - -java运行的格式为: - -运行类文件:**java** \[_options_\] _classesname_ \[args\] - -运行jar文件:**java** \[_options_\] -jar _filename_ \[args\] - -其中: - -_options_:命令选项,选项之间用空格分隔。 - -_classname_:运行的.class文件名。 - -_filename_:运行的.jar文件名。 - -args:传递给main\(\)函数的参数,参数之间用空格分隔。 - -java是运行java应用程序的工具,其_options_参数取值很多,但有些大部分并不常用,常用的_options_取值如[表2](#table371918587238)所示。 - -**表 2** java常用的运行选项 - - - - - - - - - - - - - - - - -

options取值

-

说明

-

示例

-

-cp path或-classpath path

-

指定要运行的文件所在的位置以及需要用到的类路径,包括jar、zip和class文件目录。

-

当路径有多个是,使用“:”分隔。

-

-

-

-verbose

-

输出关于编译器正在执行的操作的消息,如加载的类信息和编译的源文件信息。

-

#输出关于编译器正在执行的操作的消息。

-

java -verbose -cp bin Demo.java

-
- -## jar打包选项 - -jar的命令格式为:**jar** \{c | t | x | u\}\[vfm0M\] \[_jarfile_\] \[_manifest_\] \[-C _dir_\] _file_... - -jar命令参数说明如[表3](#table3691718114817)所示。 - -**表 3** jar命令参数说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

参数

-

说明

-

示例

-

c

-

创建jar文件包。

-

#把当前目录的hello.class文件打包到Hello.jar,且不显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。

-

jar cf Hello.jar hello.class

-

t

-

列出jar文件包的内容列表。

-

#列出Hello.jar包含的文件清单。

-

jar tf Hello.jar

-

x

-

展开jar文件包的指定文件或者所有文件。

-

#解压Hello.jar 到当前目录,不显示任何信息。

-

jar xf Hello.jar

-

u

-

更新已存在的jar文件包,如添加文件到jar文件包中。

-

-

-

v

-

生成详细报告并打印到标准输出。

-

#把当前目录的hello.class文件打包到Hello.jar,并显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。

-

jar cvf Hello.jar hello.class

-

f

-

指定jar文件名,通常这个参数是必须的。

-

-

-

m

-

指定需要包含的manifest清单文件。

-

-

-

0

-

只存储,不压缩,这样产生的jar文件包会比不用该参数产生的体积大,但速度更快。

-

-

-

M

-

不产生所有项的manifest清单文件,此参数会忽略m参数

-

#把当前目录的hello.class文件打包到Hello.jar,并显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。但在创建Hello.jar时不产生manifest 文件。

-

jar cvfM Hello.jar hello.class

-

jarfile

-

.jar文件包,它是f参数的附属参数。

-

-

-

manifest

-

.mf的manifest清单文件,它是m参数的附属参数

-

-

-

-C dir

-

转到指定dir下执行jar命令,只能配合参数c、t使用。

-

-

-

file

-

指定文件/路径列表,文件或路径下的所有文件(包括递归路径下的)都会被打入jar文件包中,或解压jar文件到路径下。

-

#把当前目录的所有class文件打包到Hello.jar,并显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。

-

jar cvf Hello.jar *.class

-
- diff --git a/content/zh/docs/ApplicationDev/Makefile.md b/content/zh/docs/ApplicationDev/Makefile.md deleted file mode 100644 index 0c25b5ea7125411a00980214ecd6de6780cadd8b..0000000000000000000000000000000000000000 --- a/content/zh/docs/ApplicationDev/Makefile.md +++ /dev/null @@ -1,55 +0,0 @@ -# Makefile - -make是通过Makefile文件获取如何编译、链接和安装、清理的方法,从而实现将源代码文件生成可执行文件和其他相关文件的工具。因此,Makefile中描述了整个工程的编译和链接等规则,其中包含了哪些文件需要编译,哪些文件不需要编译,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重建等等。Makefile文件让工程编译实现了自动化,不需要每次都手动输入一堆源文件和参数。 - -本章简单介绍Makefile文件的结构和主要内容,更多Makefile的内容请通过**info make**命令查询 - -## Makefile结构 - -Makefile文件结构如下所示: - -_targets_:_prereguisites_ - -_command_ - -或者是: - -_targets_:_prerequisites_;_command_ - -_command_ - -其中: - -- _targets_:目标,可以是目标文件、可执行文件或标签。 -- _prerequisites_:依赖文件,生成targets需要的文件或者是目标。可以是多个,也可以是没有。 -- _command_:make需要执行的命令(任意的 shell 命令)。可以有多条命令,每一条命令占一行。 -- 目标和依赖文件之间要使用“:”分隔,命令的开始一定要按“Tab”。 - -Makefile文件结构表明了输出的目标,输出目标的依赖对象和生成目标需要执行的命令。 - -## Makefile主要内容 - -一个Makefile文件主要由以下内容组成。 - -- 显式规则 - - 明确写出来的依赖关系,如要生成的文件,文件的依赖文件,生成的命令。 - -- 隐含规则 - - 由make自动推导的规则,make命令支持自动推导功能。 - -- 变量的定义 -- 文件指示 - - 文件指示包括三部分: - - - include 其他 Makefile,如include xx.md。 - - 选择执行,如\#ifdef。 - - 定义多行命令,如define...endef。\(define ... endef\) - -- 注释 - - 以 “\#” 开头。 - - diff --git "a/content/zh/docs/ApplicationDev/OBS\347\256\200\344\273\213.md" "b/content/zh/docs/ApplicationDev/OBS\347\256\200\344\273\213.md" deleted file mode 100644 index d65bcf7435a8e5301f0be91e8c3a96dac10679d4..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/OBS\347\256\200\344\273\213.md" +++ /dev/null @@ -1,8 +0,0 @@ -# OBS简介 - -OBS是基于openSUSE发行版的通用编译框架,用于将源码包构建为RPM软件包或Linux镜像。OBS采用自动化的分布式编译方式,支持多种Linux操作系统发行版(openEuler、SUSE、Debian等)镜像和安装包的编译,且支持在多种架构平台(x86、ARM64等)上编译。 - -OBS由后端和前端组成,后端实现所有核心功能,前端提供了网页应用和API,用于与后端进行交互。此外,OBS还有一个API命令行客户端osc,osc是在一个单独的存储库中开发的。 - -OBS使用工程组织软件包。基础的权限控制、相关的存仓库和构建目标(操作系统和架构)都可以在工程中定义。一个工程可以包含多个子工程,各个子工程可以独立配置,共同完成任务。 - diff --git a/content/zh/docs/ApplicationDev/application-development.md b/content/zh/docs/ApplicationDev/application-development.md index e78ebd9ca5de174c59a93c932a6d217d3d434a91..21d1513b77eeacb2a4fe6da5049bb2796fe4fb2c 100644 --- a/content/zh/docs/ApplicationDev/application-development.md +++ b/content/zh/docs/ApplicationDev/application-development.md @@ -1 +1,94 @@ -本文档简要介绍应用程序开发需要的常用工具,以指导用户使用openEuler并基于openEuler进行应用程序开发。 \ No newline at end of file +# 应用开发指南 + +本文档简要介绍应用程序开发需要的常用工具,以指导用户使用openEuler并基于openEuler进行应用程序开发。 + +## 概述 + +本文档主要介绍如下四部分内容,以指导用户使用openEuler并基于openEuler进行代码开发。 + +- 在openEuler系统中安装和使用GCC编译器,并完成一个简单代码的开发、编译和执行。 +- 在openEuler系统中使用JDK自带工具完成代码的编译和执行。 +- 在openEuler系统中安装IntelliJ IDEA进行Java开发。 +- 在本地或使用OBS(Open Build Service)创建RPM(The RPM Package Manager)软件包的方法。 + +## 读者对象 + +本文档适用于所有使用openEuler操作系统进行代码开发的用户。用户需要具备如下经验或能力: + +- 具备Linux操作系统基础知识 +- 了解Linux命令行的基本使用方法 + +## 符号约定 + +在本文中可能出现下列标志,它们所代表的含义如下。 + + + + + + + + + + + + + +

符号

+

说明

+

+

用于传递设备或环境安全警示信息,若不避免,可能会导致设备损坏、数据丢失、设备性能降低或其它不可预知的结果。

+

“注意”不涉及人身伤害。

+

+

用于突出重要/关键信息、最佳实践和小窍门等。

+

“说明”不是安全警示信息,不涉及人身、设备及环境伤害。

+
+ +## 命令行格式约定 + +**表 1** 命令行格式的约定 + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

格式

+

含义

+

粗体

+

命令行关键字,即命令中保持不变、必须照输的部分,采用加粗字体表示。

+

斜体

+

命令行参数,即命令中必须由实际值进行替代的部分,采用斜体表示。

+

[ ]

+

用“[ ]”括起来的部分表示在命令配置时是可选的。

+

{ x | y | ... }

+

表示从两个或多个选项中选取一个。

+

[ x | y | ... ]

+

表示从两个或多个选项中选取一个或者不选。

+

{ x | y | ... }*

+

表示从两个或多个选项中选取多个,最少选取一个,最多选取所有选项。

+

[ x | y | ... ]*

+

表示从两个或多个选项中选取一个、多个或者不选。

+
diff --git "a/content/zh/docs/ApplicationDev/figures/RPM\350\275\257\344\273\266\345\214\205\344\270\213\350\275\275\351\241\265\351\235\242.png" "b/content/zh/docs/ApplicationDev/figures/RPM\350\275\257\344\273\266\345\214\205\344\270\213\350\275\275\351\241\265\351\235\242.png" index e5663b6259982541ae9350701326665f3dee43f6..9f32d6c16d344df6951fc4e6aa027d02dfb9ccb5 100644 Binary files "a/content/zh/docs/ApplicationDev/figures/RPM\350\275\257\344\273\266\345\214\205\344\270\213\350\275\275\351\241\265\351\235\242.png" and "b/content/zh/docs/ApplicationDev/figures/RPM\350\275\257\344\273\266\345\214\205\344\270\213\350\275\275\351\241\265\351\235\242.png" differ diff --git "a/content/zh/docs/ApplicationDev/figures/Repositories\351\241\265\351\235\242.png" "b/content/zh/docs/ApplicationDev/figures/Repositories\351\241\265\351\235\242.png" index c64bfdd1bca838c5b72fa7bb7d73b525e8be79f6..b7c04eedf9dd32cf4a9d024a05f5c8b294c76934 100644 Binary files "a/content/zh/docs/ApplicationDev/figures/Repositories\351\241\265\351\235\242.png" and "b/content/zh/docs/ApplicationDev/figures/Repositories\351\241\265\351\235\242.png" differ diff --git "a/content/zh/docs/ApplicationDev/java\347\250\213\345\272\217\347\224\237\346\210\220\346\265\201\347\250\213.md" "b/content/zh/docs/ApplicationDev/java\347\250\213\345\272\217\347\224\237\346\210\220\346\265\201\347\250\213.md" deleted file mode 100644 index c45e06f4f3e0f2c3a6a1ecf97221cdf5b01c39c2..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/java\347\250\213\345\272\217\347\224\237\346\210\220\346\265\201\347\250\213.md" +++ /dev/null @@ -1,7 +0,0 @@ -# java程序生成流程 - -通过JDK将java源代码文件生成并运行Java程序,需要经过编译和运行。 - -1. 编译:是指使用Java编译器(javac)将java源代码文件(.java文件)编译为.class的字节码文件。 -2. 运行:是指在Java虚拟机上执行字节码文件。 - diff --git "a/content/zh/docs/ApplicationDev/make\345\267\245\344\275\234\346\265\201\347\250\213.md" "b/content/zh/docs/ApplicationDev/make\345\267\245\344\275\234\346\265\201\347\250\213.md" deleted file mode 100644 index 82ea835a8054b142ac536367c50477462bc89746..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/make\345\267\245\344\275\234\346\265\201\347\250\213.md" +++ /dev/null @@ -1,10 +0,0 @@ -# make工作流程 - -使用make由源代码文件生成可执行文件,需要经过如下步骤。 - -1. make命令会读入Makefile文件,包括当前目录下命名为"GNUmakefile" 、"makefile" 、"Makefile"的文件、被include的makefile文件、参数-f、--file、--makefile指定的规则文件。 -2. 初始化变量。 -3. 推导隐含规则,分析依赖关系,并创建依赖关系链。 -4. 根据依赖关系链,决定哪些目标需要重新生成。 -5. 执行生成命令,最终输出终极文件。 - diff --git "a/content/zh/docs/ApplicationDev/make\351\200\211\351\241\271.md" "b/content/zh/docs/ApplicationDev/make\351\200\211\351\241\271.md" deleted file mode 100644 index eab22da4710593b8ce2f7440098eacb471b74bad..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/make\351\200\211\351\241\271.md" +++ /dev/null @@ -1,106 +0,0 @@ -# make选项 - -make命令格式为:**make** \[_option_\]... \[_targe_t\]... - -其中: - -_option_:参数选项。 - -_target_:Makefile中指定的目标。 - -常用make的_option_取值如[表1](#table261872312343)所示。 - -**表 1** 常用的make选项 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

options取值

-

说明

-

-C dir,--directory=dir

-

指定make在开始运行后的工作目录为dir

-

当存在多个 -C 选项的时候,make 的最终工作目录是第一个目录的相对路径。

-

-d

-

make在执行的过程中打印出所有的调试信息。使用-d选项可以显示make构造依赖关系链、重建目标过程中的所有信息。

-

-e,--enveronment-overrides

-

使用环境变量定义覆盖Makefile中的同名变量定义。

-

-f file,--file=file

-

--makefile=file

-

指定file文件为make 执行的Makefile文件。

-

-p,--help

-

打印帮助信息。

-

-i,--ignore-errors

-

执行过程中忽略规则命令执行的错误。

-

-k,--keep-going

-

执行命令错误时不终止make的执行,make 尽最大可能执行所有的命令,直至出现知名的错误才终止。

-

-n,--just-print,--dry-run

-

按实际运行时的执行顺序模拟执行命令(包括用@开头的命令),没有实际执行效果,仅仅用于显示执行过程。

-

-o file,--old-file=file,--assume-old=file

-

指定file文件不需要重建,即使它的依赖已经过期,同时不重建此依赖文件的任何目标。

-

-p,--print-date-base

-

命令执行之前,打印出make读取的Makefile的所有数据,同时打印出 make的版本信息。如果只需要打印这些数据信息,可以使用 “make -qp”命令,查看 make 执行之前预设的规则和变量,可使用命令“make -p -f /dev/null”。

-

-r,--no-builtin-rules

-

忽略内嵌的隐含规则的使用,同时忽略所有后缀规则的隐含后缀列表。

-

-R,--no-builtin-variabes

-

忽略内嵌的隐含变量。

-

-s,--silent,--quiet

-

取消命令执行过程中的打印。

-

-S,--no-keep-going,--stop

-

取消 "-k" 的选项在递归的 make 过程中子 make 通过 "MAKEFLAGS" 变量继承了上层的命令行选项那个。我们可以在子 make 中使用“-S”选项取消上层传递的 "-k" 选项,或者取消系统环境变量 "MAKEFLAGS" 中 "-k"选项。

-

-t,--touch

-

更新所有的目标文件的时间戳到当前系统时间。防止 make 对所有过时目标文件的重建。

-

-v,version

-

查看make的版本信息。

-
- diff --git a/content/zh/docs/ApplicationDev/zh-cn_bookmap_0229243731.md b/content/zh/docs/ApplicationDev/zh-cn_bookmap_0229243731.md deleted file mode 100644 index c67d8a69ff4efa30b1daef6af6e2dd692e7a672c..0000000000000000000000000000000000000000 --- a/content/zh/docs/ApplicationDev/zh-cn_bookmap_0229243731.md +++ /dev/null @@ -1,89 +0,0 @@ -# 应用开发指南 - -- [法律声明](法律声明.md) -- [前言](前言.md) -- [开发环境准备](开发环境准备.md) - - [环境要求](环境要求.md) - - [配置repo源](配置repo源.md) - - [安装软件包](安装软件包.md) - - [安装JDK软件包](安装JDK软件包.md) - - [安装rpm-build软件包](安装rpm-build软件包.md) - - - [使用IDE进行Java开发](使用IDE进行Java开发.md) - - [简介](简介.md) - - [使用MobaXterm登录服务器](使用MobaXterm登录服务器.md) - - [设置JDK环境](设置JDK环境.md) - - [下载安装GTK库](下载安装GTK库.md) - - [设置X11 Forwarding](设置X11-Forwarding.md) - - [下载并运行IntelliJ IDEA](下载并运行IntelliJ-IDEA.md) - - -- [使用GCC编译](使用GCC编译.md) - - [简介](简介-0.md) - - [基本规则](基本规则.md) - - [文件类型](文件类型.md) - - [编译流程](编译流程.md) - - [编译选项](编译选项.md) - - [多源文件编译](多源文件编译.md) - - - [库](库.md) - - [动态链接库](动态链接库.md) - - [静态链接库](静态链接库.md) - - - [示例](示例.md) - - [使用GCC编译C程序示例](使用GCC编译C程序示例.md) - - [使用GCC创建和使用动态链接库示例](使用GCC创建和使用动态链接库示例.md) - - [使用GCC创建和使用静态链接库示例](使用GCC创建和使用静态链接库示例.md) - - -- [使用make编译](使用make编译.md) - - [简介](简介-1.md) - - [基本规则](基本规则-2.md) - - [文件类型](文件类型-3.md) - - [make工作流程](make工作流程.md) - - [make选项](make选项.md) - - - [Makefile](Makefile.md) - - [示例](示例-4.md) - - [使用Makefile实现编译的示例](使用Makefile实现编译的示例.md) - - -- [使用JDK编译](使用JDK编译.md) - - [简介](简介-5.md) - - [基本规则](基本规则-6.md) - - [文件类型及工具](文件类型及工具.md) - - [java程序生成流程](java程序生成流程.md) - - [JDK常用工具选项](JDK常用工具选项.md) - - - [类库](类库.md) - - [示例](示例-7.md) - - [编译不带包的java程序示例](编译不带包的java程序示例.md) - - [编译带包的java程序示例](编译带包的java程序示例.md) - - -- [构建RPM包](构建RPM包.md) - - [打包说明](打包说明.md) - - [本地构建](本地构建.md) - - [搭建开发环境](搭建开发环境.md) - - [创建Hello World RPM包](创建Hello-World-RPM包.md) - - [下载源码](下载源码.md) - - [编辑SPEC文件](编辑SPEC文件.md) - - [构建RPM包](构建RPM包-8.md) - - - - [使用OBS构建](使用OBS构建.md) - - [OBS简介](OBS简介.md) - - [在线构建软件包](在线构建软件包.md) - - [构建已有软件包](构建已有软件包.md) - - [新增软件包](新增软件包.md) - - [获取软件包](获取软件包.md) - - - [使用osc构建软件包](使用osc构建软件包.md) - - [安装并配置osc](安装并配置osc.md) - - [构建已有软件包](构建已有软件包-9.md) - - [新增软件包](新增软件包-10.md) - - [获取软件包](获取软件包-11.md) - - - - diff --git "a/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\345\256\211\350\243\205GTK\345\272\223.md" "b/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\345\256\211\350\243\205GTK\345\272\223.md" deleted file mode 100644 index 001126943ef990ce1a9c291ec7d3f4b2019d6bc2..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\345\256\211\350\243\205GTK\345\272\223.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 下载安装GTK库 - -请确认您具有root权限后,运行如下命令: - -``` -# dnf list installed | grep gtk -``` - -如果显示gtk2或者gtk3,则表示您已安装该库,可以直接跳过进入下一步,否则运行如下命令自动下载安装gtk库。 - -``` -# dnf -y install gtk2 libXtst libXrender xauth -``` - diff --git "a/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\345\271\266\350\277\220\350\241\214IntelliJ-IDEA.md" "b/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\345\271\266\350\277\220\350\241\214IntelliJ-IDEA.md" deleted file mode 100644 index b12a9dda7f91cd1605254bbe37685ce4263cc907..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\345\271\266\350\277\220\350\241\214IntelliJ-IDEA.md" +++ /dev/null @@ -1,15 +0,0 @@ -# 下载并运行IntelliJ IDEA - -在执行如上环境配置后,您就可以下载使用IntelliJ IDEA了。鉴于最新版的IntelliJ IDEA和openEuler系统在部分功能上有兼容性问题,建议您从此[链接](https://www.jetbrains.com/idea/download/other.html)下载2018版本linux压缩包。下载好后把压缩包移到您想要安装该软件的目录,对压缩包进行解压: - -``` -# tar xf ideaIC-2018.3.tar.gz -``` - -解压后切换到IntelliJ IDEA的目录下并运行。 - -``` -# cd ./idea-IC-183.4284.148 -# bin/idea.sh & -``` - diff --git "a/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\346\272\220\347\240\201.md" "b/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\346\272\220\347\240\201.md" deleted file mode 100644 index 796df60dceb38fa5ef026283beb685c664957eec..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\270\213\350\275\275\346\272\220\347\240\201.md" +++ /dev/null @@ -1,9 +0,0 @@ -# 下载源码 - -我们直接下载官方例子的源码,使用如下命令: - -``` -# cd ~/rpmbuild/SOURCES -# wget http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz -``` - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\345\212\250\346\200\201\351\223\276\346\216\245\345\272\223\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\345\212\250\346\200\201\351\223\276\346\216\245\345\272\223\347\244\272\344\276\213.md" deleted file mode 100644 index f0c1bae17c5b92a3c3303474907f5dd0a591d20a..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\345\212\250\346\200\201\351\223\276\346\216\245\345\272\223\347\244\272\344\276\213.md" +++ /dev/null @@ -1,113 +0,0 @@ -# 使用GCC创建和使用动态链接库示例 - -1. cd到代码目录,此处以用户“/home/code”进行举例。并在该目录下创建src,lib,include子目录,分别用于存放源文件,动态库文件和头文件。 - - ``` - cd /home/code - mkdir src - mkdir lib - mkdir include - ``` - -2. cd到/home/code/src目录,创建2个函数add.c、sub.c,分别实现加、减。 - - ``` - cd /home/code/src - vi add.c - vi sub.c - ``` - - add.c代码内容示例: - - ``` - #include "math.h" - int add(int a, int b) - { - return a+b; - } - ``` - - sub.c代码内容示例: - - ``` - #include "math.h" - int sub(int a, int b) - { - return a-b; - } - ``` - -3. 将add.c、sub.c源文件创建为动态库libmath.so,并将该动态库存放在/home/code/lib目录。 - - ``` - gcc -fPIC -shared add.c sub.c -o /home/code/lib/libmath.so - ``` - -4. cd到/home/code/include目录,创建1个头文件math.h,声明函数的头文件。 - - ``` - cd /home/code/include - vi math.h - ``` - - math.h代码内容示例: - - ``` - #ifndef __MATH_H_ - #define __MATH_H_ - int add(int a, int b); - int sub(int a, int b); - #endif - ``` - -5. cd到/home/code/src目录,创建一个调用add\(\)和sub\(\)的main.c函数。 - - ``` - cd /home/code/src - vi main.c - ``` - - math.c代码内容示例: - - ``` - #include - #include "math.h" - int main() - { - int a, b; - printf("Please input a and b:\n"); - scanf("%d %d", &a, &b); - printf("The add: %d\n", add(a,b)); - printf("The sub: %d\n", sub(a,b)); - return 0; - } - ``` - -6. 将main.c和libmath.so一起编译成math.out。 - - ``` - gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out - ``` - -7. 将动态链接库所在的路径加入到环境变量中。 - - ``` - export LD_LIBRARY_PATH=/home/code/lib:$LD_LIBRARY_PATH - ``` - -8. 执行math.out。 - - ``` - ./math.out - ``` - - 执行结果如下所示: - - ``` - Please input a and b: - 9 2 - The add: 11 - The sub: 7 - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\351\235\231\346\200\201\351\223\276\346\216\245\345\272\223\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\351\235\231\346\200\201\351\223\276\346\216\245\345\272\223\347\244\272\344\276\213.md" deleted file mode 100644 index d7e0661c8b4f8a11c5746ab6ab9d972e7ce6fad9..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\345\210\233\345\273\272\345\222\214\344\275\277\347\224\250\351\235\231\346\200\201\351\223\276\346\216\245\345\272\223\347\244\272\344\276\213.md" +++ /dev/null @@ -1,113 +0,0 @@ -# 使用GCC创建和使用静态链接库示例 - -1. cd到代码目录,此处以用户“/home/code”进行举例。并在该目录下创建src,lib,include子目录,分别用于存放源文件,静态库文件和头文件。 - - ``` - cd /home/code - mkdir src - mkdir lib - mkdir include - ``` - -2. cd到/home/code/src目录,创建2个函数add.c、sub.c,分别实现加、减。 - - ``` - cd /home/code/src - vi add.c - vi sub.c - ``` - - add.c代码内容示例: - - ``` - #include "math.h" - int add(int a, int b) - { - return a+b; - } - ``` - - sub.c代码内容示例: - - ``` - #include "math.h" - int sub(int a, int b) - { - return a-b; - } - ``` - -3. 将add.c、sub.c源文件编译为目标文件add.o、sub.o。 - - ``` - gcc -c add.c sub.c - ``` - -4. 将add.o、sub.o目标文件通过ar命令打包成静态库libmath.a,并将该动态库存放在/home/code/lib目录。 - - ``` - ar rcs /home/code/lib/libmath.a add.o sub.o - ``` - -5. cd到/home/code/include目录,创建1个头文件math.h,声明函数的头文件。 - - ``` - cd /home/code/include - vi math.h - ``` - - math.h代码内容示例: - - ``` - #ifndef __MATH_H_ - #define __MATH_H_ - int add(int a, int b); - int sub(int a, int b); - #endif - ``` - -6. cd到/home/code/src目录,创建一个调用add\(\)和sub\(\)的main.c函数。 - - ``` - cd /home/code/src - vi main.c - ``` - - math.c代码内容示例: - - ``` - #include - #include "math.h" - int main() - { - int a, b; - printf("Please input a and b:\n"); - scanf("%d %d", &a, &b); - printf("The add: %d\n", add(a,b)); - printf("The sub: %d\n", sub(a,b)); - return 0; - } - ``` - -7. 将main.c和libmath.a一起编译成math.out。 - - ``` - gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out - ``` - -8. 执行math.out。 - - ``` - ./math.out - ``` - - 执行结果如下所示: - - ``` - Please input a and b: - 9 2 - The add: 11 - The sub: 7 - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221.md" index 43f30110435a919c6123ecfdd8b069e616dc327f..c15b6bb206c20bfc8507f0d899675c1a3e677840 100644 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221.md" +++ "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221.md" @@ -1,6 +1,622 @@ -# 使用GCC编译 +# 使用GCC编译 本章介绍GCC编译的一些基本知识,并通过示例进行实际演示。更多的GCC知识请通过**man gcc**命令查询。 + +- [使用GCC编译](#使用gcc编译) + - [简介](#简介) + - [基本规则](#基本规则) + - [文件类型](#文件类型) + - [编译流程](#编译流程) + - [编译选项](#编译选项) + - [多源文件编译](#多源文件编译) + - [库](#库) + - [动态链接库](#动态链接库) + - [静态链接库](#静态链接库) + - [示例](#示例) + - [使用GCC编译C程序示例](#使用gcc编译c程序示例) + - [使用GCC创建和使用动态链接库示例](#使用gcc创建和使用动态链接库示例) + - [使用GCC创建和使用静态链接库示例](#使用gcc创建和使用静态链接库示例) + + +## 简介 + +GCC(GNU Compiler Collection)是GNU推出的功能强大、性能优越的多平台编译器。GCC编译器能将C、C++语言源程序、汇编程序和目标程序编译、连接成可执行文件。openEuler操作系统中已默认安装了GCC软件包。 + +## 基本规则 + + + +### 文件类型 + +对于任何给定的输入文件,文件类型决定进行何种编译。GCC常用的文件类型如[表1](#table634145764320)所示。 + +**表 1** GCC常用的文件类型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

扩展名(后缀)

+

说明

+

.c

+

C语言源代码文件。

+

.C,.cc或.cxx

+

C++源代码文件。

+

.m

+

Objective-C源代码文件。

+

.s

+

汇编语言源代码文件。

+

.i

+

已经预处理的C源代码文件。

+

.ii

+

已经预处理的C++源代码文件。

+

.S

+

已经预处理的汇编语言源代码文件。

+

.h

+

程序所包含的头文件。

+

.o

+

编译后的目标文件。

+

.so

+

动态链接库,它是一种特殊的目标文件。

+

.a

+

静态链接库。

+

.out

+

可执行文件,但可执行文件没有统一的后缀,系统从文件的属性来区分可执行文件和不可执行文件。如果没有给出可执行文件的名字,GCC将生成一个名为a.out的文件。

+
+ +### 编译流程 + +使用GCC将源代码文件生成可执行文件,需要经过预处理、编译、汇编和链接。 + +1. 预处理:将源程序(如 **.c** 文件)预处理,生成 **.i** 文件。 +2. 编译:将预处理后的 **.i** 文件编译成为汇编语言,生成 **.s** 文件。 +3. 汇编:将汇编语言文件经过汇编,生成目标文件 **.o** 文件。 +4. 链接:将各个模块的 **.o** 文件链接起来生成一个可执行程序文件。 + +其中 **.i** 文件、**.s**文件、**.o**文件是中间文件或临时文件,如果使用GCC一次性完成C语言程序的编译,则这些文件会被删除。 + +### 编译选项 + +GCC编译的命令格式为:**gcc** \[_options_\] \[_filenames_\] + +其中: + +_options_ :编译选项。 + +_filenames_ :文件名称。 + +GCC是一个功能强大的编译器,其 _options_ 参数取值很多,但有些大部分并不常用,常用的 _options_ 取值如[表2](#table1342946175212)所示。 + +**表 2** GCC常用的编译选项 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

options取值

+

说明

+

示例

+

-c

+

编译、汇编指定的源文件生成目标文件,但不进行链接。通常用于编译不包含主程序的子程序文件。

+

#使用-c选项编译test1.c、test2.c源文件

+

gcc -c test1.c test2.c

+

-S

+

编译指定的源文件生成以.s作为后缀的汇编语言文件,但不进行汇编。

+

#编译器预处理 circle.c,将其翻译成汇编语言,并将结果存储在 circle.s 文件中。

+

gcc -S circle.c

+

-E

+

预处理指定的源文件,但不进行编译。

+

默认情况下,预处理器的输出会被导入到标准输出流(如显示器),可以利用-o选项把它导入到某个输出文件。

+

#预处理的结果导出到 circle.i 文件。

+

gcc -E circle.c -o circle.i

+

-o file

+

用在生成可执行文件时,生成指定的输出文件file。同时该名称不能和源文件同名。如果不给出这个选项,gcc就给出预设的可执行文件a.out。

+

#将源文件作为输入文件,将可执行文件作为输出文件,也即完整地编译整个程序。

+

gcc main.c func.c -o app.out

+

-g

+

在可执行程序中包含标准调试信息。

+

-

+

-L libary_path

+

在库文件的搜索路径列表中添加libary_path路径。

+

-

+

-Ilibrary

+

链接时搜索指定的函数库library

+

使用 GCC 编译和链接程序时,GCC 默认会链接 libc.a 或者 libc.so,但是对于其他的库(例如非标准库、第三方库等),就需要手动添加。

+

#使用-l选项,以链接数学库。

+

gcc main.c -o main.out -lm

+
说明:

数学库的文件名是 libm.a。前缀lib和后缀.a是标准的,m是基本名称,GCC 会在-l选项后紧跟着的基本名称的基础上自动添加这些前缀、后缀,本例中,基本名称为 m。

+
+

-I head_path

+

在头文件的搜索路径列表中添加head_path路径。

+

-

+

-static

+

进行静态编译,及链接静态库,禁止链接动态库。

+

-

+

-shared

+

默认选项,可省略。

+
  • 可以生成动态库文件。
  • 进行动态编译,优先链接动态库,只有没有动态库是才会链接同名的静态库。
+

-

+

-fPIC(或-fpic)

+

生成使用相对地址的位置无关的目标代码。通常使用-static选项从该PIC目标文件生成动态库文件。

+

-

+
+ +### 多源文件编译 + +多个源文件的编译方法有2种。 + +- 多个源文件一起编译。编译时需要所有文件重新编译。 + + 示例:将test1.c和tes2.c分别编译后链接成test可执行文件。 + + ``` + gcc test1.c test2.c -o test + ``` + +- 分别编译各个源文件,之后对编译后输出的目标文件链接。编译时只重新编译修改的文件,未修改的文件不用重新编译。 + + 示例:分别编译test1.c,test2.c,在将二者的目标文件test1.o,test2.o链接成test可执行文件。 + + ``` + gcc -c test1.c + gcc -c test2.c + gcc -o test1.o test2.o -o test + ``` + + +## 库 + +库是写好的、现有的、成熟的、可以复用的代码。每个程序都要依赖很多基础的底层库。 + +库文件在命名时约定,以lib为前缀,以.so(动态库)或.a(静态库)为后缀,中间为库文件名。如libfoo.so或libfoo.a。由于所有的库文件都遵循了同样的规范,因此当在链接库时,-l 选项指定链接的库文件名时可以省去lib前缀,即GCC 在对-lfoo 进行处理时,会自动去链接名为libfoo.so 或libfoo.a的库文件。而当在创建库时,必须指定完整文件名libfoo.so或libfoo.a。 + +根据链接时期的不同,库分为静态库和动态库。静态库是在链接阶段,将汇编生成的目标文件.o与引用到的库一起链接打包到可执行文件中;而动态库是在程序编译时并不会被链接到目标代码中,而是在程序运行时才被载入。二者有如下差异。 + +- 资源利用不一样。 + + 静态库为生成的可执行文件的一部分,而动态库为单独的文件。所以使用静态库和和动态库的可执行文件大小和占用的磁盘空间大小不一样,导致资源利用不一样。 + +- 扩展性与兼容性不一样 + + 静态库中某个函数的实现变了,那么可执行文件必须重新编译,而对于动态链接生成的可执行文件,只需要更新动态库本身即可,不需要重新编译可执行文件。 + +- 依赖不一样 + + 静态库的可执行文件不需要依赖其他的内容即可运行,而动态库的可执行文件必须依赖动态库的存在。所以静态库更方便移植。 + +- 加载速度不一样 + + 静态库在链接时就和可执行文件在一块了,而动态库在加载或者运行时才链接,因此,对于同样的程序,静态链接的要比动态链接加载更快。 + + +### 动态链接库 + +使用-shared选项 和-fPIC选项,可直接使用源文件、汇编文件或者目标文件创建一个动态库。其中-fPIC 选项作用于编译阶段,在生成目标文件时就需要使用该选项,以生成位置无关的代码。 + +示例1:从源文件生成动态链接库。 + +``` +gcc -fPIC -shared test.c -o libtest.so +``` + +示例2:从目标文件生成动态链接库。 + +``` +gcc -fPIC -c test.c -o test.o +gcc -shared test.o -o libtest.so +``` + +将一个动态库链接到可执行文件,需要在命令行中列出动态库的名称。 + +示例:将main.c和libtest.so一起编译成 app.out,当 app.out 运行时,会动态地加载链接库 libtest.so。 + +``` +gcc main.c libtest.so -o app.out +``` + +这种方式是直接指定使用当前目录下的libtest.so文件。 + +若使用下面搜索动态库的方式,则为了确保程序在运行时能够链接到动态库,需要通过如下三种方法中的任一种实现。 + +- 将动态库保存在标准目录下,例如 /usr/lib。 +- 把动态库所在路径libaryDIR增加到环境变量LD\_LIBRARY\_PATH中 + + export LD\_LIBRARY\_PATH=libraryDIR:$LD\_LIBRARY\_PATH + + >![](public_sys-resources/icon-note.gif) **说明:** + >LD\_LIBRARY\_PATH为动态库的环境变量。当运行动态库时,若动态库不在缺省文件夹(/lib 和/usr/lib)下,则需要指定环境变量LD\_LIBRARY\_PATH。 + +- 把动态库所在路径libaryDIR增加 /etc/ld.so.conf中然后执行ldconfig或者以动态库所在路径libaryDIR为参数执行ldconfig。 + +``` +gcc main.c -L libraryDIR -ltest -o app.out +export LD_LIBRARY_PATH=libraryDIR:$LD_LIBRARY_PATH +``` + +### 静态链接库 + +创建一个静态链接库,需要先将源文件编译为目标文件,然后在使用ar命令将目标文件打包成静态链接库。 + +示例:将源文件test1.c,test2.c,test3.c编译并打包成静态库。 + +``` +gcc -c test1.c test2.c test3.c +ar rcs libtest.a test1.o test2.o test3.o +``` + +其中ar是一个备份压缩命令,可以将多个文件打包成一个备份文件(也叫归档文件),也可以从备份文件中提取成员文件。ar最常见的用法是将目标文件打包为静态链接库。 + +ar将目标文件打包成静态链接库的命令格式为: + +ar rcs _Sllfilename_ _Targetfilelist_ + +- _Sllfilename_ :静态库文件名。 +- _Targetfilelist_ :目标文件列表。 +- r: 替换库中已有的目标文件,或者加入新的目标文件。 +- c: 创建一个库,不管库否存在,都将创建。 +- s: 创建目标文件索引,在创建较大的库时能提高速度。 + +示例:创建一个main.c文件来使用静态库 + +``` +gcc main.c -L libraryDIR -ltest -o test.out +``` + +其中libraryDIR为libtest.a库的路径。 + +## 示例 + + +### 使用GCC编译C程序示例 + +1. cd到代码目录,此处以用户“/home/code”进行举例。如下所示: + + ``` + cd /home/code + ``` + +2. 编写Hello World程序,保存为helloworld.c,此处以编译Hello World程序进行举例说明。示例如下: + + ``` + vi helloworld.c + ``` + + 代码内容示例: + + ``` + #include + int main() + { + printf("Hello World!\n"); + return 0; + } + ``` + +3. 在代码目录,执行编译,使用命令: + + ``` + gcc helloworld.c -o helloworld + ``` + + 编译执行未报错,表明执行通过。 + +4. 编译完成后,会生成helloworld文件,查看编译结果,示例如下: + + ``` + # ./helloworld + Hello World! + ``` + + +### 使用GCC创建和使用动态链接库示例 + +1. cd到代码目录,此处以用户“/home/code”进行举例。并在该目录下创建src,lib,include子目录,分别用于存放源文件,动态库文件和头文件。 + + ``` + cd /home/code + mkdir src + mkdir lib + mkdir include + ``` + +2. cd到/home/code/src目录,创建2个函数add.c、sub.c,分别实现加、减。 + + ``` + cd /home/code/src + vi add.c + vi sub.c + ``` + + add.c代码内容示例: + + ``` + #include "math.h" + int add(int a, int b) + { + return a+b; + } + ``` + + sub.c代码内容示例: + + ``` + #include "math.h" + int sub(int a, int b) + { + return a-b; + } + ``` + +3. 将add.c、sub.c源文件创建为动态库libmath.so,并将该动态库存放在/home/code/lib目录。 + + ``` + gcc -fPIC -shared add.c sub.c -o /home/code/lib/libmath.so + ``` + +4. cd到/home/code/include目录,创建1个头文件math.h,声明函数的头文件。 + + ``` + cd /home/code/include + vi math.h + ``` + + math.h代码内容示例: + + ``` + #ifndef __MATH_H_ + #define __MATH_H_ + int add(int a, int b); + int sub(int a, int b); + #endif + ``` + +5. cd到/home/code/src目录,创建一个调用add\(\)和sub\(\)的main.c函数。 + + ``` + cd /home/code/src + vi main.c + ``` + + math.c代码内容示例: + + ``` + #include + #include "math.h" + int main() + { + int a, b; + printf("Please input a and b:\n"); + scanf("%d %d", &a, &b); + printf("The add: %d\n", add(a,b)); + printf("The sub: %d\n", sub(a,b)); + return 0; + } + ``` + +6. 将main.c和libmath.so一起编译成math.out。 + + ``` + gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out + ``` + +7. 将动态链接库所在的路径加入到环境变量中。 + + ``` + export LD_LIBRARY_PATH=/home/code/lib:$LD_LIBRARY_PATH + ``` + +8. 执行math.out。 + + ``` + ./math.out + ``` + + 执行结果如下所示: + + ``` + Please input a and b: + 9 2 + The add: 11 + The sub: 7 + ``` + + +### 使用GCC创建和使用静态链接库示例 + +1. cd到代码目录,此处以用户“/home/code”进行举例。并在该目录下创建src,lib,include子目录,分别用于存放源文件,静态库文件和头文件。 + + ``` + cd /home/code + mkdir src + mkdir lib + mkdir include + ``` + +2. cd到/home/code/src目录,创建2个函数add.c、sub.c,分别实现加、减。 + + ``` + cd /home/code/src + vi add.c + vi sub.c + ``` + + add.c代码内容示例: + + ``` + #include "math.h" + int add(int a, int b) + { + return a+b; + } + ``` + + sub.c代码内容示例: + + ``` + #include "math.h" + int sub(int a, int b) + { + return a-b; + } + ``` + +3. 将add.c、sub.c源文件编译为目标文件add.o、sub.o。 + + ``` + gcc -c add.c sub.c + ``` + +4. 将add.o、sub.o目标文件通过ar命令打包成静态库libmath.a,并将该动态库存放在/home/code/lib目录。 + + ``` + ar rcs /home/code/lib/libmath.a add.o sub.o + ``` + +5. cd到/home/code/include目录,创建1个头文件math.h,声明函数的头文件。 + + ``` + cd /home/code/include + vi math.h + ``` + + math.h代码内容示例: + + ``` + #ifndef __MATH_H_ + #define __MATH_H_ + int add(int a, int b); + int sub(int a, int b); + #endif + ``` + +6. cd到/home/code/src目录,创建一个调用add\(\)和sub\(\)的main.c函数。 + + ``` + cd /home/code/src + vi main.c + ``` + + math.c代码内容示例: + + ``` + #include + #include "math.h" + int main() + { + int a, b; + printf("Please input a and b:\n"); + scanf("%d %d", &a, &b); + printf("The add: %d\n", add(a,b)); + printf("The sub: %d\n", sub(a,b)); + return 0; + } + ``` + +7. 将main.c和libmath.a一起编译成math.out。 + + ``` + gcc main.c -I /home/code/include -L /home/code/lib -lmath -o math.out + ``` + +8. 执行math.out。 + + ``` + ./math.out + ``` + + 执行结果如下所示: + + ``` + Please input a and b: + 9 2 + The add: 11 + The sub: 7 + ``` diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221C\347\250\213\345\272\217\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221C\347\250\213\345\272\217\347\244\272\344\276\213.md" deleted file mode 100644 index 256dd38a3178d54f5938204d728f942748a71059..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250GCC\347\274\226\350\257\221C\347\250\213\345\272\217\347\244\272\344\276\213.md" +++ /dev/null @@ -1,41 +0,0 @@ -# 使用GCC编译C程序示例 - -1. cd到代码目录,此处以用户“/home/code”进行举例。如下所示: - - ``` - cd /home/code - ``` - -2. 编写Hello World程序,保存为helloworld.c,此处以编译Hello World程序进行举例说明。示例如下: - - ``` - vi helloworld.c - ``` - - 代码内容示例: - - ``` - #include - int main() - { - printf("Hello World!\n"); - return 0; - } - ``` - -3. 在代码目录,执行编译,使用命令: - - ``` - gcc helloworld.c -o helloworld - ``` - - 编译执行未报错,表明执行通过。 - -4. 编译完成后,会生成helloworld文件,查看编译结果,示例如下: - - ``` - # ./helloworld - Hello World! - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250IDE\350\277\233\350\241\214Java\345\274\200\345\217\221.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250IDE\350\277\233\350\241\214Java\345\274\200\345\217\221.md" deleted file mode 100644 index a55ade07a8622a13d6e69a0cd6fb1c252c16084c..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250IDE\350\277\233\350\241\214Java\345\274\200\345\217\221.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 使用IDE进行Java开发 - -对于小型的Java程序,可以直接参考“使用JDK编译”章节得到可运行Java应用。但是对于大中型Java应用,这种方式已经无法满足开发者的需求。因此您可以参考如下步骤安装IDE并进行使用,以方便您在openEuler系统上的Java开发工作。 - - - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250JDK\347\274\226\350\257\221.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250JDK\347\274\226\350\257\221.md" index 0129cde9ad178c7eb674a8d9f204812ac922f4fa..d08a464eb8304b2b54be54bae1199b5c84af299a 100644 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250JDK\347\274\226\350\257\221.md" +++ "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250JDK\347\274\226\350\257\221.md" @@ -1,3 +1,530 @@ -# 使用JDK编译 +# 使用JDK编译 + +- [使用JDK编译](#使用jdk编译) + - [简介](#简介) + - [基本规则](#基本规则) + - [文件类型及工具](#文件类型及工具) + - [java程序生成流程](#java程序生成流程) + - [JDK常用工具选项](#jdk常用工具选项) + - [类库](#类库) + - [包的声明](#包的声明) + - [包的引用](#包的引用) + - [示例](#示例) + - [编译不带包的java程序示例](#编译不带包的java程序示例) + - [编译带包的java程序示例](#编译带包的java程序示例) + + +## 简介 + +JDK(Java Development Kit)是 Java 开发者进行 Java 开发所必须的软件包,包含 JRE(Java Runtime Environment)和编译、调测工具。openEuler在OpenJDK 的基础上进行了 GC 优化、并发稳定性增强、安全性增强等修改,提高了 Java 应用程序在 ARM 上的性能和稳定性。 + +## 基本规则 + + +### 文件类型及工具 + +对于任何给定的输入文件,文件类型决定采用何种工具进行处理。JDK常用的文件类型如[表1](#table634145764320)所示,JDK常用的工具如[表2](#table103504146433)所示。 + +**表 1** JDK常用的文件类型 + + + + + + + + + + + + + + + + +

扩展名(后缀)

+

说明

+

.java

+

java语言源代码文件。

+

.class

+

java的字节码文件,是一种和任何具体机器环境及操作系统环境无关的中间代码。它是一种二进制文件,是Java 源文件由 Java 编译器编译后生成的目标代码文件。

+

.jar

+

java的jar压缩文件。

+
+ +**表 2** JDK常用的工具 + + + + + + + + + + + + + + + + +

工具名称

+

说明

+

java

+

Java运行工具,用于运行.class字节码文件或.jar文件。

+

javac

+

Java编程语言的编译器,将.java的源代码文件编译成.class的字节码文件。

+

jar

+

创建和管理Jar文件

+
+ +### java程序生成流程 + +通过JDK将java源代码文件生成并运行Java程序,需要经过编译和运行。 + +1. 编译:是指使用Java编译器(javac)将java源代码文件(.java文件)编译为.class的字节码文件。 +2. 运行:是指在Java虚拟机上执行字节码文件。 + +### JDK常用工具选项 + +#### javac编译选项 + +javac编译的命令格式为:**javac** \[_options_\] \[_sourcefiles_\] \[_classes_\] \[@_argfiles_\] + +其中: + +_options_ :命令选项。 + +_sourcefiles_ :一个或多个需要编译的源文件。 + +_classes_ :一个或多个要为注释处理的类。 + +@_argfiles_ :一个或多个列出选项和源文件的文件。这些文件中不允许有-J选项。 + +javac是java编译器,其 _options_ 参数取值很多,但有些大部分并不常用,常用的 _options_ 取值如[表3](#table1342946175212)所示。 + +**表 3** javac常用的编译选项 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

options取值

+

说明

+

示例

+

-d path

+

指定存放生成的类文件的路径

+

默认情况下,编译生成的类文件与源文件在同一路径下。使用-d选项可以将类文件输出到指定路径。

+

#使用-d选项将所有类文件输出到bin路径下

+

javac /src/*.java -d /bin

+

-s path

+

指定存放生成的源文件的路径

+

-

+

-cp path或-classpath path

+

搜索编译所需的class文件,指出编译所用到的class文件的位置。

+

#在Demo中要调用GetStringDemo类中的getLine()方法,而GetStringDemo类编译后的文件,即.class文件在bin目录下。

+

javac -cp bin Demo.java -d bin

+

-verbose

+

输出关于编译器正在执行的操作的消息,如加载的类信息和编译的源文件信息。

+

#输出关于编译器正在执行的操作的消息。

+

javac -verbose -cp bin Demo.java

+

-source sourceversion

+

指定查找输入源文件的位置。

+

-

+

-sourcepath path

+

用于搜索编译所需的源文件(即java文件),指定要搜索的源文件的位置,如jar、zip或其他包含java文件的目录。

+

-

+

-target targetversion

+

生成特定JVM版本的类文件。取值为1.1,1.2,1.3,1.4,1.5(或5),1.6(或6),1.7(或7),1.8(或8)。targetversion的默认取值与-source选项的sourceversion有关。sourceversion取值:

+
  • 1.2,targetversion为1.4;
  • 1.3,targetversion为1.4;
  • 1.5、1.6、1.7、未指定,targetversion为1.8。
  • 其他值,targetversionsourceversion取值相同。
+

-

+
+ +#### java运行选项 + +java运行的格式为: + +运行类文件:**java** \[_options_\] _classesname_ \[args\] + +运行jar文件:**java** \[_options_\] -jar _filename_ \[args\] + +其中: + +_options_ :命令选项,选项之间用空格分隔。 + +_classname_ :运行的.class文件名。 + +_filename_ :运行的.jar文件名。 + +args:传递给main\(\)函数的参数,参数之间用空格分隔。 + +java是运行java应用程序的工具,其 _options_ 参数取值很多,但有些大部分并不常用,常用的 _options_ 取值如[表4](#table371918587238)所示。 + +**表 4** java常用的运行选项 + + + + + + + + + + + + + + + + +

options取值

+

说明

+

示例

+

-cp path或-classpath path

+

指定要运行的文件所在的位置以及需要用到的类路径,包括jar、zip和class文件目录。

+

当路径有多个是,使用“:”分隔。

+

-

+

-verbose

+

输出关于编译器正在执行的操作的消息,如加载的类信息和编译的源文件信息。

+

#输出关于编译器正在执行的操作的消息。

+

java -verbose -cp bin Demo.java

+
+ +#### jar打包选项 + +jar的命令格式为:**jar** \{c | t | x | u\}\[vfm0M\] \[_jarfile_\] \[_manifest_\] \[-C _dir_\] _file_... + +jar命令参数说明如[表5](#table3691718114817)所示。 + +**表 5** jar命令参数说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

参数

+

说明

+

示例

+

c

+

创建jar文件包。

+

#把当前目录的hello.class文件打包到Hello.jar,且不显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。

+

jar cf Hello.jar hello.class

+

t

+

列出jar文件包的内容列表。

+

#列出Hello.jar包含的文件清单。

+

jar tf Hello.jar

+

x

+

展开jar文件包的指定文件或者所有文件。

+

#解压Hello.jar 到当前目录,不显示任何信息。

+

jar xf Hello.jar

+

u

+

更新已存在的jar文件包,如添加文件到jar文件包中。

+

-

+

v

+

生成详细报告并打印到标准输出。

+

#把当前目录的hello.class文件打包到Hello.jar,并显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。

+

jar cvf Hello.jar hello.class

+

f

+

指定jar文件名,通常这个参数是必须的。

+

-

+

m

+

指定需要包含的manifest清单文件。

+

-

+

0

+

只存储,不压缩,这样产生的jar文件包会比不用该参数产生的体积大,但速度更快。

+

-

+

M

+

不产生所有项的manifest清单文件,此参数会忽略m参数

+

#把当前目录的hello.class文件打包到Hello.jar,并显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。但在创建Hello.jar时不产生manifest 文件。

+

jar cvfM Hello.jar hello.class

+

jarfile

+

.jar文件包,它是f参数的附属参数。

+

-

+

manifest

+

.mf的manifest清单文件,它是m参数的附属参数

+

-

+

-C dir

+

转到指定dir下执行jar命令,只能配合参数c、t使用。

+

-

+

file

+

指定文件/路径列表,文件或路径下的所有文件(包括递归路径下的)都会被打入jar文件包中,或解压jar文件到路径下。

+

#把当前目录的所有class文件打包到Hello.jar,并显示打包的过程。如果Hello.jar文件还不存在,就创建它,否则首先清空它。

+

jar cvf Hello.jar *.class

+
+ +## 类库 + +java类库是以包的形式实现的,包是类和接口的集合。java编译器为每个类生成一个字节码文件,且文件名与类名相同,因此同名的类之间就有可能发生冲突。java语言中,把一组类和接口封装在一个包内,包可以有效地管理类名空间,位于不同包中的类即使同名也不会冲突,从而解决了同名类之间可能发生的冲突问题,为管理大量的类和接口提供了方便,也有利于类和接口的安全。 + +除java提供的许多包外,开发者也可以自定义包,把自己编写的类和接口等组成程序包的形式,以便后续使用。 + +自定义包需要先声明包,然后在使用包。 + +### 包的声明 + +包的声明格式为:package pkg1\[.pkg2\[.pkg3...\]\]; + +为了声明一个包,首先必须建立一个相应的目录结构,子目录与包名一致,然后在需要放入该包的类文件开头声明包,表示该文件的全部类都属于这个包。包声明中的“.”指明了目录的层次。如果源程序文件中没有package语句,则指定为无名包。无名包没有路径,一般情况下,java仍然会把源文件中的类存储在当前工作目录(即存放java源文件的目录)下。 + +包声明语句必须被加到源程序文件的起始部分,而且前面不能有注释和空格。如果在不同源程序文件中使用相同的包声明语句,就可以将不同源程序文件中的类都包含在相同的包中。 + +### 包的引用 + +在 Java 中,为了能使用java提供的包中的公用类,或者使用自定义的包中的类,有两种方法。 + +- 在要引用的类名前带上包名。 + + 如:name.A obj=new name.A \(\); + + 其中,name为包名,A为类名,obj为对象。表示程序中用name包中的A类定义一个对象obj。 + + 示例:新建一个example包中Test类的test对象。 + + ``` + example.Test test = new example.Test(); + ``` + +- 在文件开头使用import来导入包中的类。 + + import语句的格式为:import pkg1\[.pkg2\[.pkg3...\]\].\(classname | \*\); + + 其中,pkg1\[.pkg2\[.pkg3...\]\]表明包的层次,classname为所要导入的类。如果要从一个包中导入多个类,则可以使用通配符“\*”来替代。 + + 示例:导入example包中的Test类。 + + ``` + import example.Test; + ``` + + 示例:将example 整个包导入。 + + ``` + import example.*; + ``` + + +## 示例 + + +### 编译不带包的java程序示例 + +1. cd到代码目录,此处以用户“/home/code”进行举例。如下所示: + + ``` + # cd /home/code + ``` + +2. 编写Hello World程序,保存为HelloWorld.java,此处以编译Hello World程序进行举例说明。示例如下: + + ``` + # vi HelloWorld.java + ``` + + 代码内容示例: + + ``` + public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello World"); + } + } + ``` + +3. 在代码目录,执行编译,使用命令: + + ``` + # javac HelloWorld.java + ``` + + 编译执行未报错,表明执行通过。 + +4. 编译完成后,会生成 HelloWorld.class 文件,通过java命令可执行查看结果,示例如下: + + ``` + # java HelloWorld + Hello World + ``` + + +### 编译带包的java程序示例 + +1. cd到代码目录,此处以用户“/home/code”进行举例。并在该目录下创建“/home/code/Test/my/example”、“/home/code/Hello/world/developers”、“/home/code/Hi/openos/openeuler”子目录,分别用于存放源文件。 + + ``` + cd /home/code + + mkdir -p Test/my/example + mkdir -p Hello/world/developers + mkdir -p Hi/openos/openeuler + ``` + +2. cd到/home/code/Test/my/example目录,创建Test.java。 + + ``` + cd /home/code/Test/my/example + vi Test.java + ``` + + Test.java代码内容示例: + + ``` + package my.example; + import world.developers.Hello; + import openos.openeuler.Hi; + public class Test { + public static void main(String[] args) { + Hello me = new Hello(); + me.hello(); + Hi you = new Hi(); + you.hi(); + } + } + ``` + +3. cd到/home/code/Hello/world/developers目录,创建Hello.java。 + + ``` + cd /home/code/Hello/world/developers + vi Hello.java + ``` + + Hello.java代码内容示例: + + ``` + package world.developers; + public class Hello { + public void hello(){ + System.out.println("Hello, openEuler."); + } + } + ``` + +4. cd到/home/code/Hi/openos/openeuler目录,创建Hi.java。 + + ``` + cd /home/code/Hi/openos/openeuler + vi Hi.java + ``` + + Hi.java代码内容示例: + + ``` + package openos.openeuler; + public class Hi { + public void hi(){ + System.out.println("Hi, the global developers."); + } + } + ``` + +5. cd到/home/code,使用javac编译源文件。 + + ``` + cd /home/code + javac -classpath Hello:Hi Test/my/example/Test.java + ``` + + 执行完命令后,会在“/home/code/Test/my/example”、“/home/code/Hello/world/developers”、“/home/code/Hi/openos/openeuler”目录下分别生成Test.class、Hello.class、Hi.class文件。 + +6. cd到/home/code,使用java运行Test程序。 + + ``` + cd /home/code + java -classpath Test:Hello:Hi my/example/Test + ``` + + 执行结果如下所示: + + ``` + Hello, openEuler. + Hi, the global developers. + ``` diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250Makefile\345\256\236\347\216\260\347\274\226\350\257\221\347\232\204\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250Makefile\345\256\236\347\216\260\347\274\226\350\257\221\347\232\204\347\244\272\344\276\213.md" deleted file mode 100644 index 4cb7935d168bfa4387396d54a8f5d861d1813e72..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250Makefile\345\256\236\347\216\260\347\274\226\350\257\221\347\232\204\347\244\272\344\276\213.md" +++ /dev/null @@ -1,100 +0,0 @@ -# 使用Makefile实现编译的示例 - -1. cd到代码目录,此处以用户“/home/code”进行举例。 - - ``` - cd /home/code - ``` - -2. 创建1个头文件hello.h和2个函数hello.c、main.c。 - - ``` - cd /home/code/ - ``` - - hello.h代码内容示例: - - ``` - #pragma once - #include - void hello(); - ``` - - hello.c代码内容示例: - - ``` - #include "hello.h" - void hello() - { - int i=1; - while(i<5) - { - printf("The %dth say hello.\n", i); - i++; - } - } - - ``` - - main.c代码内容示例: - - ``` - #include "hello.h" - #include - int main() - { - hello(); - return 0; - } - ``` - -3. 创建Makefile文件。 - - ``` - vi Makefile - ``` - - Makefile文件内容示例: - - ``` - main:main.o hello.o - gcc -o main main.o hello.o - main.o:main.c - gcc -c main.c - hello.o:hello.c - gcc -c hello.c - clean: - rm -f hello.o main.o main - ``` - -4. 执行make命令。 - - ``` - make - ``` - - 命令执行后,会打印Makefile中执行的命令。如果不需要打印该信息,可以在执行make命令是加上参数-s。 - - gcc -c main.c - - gcc -c hello.c - - gcc -o main main.o hello.o - -5. 执行./main目标。 - - ``` - ./main - ``` - - 命令执行后,打印如下信息: - - The 1th say hello. - - The 2th say hello. - - The 3th say hello. - - The 4th say hello. - - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250MobaXterm\347\231\273\345\275\225\346\234\215\345\212\241\345\231\250.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250MobaXterm\347\231\273\345\275\225\346\234\215\345\212\241\345\231\250.md" deleted file mode 100644 index a9bf8c15e50be87d870a56b51523f1dba3d4333e..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250MobaXterm\347\231\273\345\275\225\346\234\215\345\212\241\345\231\250.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 使用MobaXterm登录服务器 - -MobaXterm是一款非常优秀的SSH客户端,其自带X Server,可以轻松解决远程GUI显示问题。 - -您需要提前下载安装好MobaXterm并打开,然后SSH登录您的服务器并进行以下操作。 - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250OBS\346\236\204\345\273\272.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250OBS\346\236\204\345\273\272.md" deleted file mode 100644 index 3102d90d2e4b888751293ebe9a10e9ddc1fb1159..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250OBS\346\236\204\345\273\272.md" +++ /dev/null @@ -1,8 +0,0 @@ -# 使用OBS构建 - -本章介绍通过网页和osc构建RPM软件包的方法。主要包括如下两类: - -- 修改已有软件包:修改已有软件包源代码,然后将修改后的源代码构建成一个RPM软件包。 -- 新增软件包:从无到有全新开发一个新的软件源文件,并将新开发的源文件构建成一个RPM软件包。 - - diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250make\347\274\226\350\257\221.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250make\347\274\226\350\257\221.md" index 3b8e675bdf62d277d093954358a403e55761944d..f10d9cc1e071a35e4ae2eb80c084ed1542172efb 100644 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250make\347\274\226\350\257\221.md" +++ "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250make\347\274\226\350\257\221.md" @@ -1,5 +1,376 @@ -# 使用make编译 +# 使用make编译 本章介绍make编译的一些基本知识,并通过示例进行实际演示。更多的make知识请通过**man make**命令查询。 + +- [使用make编译](#使用make编译) + - [简介](#简介) + - [基本规则](#基本规则) + - [文件类型](#文件类型) + - [make工作流程](#make工作流程) + - [make选项](#make选项) + - [Makefile](#makefile) + - [Makefile结构](#makefile结构) + - [Makefile主要内容](#makefile主要内容) + - [示例](#示例) + - [使用Makefile实现编译的示例](#使用makefile实现编译的示例) + + + +## 简介 + +GNU make实用程序(通常缩写为make)是一种用于控制从源文件生成可执行文件的工具。 make会自动确定复杂程序的哪些部分已更改并需要重新编译。 make使用称为Makefiles的配置文件来控制程序的构建方式。 + +## 基本规则 + + +### 文件类型 + +makefile文件中可能用到的文件类型如[表1](#table634145764320)所示。 + +**表 1** 文件类型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

扩展名(后缀)

+

说明

+

.c

+

C语言源代码文件。

+

.C,.cc或.cxx

+

C++源代码文件。

+

.m

+

Objective-C源代码文件。

+

.s

+

汇编语言源代码文件。

+

.i

+

已经预处理的C源代码文件。

+

.ii

+

已经预处理的C++源代码文件。

+

.S

+

已经预处理的汇编语言源代码文件。

+

.h

+

程序所包含的头文件。

+

.o

+

编译后的目标文件。

+

.so

+

动态链接库,它是一种特殊的目标文件。

+

.a

+

静态链接库。

+

.out

+

可执行文件,但可执行文件没有统一的后缀,系统从文件的属性来区分可执行文件和不可执行文件。如果没有给出可执行文件的名字,GCC将生成一个名为a.out的文件。

+
+ +### make工作流程 + +使用make由源代码文件生成可执行文件,需要经过如下步骤。 + +1. make命令会读入Makefile文件,包括当前目录下命名为"GNUmakefile" 、"makefile" 、"Makefile"的文件、被include的makefile文件、参数-f、\-\-file、\-\-makefile指定的规则文件。 +2. 初始化变量。 +3. 推导隐含规则,分析依赖关系,并创建依赖关系链。 +4. 根据依赖关系链,决定哪些目标需要重新生成。 +5. 执行生成命令,最终输出终极文件。 + +### make选项 + +make命令格式为:**make** \[_option_\]... \[_target_\]... + +其中: + +_option_ :参数选项。 + +_target_ :Makefile中指定的目标。 + +常用make的 _option_ 取值如[表2](#table261872312343)所示。 + +**表 2** 常用的make选项 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

options取值

+

说明

+

-C dir,\-\-directory=dir

+

指定make在开始运行后的工作目录为dir

+

当存在多个 -C 选项的时候,make 的最终工作目录是第一个目录的相对路径。

+

-d

+

make在执行的过程中打印出所有的调试信息。使用-d选项可以显示make构造依赖关系链、重建目标过程中的所有信息。

+

-e,\-\-enveronment-overrides

+

使用环境变量定义覆盖Makefile中的同名变量定义。

+

-f file,\-\-file=file

+

\-\-makefile=file

+

指定file文件为make 执行的Makefile文件。

+

-p,\-\-help

+

打印帮助信息。

+

-i,\-\-ignore-errors

+

执行过程中忽略规则命令执行的错误。

+

-k,\-\-keep-going

+

执行命令错误时不终止make的执行,make 尽最大可能执行所有的命令,直至出现知名的错误才终止。

+

-n,\-\-just-print,\-\-dry-run

+

按实际运行时的执行顺序模拟执行命令(包括用@开头的命令),没有实际执行效果,仅仅用于显示执行过程。

+

-o file,\-\-old-file=file,\-\-assume-old=file

+

指定file文件不需要重建,即使它的依赖已经过期,同时不重建此依赖文件的任何目标。

+

-p,\-\-print-date-base

+

命令执行之前,打印出make读取的Makefile的所有数据,同时打印出 make的版本信息。如果只需要打印这些数据信息,可以使用 “make -qp”命令,查看 make 执行之前预设的规则和变量,可使用命令“make -p -f /dev/null”。

+

-r,\-\-no-builtin-rules

+

忽略内嵌的隐含规则的使用,同时忽略所有后缀规则的隐含后缀列表。

+

-R,\-\-no-builtin-variabes

+

忽略内嵌的隐含变量。

+

-s,\-\-silent,\-\-quiet

+

取消命令执行过程中的打印。

+

-S,\-\-no-keep-going,\-\-stop

+

取消 "-k" 的选项在递归的 make 过程中子 make 通过 "MAKEFLAGS" 变量继承了上层的命令行选项那个。我们可以在子 make 中使用“-S”选项取消上层传递的 "-k" 选项,或者取消系统环境变量 "MAKEFLAGS" 中 "-k"选项。

+

-t,\-\-touch

+

更新所有的目标文件的时间戳到当前系统时间。防止 make 对所有过时目标文件的重建。

+

-v,version

+

查看make的版本信息。

+
+ +## Makefile + +make是通过Makefile文件获取如何编译、链接和安装、清理的方法,从而实现将源代码文件生成可执行文件和其他相关文件的工具。因此,Makefile中描述了整个工程的编译和链接等规则,其中包含了哪些文件需要编译,哪些文件不需要编译,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重建等等。Makefile文件让工程编译实现了自动化,不需要每次都手动输入一堆源文件和参数。 + +本章简单介绍Makefile文件的结构和主要内容,更多Makefile的内容请通过**info make**命令查询 + +### Makefile结构 + +Makefile文件结构如下所示: + +_targets_:_prereguisites_ + +_command_ + +或者是: + +_targets_:_prerequisites_;_command_ + +_command_ + +其中: + +- _targets_ :目标,可以是目标文件、可执行文件或标签。 +- _prerequisites_ :依赖文件,生成targets需要的文件或者是目标。可以是多个,也可以是没有。 +- _command_ :make需要执行的命令(任意的 shell 命令)。可以有多条命令,每一条命令占一行。 +- 目标和依赖文件之间要使用“:”分隔,命令的开始一定要按“Tab”。 + +Makefile文件结构表明了输出的目标,输出目标的依赖对象和生成目标需要执行的命令。 + +### Makefile主要内容 + +一个Makefile文件主要由以下内容组成。 + +- 显式规则 + + 明确写出来的依赖关系,如要生成的文件,文件的依赖文件,生成的命令。 + +- 隐含规则 + + 由make自动推导的规则,make命令支持自动推导功能。 + +- 变量的定义 +- 文件指示 + + 文件指示包括三部分: + + - include 其他 Makefile,如include xx.md。 + - 选择执行,如\#ifdef。 + - 定义多行命令,如define...endef。\(define ... endef\) + +- 注释 + + 以 “\#” 开头。 + + +## 示例 + + + +### 使用Makefile实现编译的示例 + +1. cd到代码目录,此处以用户“/home/code”进行举例。 + + ``` + cd /home/code + ``` + +2. 创建1个头文件hello.h和2个函数hello.c、main.c。 + + ``` + cd /home/code/ + ``` + + hello.h代码内容示例: + + ``` + #pragma once + #include + void hello(); + ``` + + hello.c代码内容示例: + + ``` + #include "hello.h" + void hello() + { + int i=1; + while(i<5) + { + printf("The %dth say hello.\n", i); + i++; + } + } + + ``` + + main.c代码内容示例: + + ``` + #include "hello.h" + #include + int main() + { + hello(); + return 0; + } + ``` + +3. 创建Makefile文件。 + + ``` + vi Makefile + ``` + + Makefile文件内容示例: + + ``` + main:main.o hello.o + gcc -o main main.o hello.o + main.o:main.c + gcc -c main.c + hello.o:hello.c + gcc -c hello.c + clean: + rm -f hello.o main.o main + ``` + +4. 执行make命令。 + + ``` + make + ``` + + 命令执行后,会打印Makefile中执行的命令。如果不需要打印该信息,可以在执行make命令是加上参数-s。 + + gcc -c main.c + + gcc -c hello.c + + gcc -o main main.o hello.o + +5. 执行./main目标。 + + ``` + ./main + ``` + + 命令执行后,打印如下信息: + + The 1th say hello. + + The 2th say hello. + + The 3th say hello. + + The 4th say hello. diff --git "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250osc\346\236\204\345\273\272\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\344\275\277\347\224\250osc\346\236\204\345\273\272\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 8e6e6d17e4c62d2866fd4224bd9459097dc3b076..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\344\275\277\347\224\250osc\346\236\204\345\273\272\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 使用osc构建软件包 - -本章介绍使用OBS的命令行工具osc创建工程并构建RPM软件包的方法。 - - - diff --git "a/content/zh/docs/ApplicationDev/\345\210\233\345\273\272Hello-World-RPM\345\214\205.md" "b/content/zh/docs/ApplicationDev/\345\210\233\345\273\272Hello-World-RPM\345\214\205.md" deleted file mode 100644 index 1d24bf0f48c69be21fbc1e6b6e24e09eb9220421..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\210\233\345\273\272Hello-World-RPM\345\214\205.md" +++ /dev/null @@ -1,5 +0,0 @@ -# 创建Hello World RPM包 - -这里以GNU“Hello World” 项目的打包过程作为示例,包含了典型的FOSS(Free and Open Source Software) 软件项目相关的最常用的外围组件,其中包括配置/编译/安装环境、文档、国际化等等。 - - diff --git "a/content/zh/docs/ApplicationDev/\345\211\215\350\250\200.md" "b/content/zh/docs/ApplicationDev/\345\211\215\350\250\200.md" deleted file mode 100644 index 325fc6cf0d8e81b9cf8b08623bec159cdfa9146c..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\211\215\350\250\200.md" +++ /dev/null @@ -1,93 +0,0 @@ -# 前言 - -## 概述 - -本文档主要介绍如下四部分内容,以指导用户使用openEuler并基于openEuler进行代码开发。 - -- 在openEuler系统中安装和使用GCC编译器,并完成一个简单代码的开发、编译和执行。 -- 在openEuler系统中使用JDK自带工具完成代码的编译和执行。 -- 在openEuler系统中安装IntelliJ IDEA进行Java开发。 -- 在本地或使用OBS(Open Build Service)创建RPM(The RPM Package Manager)软件包的方法。 - -## 读者对象 - -本文档适用于所有使用openEuler操作系统进行代码开发的用户。用户需要具备如下经验或能力: - -- 具备Linux操作系统基础知识 -- 了解Linux命令行的基本使用方法 - -## 符号约定 - -在本文中可能出现下列标志,它们所代表的含义如下。 - - - - - - - - - - - - - -

符号

-

说明

-

-

用于传递设备或环境安全警示信息,若不避免,可能会导致设备损坏、数据丢失、设备性能降低或其它不可预知的结果。

-

“注意”不涉及人身伤害。

-

-

用于突出重要/关键信息、最佳实践和小窍门等。

-

“说明”不是安全警示信息,不涉及人身、设备及环境伤害。

-
- -## 命令行格式约定 - -**表 1** 命令行格式的约定 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

格式

-

含义

-

粗体

-

命令行关键字,即命令中保持不变、必须照输的部分,采用加粗字体表示。

-

斜体

-

命令行参数,即命令中必须由实际值进行替代的部分,采用斜体表示。

-

[ ]

-

用“[ ]”括起来的部分表示在命令配置时是可选的。

-

{ x | y | ... }

-

表示从两个或多个选项中选取一个。

-

[ x | y | ... ]

-

表示从两个或多个选项中选取一个或者不选。

-

{ x | y | ... }*

-

表示从两个或多个选项中选取多个,最少选取一个,最多选取所有选项。

-

[ x | y | ... ]*

-

表示从两个或多个选项中选取一个、多个或者不选。

-
- diff --git "a/content/zh/docs/ApplicationDev/\345\212\250\346\200\201\351\223\276\346\216\245\345\272\223.md" "b/content/zh/docs/ApplicationDev/\345\212\250\346\200\201\351\223\276\346\216\245\345\272\223.md" deleted file mode 100644 index 6425a076e89b9490921693bb8512db5d6ed21a12..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\212\250\346\200\201\351\223\276\346\216\245\345\272\223.md" +++ /dev/null @@ -1,44 +0,0 @@ -# 动态链接库 - -使用-shared选项 和-fPIC选项,可直接使用源文件、汇编文件或者目标文件创建一个动态库。其中-fPIC 选项作用于编译阶段,在生成目标文件时就需要使用该选项,以生成位置无关的代码。 - -示例1:从源文件生成动态链接库。 - -``` -gcc -fPIC -shared test.c -o libtest.so -``` - -示例2:从目标文件生成动态链接库。 - -``` -gcc -fPIC -c test.c -o test.o -gcc -shared test.o -o libtest.so -``` - -将一个动态库链接到可执行文件,需要在命令行中列出动态库的名称。 - -示例:将main.c和libtest.so一起编译成 app.out,当 app.out 运行时,会动态地加载链接库 libtest.so。 - -``` -gcc main.c libtest.so -o app.out -``` - -这种方式是直接指定使用当前目录下的libtest.so文件。 - -若使用下面搜索动态库的方式,则为了确保程序在运行时能够链接到动态库,需要通过如下三种方法中的任一种实现。 - -- 将动态库保存在标准目录下,例如 /usr/lib。 -- 把动态库所在路径libaryDIR增加到环境变量LD\_LIBRARY\_PATH中 - - export LD\_LIBRARY\_PATH=libraryDIR:$LD\_LIBRARY\_PATH - - >![](public_sys-resources/icon-note.gif) **说明:** - >LD\_LIBRARY\_PATH为动态库的环境变量。当运行动态库时,若动态库不在缺省文件夹(/lib 和/usr/lib)下,则需要指定环境变量LD\_LIBRARY\_PATH。 - -- 把动态库所在路径libaryDIR增加 /etc/ld.so.conf中然后执行ldconfig或者以动态库所在路径libaryDIR为参数执行ldconfig。 - -``` -gcc main.c -L libraryDIR -ltest -o app.out -export LD_LIBRARY_PATH=libraryDIR:$LD_LIBRARY_PATH -``` - diff --git "a/content/zh/docs/ApplicationDev/\345\234\250\347\272\277\346\236\204\345\273\272\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\345\234\250\347\272\277\346\236\204\345\273\272\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 9c365822cfc242fb7a2ea622d6e9db77e3d2bc37..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\234\250\347\272\277\346\236\204\345\273\272\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 在线构建软件包 - -本章介绍通过OBS网页端在线构建RPM软件包的方法。 - - - diff --git "a/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231-2.md" "b/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231-2.md" deleted file mode 100644 index 1bcb9e55df3c4033066e79ce25736467b291e00d..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231-2.md" +++ /dev/null @@ -1,3 +0,0 @@ -# 基本规则 - - diff --git "a/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231-6.md" "b/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231-6.md" deleted file mode 100644 index db565f03c04145966dce5fa16a8a5b7d37fe12cf..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231-6.md" +++ /dev/null @@ -1,3 +0,0 @@ -# 基本规则 - - diff --git "a/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231.md" "b/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231.md" deleted file mode 100644 index a16de89db8e2865fe3b7a4af243a4d9505631b1a..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\237\272\346\234\254\350\247\204\345\210\231.md" +++ /dev/null @@ -1,4 +0,0 @@ -# 基本规则 - - - diff --git "a/content/zh/docs/ApplicationDev/\345\244\232\346\272\220\346\226\207\344\273\266\347\274\226\350\257\221.md" "b/content/zh/docs/ApplicationDev/\345\244\232\346\272\220\346\226\207\344\273\266\347\274\226\350\257\221.md" deleted file mode 100644 index da41ebf82480a31f7abe966515504624687d191e..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\244\232\346\272\220\346\226\207\344\273\266\347\274\226\350\257\221.md" +++ /dev/null @@ -1,23 +0,0 @@ -# 多源文件编译 - -多个源文件的编译方法有2种。 - -- 多个源文件一起编译。编译时需要所有文件重新编译。 - - 示例:将test1.c和tes2.c分别编译后链接成test可执行文件。 - - ``` - gcc test1.c test2.c -o test - ``` - -- 分别编译各个源文件,之后对编译后输出的目标文件链接。编译时只重新编译修改的文件,未修改的文件不用重新编译。 - - 示例:分别编译test1.c,test2.c,在将二者的目标文件test1.o,test2.o链接成test可执行文件。 - - ``` - gcc -c test1.c - gcc -c test2.c - gcc -o test1.o test2.o -o test - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205JDK\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\345\256\211\350\243\205JDK\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 83415410fa8a0d3e3962434ced4baf575891124a..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205JDK\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,45 +0,0 @@ -# 安装JDK软件包 - -1. 执行**dnf list installed | grep jdk** 查询JDK软件是否已安装。 - - ``` - dnf list installed | grep jdk - ``` - - 查看命令打印信息,若打印信息中包含“jdk”,表示该软件已经安装了,则不需要再安装。若无任何打印信息,则表示该软件未安装。 - -2. 清除缓存。 - - ``` - dnf clean all - ``` - -3. 创建缓存。 - - ``` - dnf makecache - ``` - -4. 查询可安装的JDK软件包。 - - ``` - dnf search jdk | grep jdk - ``` - - 查看命令打印信息,选择安装java-x.x.x-openjdk-devel.aarch64软件包。其中x.x.x为版本号。 - -5. 安装JDK软件包,以安装java-1.8.0-openjdk-devel软件包为例。 - - ``` - dnf install java-1.8.0-openjdk-devel.aarch64 - ``` - -6. 查询JDK软件版本。 - - ``` - java -version - ``` - - 查看打印信息,若打印信息中包括“openjdk version "1.8.0\_232"”信息,表示已正确安装,其中1.8.0\_232为版本号。 - - diff --git "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205rpm-build\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\345\256\211\350\243\205rpm-build\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 02d607d904ff8883f16349911dbe79f7af3ca967..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205rpm-build\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,35 +0,0 @@ -# 安装rpm-build软件包 - -1. 执行**dnf list installed | grep rpm-build** 查询rpm-build软件是否已安装。 - - ``` - dnf list installed | grep rpm-build - ``` - - 查看命令打印信息,若打印信息中包含“rpm-build”,表示该软件已经安装了,则不需要再安装。若无任何打印信息,则表示该软件未安装。 - -2. 清除缓存。 - - ``` - dnf clean all - ``` - -3. 创建缓存。 - - ``` - dnf makecache - ``` - -4. 安装rpm-build软件包。 - - ``` - dnf install rpm-build - ``` - -5. 查询rpm-build软件版本。 - - ``` - rpmbuild --version - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205\345\271\266\351\205\215\347\275\256osc.md" "b/content/zh/docs/ApplicationDev/\345\256\211\350\243\205\345\271\266\351\205\215\347\275\256osc.md" deleted file mode 100644 index 6abd6a702890ead57f16748f2d7b6b4ccf78b60f..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205\345\271\266\351\205\215\347\275\256osc.md" +++ /dev/null @@ -1,43 +0,0 @@ -# 安装并配置osc - -## 前提条件 - -需要root权限,已设置openEuler的repo软件源。 - -## 操作步骤 - -1. 使用root用户安装osc命令行工具及依赖。 - - ``` - # dnf install osc build - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >编译RPM软件包的过程中会依赖build。 - -2. 配置osc。 - 1. 打开\~/.oscrc,命令如下: - - ``` - # vi ~/.oscrc - ``` - - 2. 在\~/.oscrc中添加user和pass字段,如下所示,它们的取值 _userName_ _和_ _passWord_ 分别是用户在OBS网页([http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/))上已经注册的账号和密码。 - - ``` - [general] - apiurl = http://openeuler-build.huawei.com/ - no_verify = 1 - [http://openeuler-build.huawei.com/] - user=userName - pass=passWord - ``` - - 3. 如果域名openeuler-build.openeuler.org无法解析,则可以在/etc/hosts文件中手动添加如下一行。其中, _ip-address_ 是obs的ip地址,为http://117.78.1.88/。 - - ``` - ip-address openeuler-build.openeuler.org - ``` - - - diff --git "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\345\256\211\350\243\205\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 7bff722b1e381afeef4a28ecd5968edaf0aa1bd1..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\256\211\350\243\205\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,5 +0,0 @@ -# 安装软件包 - -安装开发过程中需要用到的软件。不同的开发需要的软件不一样,但安装方法相同,本章以安装常用的几个软件包(JDK,rpm-build)为例。有些开发软件openEuler操作系统已默认自带,如GCC、GNU make。 - - diff --git "a/content/zh/docs/ApplicationDev/\345\272\223.md" "b/content/zh/docs/ApplicationDev/\345\272\223.md" deleted file mode 100644 index e1f1a9a4e33a2287bfc378e22c850c2dc7bf9441..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\345\272\223.md" +++ /dev/null @@ -1,25 +0,0 @@ -# 库 - -库是写好的、现有的、成熟的、可以复用的代码。每个程序都要依赖很多基础的底层库。 - -库文件在命名时约定,以lib为前缀,以.so(动态库)或.a(静态库)为后缀,中间为库文件名。如libfoo.so或libfoo.a。由于所有的库文件都遵循了同样的规范,因此当在链接库时,-l 选项指定链接的库文件名时可以省去lib前缀,即GCC 在对-lfoo 进行处理时,会自动去链接名为libfoo.so 或libfoo.a的库文件。而当在创建库时,必须指定完整文件名libfoo.so或libfoo.a。 - -根据链接时期的不同,库分为静态库和动态库。静态库是在链接阶段,将汇编生成的目标文件.o与引用到的库一起链接打包到可执行文件中;而动态库是在程序编译时并不会被链接到目标代码中,而是在程序运行时才被载入。二者有如下差异。 - -- 资源利用不一样。 - - 静态库为生成的可执行文件的一部分,而动态库为单独的文件。所以使用静态库和和动态库的可执行文件大小和占用的磁盘空间大小不一样,导致资源利用不一样。 - -- 扩展性与兼容性不一样 - - 静态库中某个函数的实现变了,那么可执行文件必须重新编译,而对于动态链接生成的可执行文件,只需要更新动态库本身即可,不需要重新编译可执行文件。 - -- 依赖不一样 - - 静态库的可执行文件不需要依赖其他的内容即可运行,而动态库的可执行文件必须依赖动态库的存在。所以静态库更方便移植。 - -- 加载速度不一样 - - 静态库在链接时就和可执行文件在一块了,而动态库在加载或者运行时才链接,因此,对于同样的程序,静态链接的要比动态链接加载更快。 - - diff --git "a/content/zh/docs/ApplicationDev/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" "b/content/zh/docs/ApplicationDev/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" index 17d7e9f0d6f846961bf1feda22c0874200be9574..141b209c3c6aef4cf24e0640d9c308ad203b2352 100644 --- "a/content/zh/docs/ApplicationDev/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" +++ "b/content/zh/docs/ApplicationDev/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.md" @@ -1,3 +1,462 @@ -# 开发环境准备 +# 开发环境准备 + +- [开发环境准备](#开发环境准备) + - [环境要求](#环境要求) + - [操作系统要求](#操作系统要求) + - [配置repo源](#配置repo源) + - [通过直接获取repo源文件的方式配置repo源](#通过直接获取repo源文件的方式配置repo源) + - [通过挂载ISO的方式配置repo源](#通过挂载iso的方式配置repo源) + - [安装软件包](#安装软件包) + - [安装JDK软件包](#安装jdk软件包) + - [安装rpm-build软件包](#安装rpm-build软件包) + - [使用IDE进行Java开发](#使用ide进行java开发) + - [简介](#简介) + - [使用MobaXterm登录服务器](#使用mobaxterm登录服务器) + - [设置JDK环境](#设置jdk环境) + - [下载安装GTK库](#下载安装gtk库) + - [设置X11 Forwarding](#设置x11-forwarding) + - [下载并运行IntelliJ IDEA](#下载并运行intellij-idea) + + +## 环境要求 + +- 若使用的是物理机,则开发环境所需的最小硬件要求如[表1](#table154419352610)所示。 + + **表 1** 最小硬件要求 + + + + + + + + + + + + + + + + + + + + + + + + +

部件名称

+

最小硬件要求

+

说明

+

架构

+
  • AArch64
  • x86_64
+
  • 支持Arm的64位架构。
  • 支持Intel的x86 64位架构。
+

CPU

+
  • 华为鲲鹏920系列CPU
  • Intel® Xeon®处理器
+

-

+

内存

+

不小于4GB(为了获得更好的应用体验,建议不小于8GB)

+

-

+

硬盘

+

为了获得更好的应用体验,建议不小于120GB)

+

支持IDE、SATA、SAS等接口的硬盘。

+
+ +- 若使用的是虚拟机,则开发环境所需的小虚拟化空间要求如[表2](#table780410493819)所示。 + + **表 2** 最小虚拟化空间要求 + + + + + + + + + + + + + + + + + + + + + + + + +

部件名称

+

最小虚拟化空间要求

+

说明

+

架构

+
  • AArch64
  • x86_64
+

-

+

CPU

+

2个CPU

+

-

+

内存

+

不小于4GB(为了获得更好的应用体验,建议不小于8GB)

+

-

+

硬盘

+

不小于32GB(为了获得更好的应用体验,建议不小于120GB)

+

-

+
+ + +### 操作系统要求 + +操作系统要求为openEuler操作系统。 + +openEuler操作系统具体安装方法请参考《openEuler 20.03 LTS 安装指南》,其中“软件选择”页面的“已选环境的附加选项”中将“开发工具”勾选。 + +## 配置repo源 + +可以通过直接获取repo源文件的方式配置repo源或通过挂载ISO的方式配置repo源。 + +### 通过直接获取repo源文件的方式配置repo源 + +>![](public_sys-resources/icon-note.gif) **说明:** +>openEuler提供了多种repo源文件,本操作以AArch64架构的OS repo源文件为例。 + +1. 进入到yum源目录。 + + ``` + cd /etc/yum.repos.d + ``` + +2. 新建local.repo文件并编辑local.repo,将repo源文件配置为yum源。 + + ``` + vi local.repo + ``` + + 编辑local.repo文件的内容如下: + + \[basiclocal\] + + name=basiclocal + + baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/OS/aarch64/ + + enabled=1 + + gpgcheck=0 + + +### 通过挂载ISO的方式配置repo源 + +>![](public_sys-resources/icon-note.gif) **说明:** +>本操作以openEuler-20.03-LTS-aarch64-dvd.iso镜像文件和openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum校验文件为例,请根据实际需要的镜像文件和校验文件进行修改。 + +1. 下载ISO镜像。 + - 通过跨平台文件传输工具下载ISO镜像 + 1. 登录openEuler社区,网址为:[https://openeuler.org](https://openeuler.org)。 + 2. 单击“下载”,进入下载页面。 + 3. 单击“获取ISO:”后面的“Link”,显示版本列表。 + 4. 选择需要下载的版本,如openEuler 20.03 LTS,则单击“openEuler-20.03-LTS”,进入下载列表。 + 5. 单击“ISO”,进入ISO下载列表。 + - aarch64:AArch64架构的ISO。 + - x86\_64:x86\_64架构的ISO。 + - source:openEuler源码ISO。 + + 6. 单击“aarch64”。 + 7. 单击“openEuler-20.03-LTS-aarch64-dvd.iso”,将openEuler发布包下载到本地。 + 8. 单击“openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum”,将openEuler校验文件下载到本地。 + 9. 登录openEuler操作系统,新建用于存放发布包和检验文件的目录,如“/home/iso”。 + + ``` + mkdir /home/iso + ``` + + 10. 使用跨平台文件传输工具(如WinSCP)将本地的openEuler发布包和校验文件上传到openEuler操作系统。 + + - 通过wget命令下载ISO镜像。 + 1. 登录openEuler社区,网址为:[https://openeuler.org](https://openeuler.org)。 + 2. 单击“下载”,进入下载页面。 + 3. 单击“获取ISO:”后面的“Link”,显示版本列表。 + 4. 选择需要下载的版本,如openEuler 20.03 LTS,则单击“openEuler-20.03-LTS”,进入下载列表。 + 5. 单击“ISO”,进入ISO下载列表。 + - aarch64:AArch64架构的ISO。 + - x86\_64:x86\_64架构的ISO。 + - source:openEuler源码ISO。 + + 6. 单击“aarch64”。 + 7. 右键单击“openEuler-20.03-LTS-aarch64-dvd.iso”,单击“复制链接地址”,将openEuler发布包地址记录好。 + 8. 右键单击“openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum”,单击“复制链接地址”,将openEuler校验文件地址记录好。 + 9. 登录openEuler操作系统,新建用于存放发布包和检验文件的目录,如“/home/iso”,并切换到该目录。 + + ``` + mkdir /home/iso + cd /home/iso + ``` + + 10. 使用**wget**命令远程下载发布包和检验文件,命令中的 _ipaddriso_ 和 _ipaddrisosum_ 分别为[1.g](#li62369349505)和[1.h](#li9236203405015)中记录的地址。 + + ``` + wget ipaddriso + wget ipaddrisosum + ``` + + +2. 发布包完整性校验。 + 1. 获取校验文件中的校验值。 + + ``` + cat openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum + ``` + + 2. 计算openEuler发布包的sha256校验值。 + + ``` + sha256sum openEuler-20.03-LTS-aarch64-dvd.iso + ``` + + 命令执行完成后,输出校验值。 + + 3. 对比步骤1和步骤2计算的校验值是否一致。 + + 如果校验值一致说明iso文件完整性没有破坏,如果校验值不一致则可以确认文件完整性已被破坏,需要重新获取。 + +3. 挂载ISO并配置为repo源。 + + 使用mount命令挂载镜像文件。 + + 示例如下: + + ``` + # mount /home/iso/openEuler-20.03-LTS-aarch64-dvd.iso /mnt/ + ``` + + 挂载好的mnt目录如下: + + ``` + . + │── boot.catalog + │── docs + │── EFI + │── images + │── Packages + │── repodata + │── TRANS.TBL + └── RPM-GPG-KEY-openEuler + ``` + + 其中,Packages为rpm包所在的目录,repodata为repo源元数据所在的目录,RPM-GPG-KEY-openEuler为openEuler的签名公钥。。 + + 挂载后的目录可以配置为yum源使用,在/etc/yum.repos.d/目录下创建\*\*\*.repo的配置文件(必须以.repo为扩展名)。 + + 示例如下: + + 在/etc/yum.repos.d目录下创建openEuler.repo 文件,使用本地镜像挂载目录作为yum源,openEuler.repo的内容如下: + + ``` + [base] + name=base + baseurl=file:///mnt + enabled=1 + gpgcheck=1 + gpgkey=file:///mnt/RPM-GPG-KEY-openEuler + ``` + + **** + + >![](public_sys-resources/icon-note.gif) **说明:** + >- gpgcheck可设置为1或0,1表示进行gpg(GNU Private Guard)校验,0表示不进行gpg校验,gpgcheck可以确定rpm包的来源是有效和安全的。 + >- gpgkey为签名公钥的存放路径。 + + +## 安装软件包 + +安装开发过程中需要用到的软件。不同的开发需要的软件不一样,但安装方法相同,本章以安装常用的几个软件包(JDK,rpm-build)为例。有些开发软件openEuler操作系统已默认自带,如GCC、GNU make。 + + +### 安装JDK软件包 + +1. 执行**dnf list installed | grep jdk** 查询JDK软件是否已安装。 + + ``` + dnf list installed | grep jdk + ``` + + 查看命令打印信息,若打印信息中包含“jdk”,表示该软件已经安装了,则不需要再安装。若无任何打印信息,则表示该软件未安装。 + +2. 清除缓存。 + + ``` + dnf clean all + ``` + +3. 创建缓存。 + + ``` + dnf makecache + ``` + +4. 查询可安装的JDK软件包。 + + ``` + dnf search jdk | grep jdk + ``` + + 查看命令打印信息,选择安装java-x.x.x-openjdk-devel.aarch64软件包。其中x.x.x为版本号。 + +5. 安装JDK软件包,以安装java-1.8.0-openjdk-devel软件包为例。 + + ``` + dnf install java-1.8.0-openjdk-devel.aarch64 + ``` + +6. 查询JDK软件版本。 + + ``` + java -version + ``` + + 查看打印信息,若打印信息中包括“openjdk version "1.8.0\_232"”信息,表示已正确安装,其中1.8.0\_232为版本号。 + + +### 安装rpm-build软件包 + +1. 执行**dnf list installed | grep rpm-build** 查询rpm-build软件是否已安装。 + + ``` + dnf list installed | grep rpm-build + ``` + + 查看命令打印信息,若打印信息中包含“rpm-build”,表示该软件已经安装了,则不需要再安装。若无任何打印信息,则表示该软件未安装。 + +2. 清除缓存。 + + ``` + dnf clean all + ``` + +3. 创建缓存。 + + ``` + dnf makecache + ``` + +4. 安装rpm-build软件包。 + + ``` + dnf install rpm-build + ``` + +5. 查询rpm-build软件版本。 + + ``` + rpmbuild --version + ``` + + +## 使用IDE进行Java开发 + +对于小型的Java程序,可以直接参考“使用JDK编译”章节得到可运行Java应用。但是对于大中型Java应用,这种方式已经无法满足开发者的需求。因此您可以参考如下步骤安装IDE并进行使用,以方便您在openEuler系统上的Java开发工作。 + + + +### 简介 + +IntelliJ IDEA是一款非常流行的Java IDE,其社区版可以免费下载使用。目前openEuler支持使用IntelliJ IDEA集成开发环境(IDE)进行Java程序的开发,从而可以提升开发人员的工作效率。 + +### 使用MobaXterm登录服务器 + +MobaXterm是一款非常优秀的SSH客户端,其自带X Server,可以轻松解决远程GUI显示问题。 + +您需要提前下载安装好MobaXterm并打开,然后SSH登录您的服务器并进行以下操作。 + +### 设置JDK环境 + +在设置JAVA\_HOME之前您需要先找到JDK的安装路径。在“开发环境准备 \> 安装软件包 \> 安装JDK软件包”章节中您已经学会了如何安装JDK,如果您还没安装好JDK,请提前安好。 + +查看java路径,命令如下: + +``` +# which java +/usr/bin/java +``` + +查看软链接的实际指向目录,命令如下: + +``` +# ls -la /usr/bin/java +lrwxrwxrwx. 1 root root 22 Mar 6 20:28 /usr/bin/java -> /etc/alternatives/java +# ls -la /etc/alternatives/java +lrwxrwxrwx. 1 root root 83 Mar 6 20:28 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64/jre/bin/java +``` + +发现JDK的真实路径为/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64,设置JAVA\_HOME和PATH,命令如下: + +``` +# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64 +# export PATH=$JAVA_HOME/bin:$PATH +``` + +### 下载安装GTK库 + +请确认您具有root权限后,运行如下命令: + +``` +# dnf list installed | grep gtk +``` + +如果显示gtk2或者gtk3,则表示您已安装该库,可以直接跳过进入下一步,否则运行如下命令自动下载安装gtk库。 + +``` +# dnf -y install gtk2 libXtst libXrender xauth +``` + +### 设置X11 Forwarding + +切换到sshd配置目录 + +``` +# cd ~/.ssh +``` + +如果该目录不存在,则创建目录后再进行切换,创建目录命令如下: + +``` +# mkdir ~/.ssh +``` + +然后在.ssh目录下编辑config文件并保存: + +1. 使用vim打卡config文件 + + ``` + # vim config + ``` + +2. 将以下内容添加到文件末尾并保存: + + ``` + Host * + ForwardAgent yes + ForwardX11 yes + ``` + + +### 下载并运行IntelliJ IDEA + +在执行如上环境配置后,您就可以下载使用IntelliJ IDEA了。鉴于最新版的IntelliJ IDEA和openEuler系统在部分功能上有兼容性问题,建议您从此[链接](https://www.jetbrains.com/idea/download/other.html)下载2018版本linux压缩包。下载好后把压缩包移到您想要安装该软件的目录,对压缩包进行解压: + +``` +# tar xf ideaIC-2018.3.tar.gz +``` + +解压后切换到IntelliJ IDEA的目录下并运行。 + +``` +# cd ./idea-IC-183.4284.148 +# bin/idea.sh & +``` diff --git "a/content/zh/docs/ApplicationDev/\346\211\223\345\214\205\350\257\264\346\230\216.md" "b/content/zh/docs/ApplicationDev/\346\211\223\345\214\205\350\257\264\346\230\216.md" deleted file mode 100644 index f7184bbbf2a04c615f14e6bc0af191f7bbdd4512..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\211\223\345\214\205\350\257\264\346\230\216.md" +++ /dev/null @@ -1,342 +0,0 @@ -# 打包说明 - -## 原理介绍 - -RPM打包的时候需要编译源码,需要把编译好的配置文件、二进制命令文件等放到合适的位置,还要根据需要对RPM的包进行测试,这些都需要先有一个“工作空间”。rpmbuild命令使用一套标准化的“工作空间”: - -``` -# rpmdev-setuptree -``` - -rpmdev-setuptree这个命令就是安装 rpmdevtools 带来的。可以看到运行了这个命令之后,在“/root“目录(非root用户为“/home/用户名“目录)下多了一个 rpmbuild 的文件夹,目录结构如下: - -``` -# tree rpmbuild -rpmbuild -├── BUILD -├── RPMS -├── SOURCES -├── SPECS -└── SRPMS -``` - -内容相关的说明如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

目录

-

宏代码

-

名称

-

功能

-

~/rpmbuild/BUILD

-

%_builddir

-

构建目录

-

源码包被解压至此,并在该目录的子目录完成编译

-

~/rpmbuild/RPMS

-

%_rpmdir

-

标准 RPM 包目录

-

生成/保存二进制 RPM 包

-

~/rpmbuild/SOURCES

-

%_sourcedir

-

源代码目录

-

保存源码包(如 .tar 包)和所有 patch 补丁

-

~/rpmbuild/SPECS

-

%_specdir

-

Spec 文件目录

-

保存 RPM 包配置(.spec)文件

-

~/rpmbuild/SRPMS

-

%_srcrpmdir

-

源代码 RPM 包目录

-

生成/保存源码 RPM 包(SRPM)

-
- -SPECS 下是RPM包的配置文件,是RPM打包的“图纸”,这个文件会告诉rpmbuild命令如何去打包。“宏代码”这一列就可以在SPEC文件中用来代指所对应的目录,类似于编程语言中的宏或全局变量。 - -## 打包流程 - -打包的过程主要分为如下步骤: - -1. 把源代码放到%\_sourcedir中。 -2. 进行编译,编译的过程是在%\_builddir中完成的,一般情况下,源代码是压缩包格式,需要先进行解压。 -3. 进行“安装”,类似于预先组装软件包,把软件包应该包含的内容(比如二进制文件、配置文件、man文档等)复制到%\_buildrootdir中,并按照实际安装后的目录结构组装,比如二进制命令可能会放在/usr/bin下,那么就在%\_buildrootdir下也按照同样的目录结构放置。 -4. 做一些必要的配置,比如在实际安装前的准备,安装后的清理等等。这些都是通过配置在SPEC文件中来告诉rpmbuild命令。 -5. 检查软件是否正常运行。 -6. 生成的RPM包放置到%\_rpmdir,源码包放置到%\_srpmdir下。 - -在SPEC文件中的,各个阶段说明如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

阶段

-

读取的目录

-

写入的目录

-

具体动作

-

%prep

-

%_sourcedir

-

%_builddir

-

读取位于 %_sourcedir 目录的源代码和 patch 。之后,解压源代码至 %_builddir 的子目录并应用所有 patch

-

%build

-

%_builddir

-

%_builddir

-

编译位于 %_builddir 构建目录下的文件。通过执行类似 ./configure && make 的命令实现。

-

%install

-

%_builddir

-

%_buildrootdir

-

读取位于 %_builddir 构建目录下的文件并将其安装至 %_buildrootdir 目录。这些文件就是用户安装 RPM 后,最终得到的文件。

-

%check

-

%_builddir

-

%_builddir

-

检查软件是否正常运行。通过执行类似 make test 的命令实现。

-

bin

-

%_buildrootdir

-

%_rpmdir

-

读取位于 %_buildrootdir 最终安装目录下的文件,以便最终在 %_rpmdir 目录下创建 RPM 包。在该目录下,不同架构的 RPM 包会分别保存至不同子目录, noarch 目录保存适用于所有架构的 RPM 包。这些 RPM 文件就是用户最终安装的 RPM 包。

-

src

-

%_sourcedir

-

%_srcrpmdir

-

创建源码 RPM 包(简称 SRPM,以.src.rpm 作为后缀名),并保存至 %_srcrpmdir 目录。SRPM 包通常用于审核和升级软件包。

-
- -## 打包选项 - -通过rpmbuild命令构建软件包。rpmbuild构建软件包一般可以通过构建SPEC文件、tar文件、source文件实现。 - -rpmbuild命令格式为:rpmbuild \[_option_...\] - -常用的rpmbuild打包选项如[表1](#table1342946175212)所示。 - -**表 1** rpmbuild打包选项 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

option取值

-

说明

-

-bp specfile

-

specfile文件的%prep段开始构建(解开源码包并打补丁)。

-

-bc specfile

-

specfile文件的%build段开始构建。

-

-bi specfile

-

specfile文件的%install段开始构建。

-

-bl specfile

-

specfile文件的%file段开始检查。

-

-ba specfile

-

通过specfile文件构建源码包和二进制包。

-

-bb specfile

-

通过specfile文件构建二进制包

-

-bs specfile

-

通过specfile文件构建源码包。

-

-rp sourcefile

-

sourcefile文件的%prep段开始构建(解开源码包并打补丁)。

-

-rc sourcefile

-

sourcefile文件的%build段开始构建。

-

-ri sourcefile

-

sourcefile文件的%install段开始构建。

-

-rl sourcefile

-

sourcefile文件的%file段开始检查。

-

-ra sourcefile

-

通过sourcefile文件构建源码包和二进制包。

-

-rb sourcefile

-

通过sourcefile文件构建二进制包

-

-rs sourcefile

-

通过sourcefile文件构建源码包。

-

-tp tarfile

-

tarfile文件的%prep段开始构建(解开源码包并打补丁)。

-

-tc tarfile

-

tarfile文件的%build段开始构建。

-

-ti tarfile

-

tarfile文件的%install段开始构建。

-

-ta tarfile

-

通过tarfile文件构建源码包和二进制包。

-

-tb tarfile

-

通过tarfile文件构建二进制包

-

-ts tarfile

-

通过tarfile文件构建源码包。

-

--buildroot=DIRECTORY

-

在构建时,使用DIRECTORY目录覆盖默认的/root目录。

-

--clean

-

完成打包后清除BUILD目录下的文件。

-

--nobuild

-

不执行任何实际的构建步骤。可用于测试spec文件。

-

--noclean

-

不执行spec文件的"%clean"阶段(即使它确实存在)。

-

--nocheck

-

不执行spec文件的"%check"阶段(即使它确实存在)。

-

--dbpath DIRECTORY

-

使用DIRECTORY中的数据库,而不是默认的 /var/lib/rpm。

-

--root DIRECTORY

-

使DIRECTORY为最高级别的路径,默认为“/”为最高路径。

-

--rebuild sourcefile

-

将安装指定的源代码包sourcefile,然后进行准备、编译、安装。

-

--recompile sourcefile

-

在 --recompile 的基础上额外构建一个新的二进制包。在构建结束时,构建目录、源代码和 spec 文件都将被删除。

-

将被删除(就好像用了 --clean),

-

-?,--help

-

打印详细的帮助信息。

-

--version

-

打印详细的版本信息。

-
- diff --git "a/content/zh/docs/ApplicationDev/\346\220\255\345\273\272\345\274\200\345\217\221\347\216\257\345\242\203.md" "b/content/zh/docs/ApplicationDev/\346\220\255\345\273\272\345\274\200\345\217\221\347\216\257\345\242\203.md" deleted file mode 100644 index 80130d91a95c22c5e8c976f813e6b237dfe80058..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\220\255\345\273\272\345\274\200\345\217\221\347\216\257\345\242\203.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 搭建开发环境 - -## 前提条件 - -需要root权限,已设置openEuler的repo软件源。 - -## 操作步骤 - -用户可以直接使用DNF工具安装 rpmdevtools,其中包含 rpm-build 等命令以及相关依赖(例如make、gdb)。使用如下命令: - -``` -# dnf install rpmdevtools* -``` - diff --git "a/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213-3.md" "b/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213-3.md" deleted file mode 100644 index 3bf54dd95a5fd4c3eaab7e0284bb806a8c76f45a..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213-3.md" +++ /dev/null @@ -1,76 +0,0 @@ -# 文件类型 - -makefile文件中可能用到的文件类型如[表1](#table634145764320)所示。 - -**表 1** 文件类型 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

扩展名(后缀)

-

说明

-

.c

-

C语言源代码文件。

-

.C,.cc或.cxx

-

C++源代码文件。

-

.m

-

Objective-C源代码文件。

-

.s

-

汇编语言源代码文件。

-

.i

-

已经预处理的C源代码文件。

-

.ii

-

已经预处理的C++源代码文件。

-

.S

-

已经预处理的汇编语言源代码文件。

-

.h

-

程序所包含的头文件。

-

.o

-

编译后的目标文件。

-

.so

-

动态链接库,它是一种特殊的目标文件。

-

.a

-

静态链接库。

-

.out

-

可执行文件,但可执行文件没有统一的后缀,系统从文件的属性来区分可执行文件和不可执行文件。如果没有给出可执行文件的名字,GCC将生成一个名为a.out的文件。

-
- diff --git "a/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213.md" "b/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213.md" deleted file mode 100644 index dbd2c3205121459189e0470bc94a85f1acf847c3..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213.md" +++ /dev/null @@ -1,76 +0,0 @@ -# 文件类型 - -对于任何给定的输入文件,文件类型决定进行何种编译。GCC常用的文件类型如[表1](#table634145764320)所示。 - -**表 1** GCC常用的文件类型 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

扩展名(后缀)

-

说明

-

.c

-

C语言源代码文件。

-

.C,.cc或.cxx

-

C++源代码文件。

-

.m

-

Objective-C源代码文件。

-

.s

-

汇编语言源代码文件。

-

.i

-

已经预处理的C源代码文件。

-

.ii

-

已经预处理的C++源代码文件。

-

.S

-

已经预处理的汇编语言源代码文件。

-

.h

-

程序所包含的头文件。

-

.o

-

编译后的目标文件。

-

.so

-

动态链接库,它是一种特殊的目标文件。

-

.a

-

静态链接库。

-

.out

-

可执行文件,但可执行文件没有统一的后缀,系统从文件的属性来区分可执行文件和不可执行文件。如果没有给出可执行文件的名字,GCC将生成一个名为a.out的文件。

-
- diff --git "a/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213\345\217\212\345\267\245\345\205\267.md" "b/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213\345\217\212\345\267\245\345\205\267.md" deleted file mode 100644 index b4b2ae5e2c24abae948182f7d389253089a46f6c..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\226\207\344\273\266\347\261\273\345\236\213\345\217\212\345\267\245\345\205\267.md" +++ /dev/null @@ -1,58 +0,0 @@ -# 文件类型及工具 - -对于任何给定的输入文件,文件类型决定采用何种工具进行处理。JDK常用的文件类型如[表1](#table634145764320)所示,JDK常用的工具如[表2](#table103504146433)所示。 - -**表 1** JDK常用的文件类型 - - - - - - - - - - - - - - - - -

扩展名(后缀)

-

说明

-

.java

-

java语言源代码文件。

-

.class

-

java的字节码文件,是一种和任何具体机器环境及操作系统环境无关的中间代码。它是一种二进制文件,是Java 源文件由 Java 编译器编译后生成的目标代码文件。

-

.jar

-

java的jar压缩文件。

-
- -**表 2** JDK常用的工具 - - - - - - - - - - - - - - - - -

工具名称

-

说明

-

java

-

Java运行工具,用于运行.class字节码文件或.jar文件。

-

javac

-

Java编程语言的编译器,将.java的源代码文件编译成.class的字节码文件。

-

jar

-

创建和管理Jar文件

-
- diff --git "a/content/zh/docs/ApplicationDev/\346\226\260\345\242\236\350\275\257\344\273\266\345\214\205-10.md" "b/content/zh/docs/ApplicationDev/\346\226\260\345\242\236\350\275\257\344\273\266\345\214\205-10.md" deleted file mode 100644 index 315b482f185817918c532ef1462c8591366c7556..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\226\260\345\242\236\350\275\257\344\273\266\345\214\205-10.md" +++ /dev/null @@ -1,56 +0,0 @@ -# 新增软件包 - -使用OBS的osc工具新增一个全新软件包的操作方法如下: - -**创建工程** - -1. 根据新增软件包的依赖情况,基于合适的工程,创建属于用户自己的个人工程。例如基于 _openEuler:Mainline_ 工程的 zlib 创建工程的参考命令如下,zlib 为工程下的任一软件包。 - - ``` - # osc branch openEuler:Mainline zlib - ``` - -2. 删除创建工程时新增的无用软件包。例如删除zlib软件包的参考命令如下: - - ``` - # cd home:testUser:branches:openEuler:Mainline - # osc rm zlib - # osc commit -m "commit log" - ``` - -3. 在个人工程下创建新增的软件包。例如新增软件包 my-first-obs-package命令如下: - - ``` - # mkdir my-first-obs-package - # cd my-first-obs-package - ``` - - -**构建RPM包** - -1. 添加准备的源文件和spec文件到软件包目录。 -2. 修改源代码和spec文件,并将对应软件包的所有文件上传到OBS服务器。参考命令如下,-m 参数后的信息为提交记录。 - - ``` - # cd home:testUser:branches:openEuler:Mainline - # osc add my-first-obs-package - # osc ci -m "commit log" - ``` - -3. 获取当前工程的仓库名称和架构,参考命令如下: - - ``` - # osc repos home:testUser:branches:openEuler:Mainline - ``` - -4. 修改提交成功后,OBS会自动开始编译软件包。可以通过如下命令,查看对应仓库的编译日志,其中_standard\_aarch64 、aarch64_分别为查询所得仓库名称和架构。 - - ``` - # cd home:testUser:branches:openEuler:Mainline/my-first-obs-package - # osc buildlog standard_aarch64 aarch64 - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >用户也可以通过网页端打开自己创建的对应工程,查看构建日志。 - - diff --git "a/content/zh/docs/ApplicationDev/\346\226\260\345\242\236\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\346\226\260\345\242\236\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 0d5d0a53497c2e2a2538b51e165a106397699e76..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\226\260\345\242\236\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,37 +0,0 @@ -# 新增软件包 - -使用OBS网页端,新增一个全新软件包的操作方法如下: - -1. 登录OBS界面。 -2. 根据新增软件包的依赖情况,选择合适的工程,即单击“All Projects”选择对应工程,例如“openEuler:Mainline”。 -3. 单击工程下任一软件包,进入该软件包的详情页面。 -4. 单击“Branch package”,在弹出的确认页面单击“Accept”确认创建子工程。 -5. 单击“Delete package”,删除新创建子工程中的软件包,如[图1](#fig18306181103615)所示。 - - **图 1** 删除子工程中软件包 - ![](figures/删除子工程中软件包.png "删除子工程中软件包") - - >![](public_sys-resources/icon-note.gif) **说明:** - >通过已有软件创建新工程是为了继承环境等依赖,而不需要实际的文件,所以这里需要把这些文件删除。 - -6. 单击“Create Package”,在弹出的页面输入软件包名称、标题和软件包描述,然后单击“Create”创建软件包,分别如[图2](#fig6762111693811)、[图3](#fig18351153518389)所示。 - - **图 2** Create Package页面 - ![](figures/Create-Package页面.png "Create-Package页面") - - **图 3** 创建软件包信息填写页面 - ![](figures/创建软件包信息填写页面.png "创建软件包信息填写页面") - -7. 在页面中单击“Add file”上传spec文件和需要编译的文件(在spec文件中指定),如[图4](#fig1475845284011)所示。 - - **图 4** Add file页面 - ![](figures/Add-file页面.png "Add-file页面") - -8. 文件上传成功后,OBS会自动开始构建RPM软件包。等待构建完成,并查看右侧状态栏的构建状态。 - - succeed:构建成功。用户可以单击“succeeded”查看构建日志。 - - failed:构建失败。请单击“failed”查看错误日志进行问题定位后重新构建。 - - unresolvable:未进行构建,可能由于缺失依赖。 - - disabled:构建被手动关闭或正在排队构建。 - - excluded:构建被禁止,可能由于缺少spec文件或者spec文件中禁止了目标架构的编译。 - - diff --git "a/content/zh/docs/ApplicationDev/\346\234\254\345\234\260\346\236\204\345\273\272.md" "b/content/zh/docs/ApplicationDev/\346\234\254\345\234\260\346\236\204\345\273\272.md" deleted file mode 100644 index 76cdda73e5a3194914bebb45c18432e4ec39f6c4..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\234\254\345\234\260\346\236\204\345\273\272.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 本地构建 - -本章通过一个简单的示例介绍如何在本地构建RPM软件包的方法。 - - - diff --git "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205-8.md" "b/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205-8.md" deleted file mode 100644 index 62da72928ba3839e6bf1e6b5dcb92c2ca54b2398..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205-8.md" +++ /dev/null @@ -1,22 +0,0 @@ -# 构建RPM包 - -构建源码、二进制和包含调试信息的软件包,在spec文件所在目录执行如下命令: - -``` -# rpmbuild -ba hello.spec -``` - -执行成功后,查看结果,使用如下命令: - -``` -# tree ~/rpmbuild/*RPMS - -/home/testUser/rpmbuild/RPMS -└── aarch64 - ├── hello-2.10-1.aarch64.rpm - ├── hello-debuginfo-2.10-1.aarch64.rpm - └── hello-debugsource-2.10-1.aarch64.rpm -/home/testUser/rpmbuild/SRPMS -└── hello-2.10-1.src.rpm -``` - diff --git "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205.md" "b/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205.md" index a8bc34a88edc1e14c12652725d23cdbc437bf82a..6518e0def9388cfe6dc423ffd7b972086a6d9ec2 100644 --- "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205.md" +++ "b/content/zh/docs/ApplicationDev/\346\236\204\345\273\272RPM\345\214\205.md" @@ -1,5 +1,808 @@ -# 构建RPM包 +# 构建RPM包 本章介绍通过本地或OBS构建RPM软件包的方法。详见[打包规则](https://gitee.com/openeuler/community/blob/master/zh/contributors/packaging.md)。 + +- [构建RPM包](#构建rpm包) + - [打包说明](#打包说明) + - [原理介绍](#原理介绍) + - [打包流程](#打包流程) + - [打包选项](#打包选项) + - [本地构建](#本地构建) + - [搭建开发环境](#搭建开发环境) + - [创建Hello World RPM包](#创建hello-world-rpm包) + - [使用OBS构建](#使用obs构建) + - [OBS简介](#obs简介) + - [在线构建软件包](#在线构建软件包) + - [使用osc构建软件包](#使用osc构建软件包) + + +## 打包说明 + +### 原理介绍 +RPM打包的时候需要编译源码,需要把编译好的配置文件、二进制命令文件等放到合适的位置,还要根据需要对RPM的包进行测试,这些都需要先有一个“工作空间”。rpmbuild命令使用一套标准化的“工作空间”: + +``` +# rpmdev-setuptree +``` + +rpmdev-setuptree这个命令就是安装 rpmdevtools 带来的。可以看到运行了这个命令之后,在“/root“目录(非root用户为“/home/用户名“目录)下多了一个 rpmbuild 的文件夹,目录结构如下: + +``` +# tree rpmbuild +rpmbuild +├── BUILD +├── RPMS +├── SOURCES +├── SPECS +└── SRPMS +``` + +内容相关的说明如下: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

目录

+

宏代码

+

名称

+

功能

+

~/rpmbuild/BUILD

+

%_builddir

+

构建目录

+

源码包被解压至此,并在该目录的子目录完成编译

+

~/rpmbuild/RPMS

+

%_rpmdir

+

标准 RPM 包目录

+

生成/保存二进制 RPM 包

+

~/rpmbuild/SOURCES

+

%_sourcedir

+

源代码目录

+

保存源码包(如 .tar 包)和所有 patch 补丁

+

~/rpmbuild/SPECS

+

%_specdir

+

Spec 文件目录

+

保存 RPM 包配置(.spec)文件

+

~/rpmbuild/SRPMS

+

%_srcrpmdir

+

源代码 RPM 包目录

+

生成/保存源码 RPM 包(SRPM)

+
+ +SPECS 下是RPM包的配置文件,是RPM打包的“图纸”,这个文件会告诉rpmbuild命令如何去打包。“宏代码”这一列就可以在SPEC文件中用来代指所对应的目录,类似于编程语言中的宏或全局变量。 + +### 打包流程 +打包的过程主要分为如下步骤: + +1. 把源代码放到%\_sourcedir中。 +2. 进行编译,编译的过程是在%\_builddir中完成的,一般情况下,源代码是压缩包格式,需要先进行解压。 +3. 进行“安装”,类似于预先组装软件包,把软件包应该包含的内容(比如二进制文件、配置文件、man文档等)复制到%\_buildrootdir中,并按照实际安装后的目录结构组装,比如二进制命令可能会放在/usr/bin下,那么就在%\_buildrootdir下也按照同样的目录结构放置。 +4. 做一些必要的配置,比如在实际安装前的准备,安装后的清理等等。这些都是通过配置在SPEC文件中来告诉rpmbuild命令。 +5. 检查软件是否正常运行。 +6. 生成的RPM包放置到%\_rpmdir,源码包放置到%\_srpmdir下。 + +在SPEC文件中的,各个阶段说明如下: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

阶段

+

读取的目录

+

写入的目录

+

具体动作

+

%prep

+

%_sourcedir

+

%_builddir

+

读取位于 %_sourcedir 目录的源代码和 patch 。之后,解压源代码至 %_builddir 的子目录并应用所有 patch

+

%build

+

%_builddir

+

%_builddir

+

编译位于 %_builddir 构建目录下的文件。通过执行类似 ./configure && make 的命令实现。

+

%install

+

%_builddir

+

%_buildrootdir

+

读取位于 %_builddir 构建目录下的文件并将其安装至 %_buildrootdir 目录。这些文件就是用户安装 RPM 后,最终得到的文件。

+

%check

+

%_builddir

+

%_builddir

+

检查软件是否正常运行。通过执行类似 make test 的命令实现。

+

bin

+

%_buildrootdir

+

%_rpmdir

+

读取位于 %_buildrootdir 最终安装目录下的文件,以便最终在 %_rpmdir 目录下创建 RPM 包。在该目录下,不同架构的 RPM 包会分别保存至不同子目录, noarch 目录保存适用于所有架构的 RPM 包。这些 RPM 文件就是用户最终安装的 RPM 包。

+

src

+

%_sourcedir

+

%_srcrpmdir

+

创建源码 RPM 包(简称 SRPM,以.src.rpm 作为后缀名),并保存至 %_srcrpmdir 目录。SRPM 包通常用于审核和升级软件包。

+
+ +### 打包选项 + +通过rpmbuild命令构建软件包。rpmbuild构建软件包一般可以通过构建SPEC文件、tar文件、source文件实现。 + +rpmbuild命令格式为:rpmbuild \[_option_...\] + +常用的rpmbuild打包选项如[表1](#table1342946175212)所示。 + +**表 1** rpmbuild打包选项 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

option取值

+

说明

+

-bp specfile

+

specfile文件的%prep段开始构建(解开源码包并打补丁)。

+

-bc specfile

+

specfile文件的%build段开始构建。

+

-bi specfile

+

specfile文件的%install段开始构建。

+

-bl specfile

+

specfile文件的%file段开始检查。

+

-ba specfile

+

通过specfile文件构建源码包和二进制包。

+

-bb specfile

+

通过specfile文件构建二进制包

+

-bs specfile

+

通过specfile文件构建源码包。

+

-rp sourcefile

+

sourcefile文件的%prep段开始构建(解开源码包并打补丁)。

+

-rc sourcefile

+

sourcefile文件的%build段开始构建。

+

-ri sourcefile

+

sourcefile文件的%install段开始构建。

+

-rl sourcefile

+

sourcefile文件的%file段开始检查。

+

-ra sourcefile

+

通过sourcefile文件构建源码包和二进制包。

+

-rb sourcefile

+

通过sourcefile文件构建二进制包

+

-rs sourcefile

+

通过sourcefile文件构建源码包。

+

-tp tarfile

+

tarfile文件的%prep段开始构建(解开源码包并打补丁)。

+

-tc tarfile

+

tarfile文件的%build段开始构建。

+

-ti tarfile

+

tarfile文件的%install段开始构建。

+

-ta tarfile

+

通过tarfile文件构建源码包和二进制包。

+

-tb tarfile

+

通过tarfile文件构建二进制包

+

-ts tarfile

+

通过tarfile文件构建源码包。

+

\-\-buildroot=DIRECTORY

+

在构建时,使用DIRECTORY目录覆盖默认的/root目录。

+

\-\-clean

+

完成打包后清除BUILD目录下的文件。

+

\-\-nobuild

+

不执行任何实际的构建步骤。可用于测试spec文件。

+

\-\-noclean

+

不执行spec文件的"%clean"阶段(即使它确实存在)。

+

\-\-nocheck

+

不执行spec文件的"%check"阶段(即使它确实存在)。

+

\-\-dbpath DIRECTORY

+

使用DIRECTORY中的数据库,而不是默认的 /var/lib/rpm。

+

\-\-root DIRECTORY

+

使DIRECTORY为最高级别的路径,默认为“/”为最高路径。

+

\-\-rebuild sourcefile

+

将安装指定的源代码包sourcefile,然后进行准备、编译、安装。

+

\-\-recompile sourcefile

+

在\-\-recompile 的基础上额外构建一个新的二进制包。在构建结束时,构建目录、源代码和 spec 文件都将被删除。

+

将被删除(就好像用了 \-\-clean),

+

-?,\-\-help

+

打印详细的帮助信息。

+

\-\-version

+

打印详细的版本信息。

+
+ +## 本地构建 + +本章通过一个简单的示例介绍如何在本地构建RPM软件包的方法。 + + + +### 搭建开发环境 + +#### 前提条件 +需要root权限,已设置openEuler的repo软件源。 + +#### 操作步骤 +用户可以直接使用DNF工具安装 rpmdevtools,其中包含 rpm-build 等命令以及相关依赖(例如make、gdb)。使用如下命令: + +``` +# dnf install rpmdevtools* +``` + +### 创建Hello World RPM包 + +这里以GNU“Hello World” 项目的打包过程作为示例,包含了典型的FOSS(Free and Open Source Software) 软件项目相关的最常用的外围组件,其中包括配置/编译/安装环境、文档、国际化等等。 + + +#### 下载源码 + +我们直接下载官方例子的源码,使用如下命令: + +``` +# cd ~/rpmbuild/SOURCES +# wget http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz +``` + +#### 编辑SPEC文件 + +新建spec文件,参考命令如下: + +``` +# vi hello.spec +``` + +在文件中写入对应内容后保存文件。文件内容示例如下,请根据实际情况修改相应字段。 + +``` +Name: hello +Version: 2.10 +Release: 1%{?dist} +Summary: The "Hello World" program from GNU +Summary(zh_CN): GNU "Hello World" 程序 +License: GPLv3+ +URL: http://ftp.gnu.org/gnu/hello +Source0: http://ftp.gnu.org/gnu/hello/%{name}-%{version}.tar.gz + +BuildRequires: gettext +Requires(post): info +Requires(preun): info + +%description +The "Hello World" program, done with all bells and whistles of a proper FOSS +project, including configuration, build, internationalization, help files, etc. + +%description -l zh_CN +"Hello World" 程序, 包含 FOSS 项目所需的所有部分, 包括配置, 构建, 国际化, 帮助文件等. + +%prep +%setup -q + +%build +%configure +make %{?_smp_mflags} + +%install +make install DESTDIR=%{buildroot} +%find_lang %{name} +rm -f %{buildroot}/%{_infodir}/dir + +%post +/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || : + +%preun +if [ $1 = 0 ] ; then +/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || : +fi + +%files -f %{name}.lang +%doc AUTHORS ChangeLog NEWS README THANKS TODO +%license COPYING +%{_mandir}/man1/hello.1.* +%{_infodir}/hello.info.* +%{_bindir}/hello + +%changelog +* Thu Dec 26 2019 Your Name - 2.10-1 +- Update to 2.10 +* Sat Dec 3 2016 Your Name - 2.9-1 +- Update to 2.9 +``` + +- Name 标签是软件名,Version 标签是版本号,而 Release 标签是发布编号。 +- Summary 标签是简要说明,英文的话第一个字母应大写,以避免 rpmlint 工具(打包检查工具)警告。 +- License 标签说明软件包的协议版本,审查软件的 License 状态是打包者的职责,这可以通过检查源码或 LICENSE 文件,或与作者沟通来完成。 +- Group 标签过去用于按照 /usr/share/doc/rpm-/GROUPS 分类软件包。目前该标记已丢弃,vim的模板还有这一条,删掉即可,不过添加该标记也不会有任何影响。%changelog 标签应包含每个 Release 所做的更改日志,尤其应包含上游的安全/漏洞补丁的说明。%changelog 条目应包含版本字符串,以避免 rpmlint 工具警告。 +- 多行的部分,如 %changelog 或 %description 由指令下一行开始,空行结束。 +- 一些不需要的行 \(如 BuildRequires 和 Requires\) 可在行首使用 ‘\#’ 注释。 +- %prep、%build、%install、%file暂时用默认的,未做任何修改。 + +#### 构建RPM包 + +构建源码、二进制和包含调试信息的软件包,在spec文件所在目录执行如下命令: + +``` +# rpmbuild -ba hello.spec +``` + +执行成功后,查看结果,使用如下命令: + +``` +# tree ~/rpmbuild/*RPMS + +/home/testUser/rpmbuild/RPMS +└── aarch64 + ├── hello-2.10-1.aarch64.rpm + ├── hello-debuginfo-2.10-1.aarch64.rpm + └── hello-debugsource-2.10-1.aarch64.rpm +/home/testUser/rpmbuild/SRPMS +└── hello-2.10-1.src.rpm +``` + +## 使用OBS构建 + +本章介绍通过网页和osc构建RPM软件包的方法。主要包括如下两类: + +- 修改已有软件包:修改已有软件包源代码,然后将修改后的源代码构建成一个RPM软件包。 +- 新增软件包:从无到有全新开发一个新的软件源文件,并将新开发的源文件构建成一个RPM软件包。 + + +### OBS简介 + +OBS是基于openSUSE发行版的通用编译框架,用于将源码包构建为RPM软件包或Linux镜像。OBS采用自动化的分布式编译方式,支持多种Linux操作系统发行版(openEuler、SUSE、Debian等)镜像和安装包的编译,且支持在多种架构平台(x86、ARM64等)上编译。 + +OBS由后端和前端组成,后端实现所有核心功能,前端提供了网页应用和API,用于与后端进行交互。此外,OBS还有一个API命令行客户端osc,osc是在一个单独的存储库中开发的。 + +OBS使用工程组织软件包。基础的权限控制、相关的存仓库和构建目标(操作系统和架构)都可以在工程中定义。一个工程可以包含多个子工程,各个子工程可以独立配置,共同完成任务。 + +### 在线构建软件包 + +本章介绍通过OBS网页端在线构建RPM软件包的方法。 + + + +#### 构建已有软件包 + +>![](public_sys-resources/icon-note.gif) **说明:** +>- 若为首次使用,请首先在OBS网页注册个人账号。 +>- 该方法需要拷贝修改后的代码,因此,请在执行下述操作前完成代码修改并提交到正确的代码路径。代码路径会在\_service文件中指定。 + +使用OBS网页端,修改已有软件的源代码,并将修改后的源文件构建为RPM软件包的操作方法如下: + +1. 登录OBS界面,地址为:[http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/)。 +2. 单击“All Projects”进入所有工程页面。 +3. 单击需要修改的对应工程,进入该工程的详情页面,例如单击“openEuler:Mainline”。 +4. 在工程详情页面的搜索框查找需要修改的软件包,然后单击该软件包包名,进入该软件包详请页面。 +5. 单击“Branch package”,在弹出的确认页面单击“Accept”确认创建子工程,如[图1](#fig77646143214)所示。 + + **图 1** Branch Confirmation页面 + ![](figures/Branch-Confirmation页面.png "Branch-Confirmation页面") + +6. 单击“\_service”文件进入编辑页面,修改\_service内容后点击“Save”保存该文件。\_service内容示例如下,其中 _userCodeURL_、 _userCommitID_ 分别为用户代码托管路径、用户代码提交版本号或分支。 + + ``` + + + git + userCodeURL + userCommitID + + + bz2 + *.tar + + + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >单击“Save”保存\_service文件后,OBS服务会根据\_service文件描述,从指定的url下载源码到OBS对应工程的软件目录下并替换原有文件,例如上述例子中 “openEuler:Mainline”工程的kernel目录。 + +7. 文件拷贝并替换完成后,OBS会自动开始构建RPM软件包。等待构建完成,并查看右侧状态栏的构建状态。 + - succeeded:构建成功。用户可以单击“succeeded”查看构建日志,如[图2](#fig10319114217337)所示。 + + **图 2** succeeded的页面 + ![](figures/succeeded的页面.png "succeeded的页面") + + - failed:构建失败。请单击“failed”查看错误日志进行问题定位后重新构建。 + - unresolvable:未进行构建,可能由于缺失依赖。 + - disabled:构建被手动关闭或正在排队构建。 + - excluded:构建被禁止,可能由于缺少spec文件或者spec文件中禁止了目标架构的编译。 + + +#### 新增软件包 + +使用OBS网页端,新增一个全新软件包的操作方法如下: + +1. 登录OBS界面。 +2. 根据新增软件包的依赖情况,选择合适的工程,即单击“All Projects”选择对应工程,例如“openEuler:Mainline”。 +3. 单击工程下任一软件包,进入该软件包的详情页面。 +4. 单击“Branch package”,在弹出的确认页面单击“Accept”确认创建子工程。 +5. 单击“Delete package”,删除新创建子工程中的软件包,如[图3](#fig18306181103615)所示。 + + **图 3** 删除子工程中软件包 + ![](figures/删除子工程中软件包.png "删除子工程中软件包") + + >![](public_sys-resources/icon-note.gif) **说明:** + >通过已有软件创建新工程是为了继承环境等依赖,而不需要实际的文件,所以这里需要把这些文件删除。 + +6. 单击“Create Package”,在弹出的页面输入软件包名称、标题和软件包描述,然后单击“Create”创建软件包,分别如[图4](#fig6762111693811)、[图5](#fig18351153518389)所示。 + + **图 4** Create Package页面 + ![](figures/Create-Package页面.png "Create-Package页面") + + **图 5** 创建软件包信息填写页面 + ![](figures/创建软件包信息填写页面.png "创建软件包信息填写页面") + +7. 在页面中单击“Add file”上传spec文件和需要编译的文件(在spec文件中指定),如[图6](#fig1475845284011)所示。 + + **图 6** Add file页面 + ![](figures/Add-file页面.png "Add-file页面") + +8. 文件上传成功后,OBS会自动开始构建RPM软件包。等待构建完成,并查看右侧状态栏的构建状态。 + - succeed:构建成功。用户可以单击“succeeded”查看构建日志。 + - failed:构建失败。请单击“failed”查看错误日志进行问题定位后重新构建。 + - unresolvable:未进行构建,可能由于缺失依赖。 + - disabled:构建被手动关闭或正在排队构建。 + - excluded:构建被禁止,可能由于缺少spec文件或者spec文件中禁止了目标架构的编译。 + + +#### 获取软件包 + +RPM软件包构建完成后,通过网页端获取对应RPM软件包的方法如下: + +1. 登录OBS界面。 +2. 单击“All Projects”找到所需软件包的对应工程,例如“openEuler:Mainline”。 +3. 在工程下单击所需软件包的包名,进入该软件包详请页面。例如上述例子中的kernel页面。 + +1. 选择Repositories页签进入软件包的软件仓库管理页面,在Publish Flag中通过单击选择“Enable”开启(状态由![](figures/zh-cn_image_0229243704.png)变为![](figures/zh-cn_image_0229243702.png))对应的RPM软件包下载功能,如[图7](#fig17480830144217)所示。 + + **图 7** Repositories页面 + ![](figures/Repositories页面.png "Repositories页面") + +2. 单击Repository列的构建工程名称,进入RPM软件包下载页面,单击RPM软件包右侧的“Download”即可下载对应RPM软件包,如[图8](#fig12152145615438)所示。 + + **图 8** RPM软件包下载页面 + ![](figures/RPM软件包下载页面.png "RPM软件包下载页面") + + +### 使用osc构建软件包 + +本章介绍使用OBS的命令行工具osc创建工程并构建RPM软件包的方法。 + + + +#### 安装并配置osc + +##### 前提条件 +需要root权限,已设置openEuler的repo软件源。 + +##### 操作步骤 +1. 使用root用户安装osc命令行工具及依赖。 + + ``` + # dnf install osc build + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >编译RPM软件包的过程中会依赖build。 + +2. 配置osc。 + 1. 打开\~/.oscrc,命令如下: + + ``` + # vi ~/.oscrc + ``` + + 2. 在\~/.oscrc中添加user和pass字段,如下所示,它们的取值 _userName_ 和 _passWord_ 分别是用户在OBS网页([http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/))上已经注册的账号和密码。 + + ``` + [general] + apiurl = http://openeuler-build.huawei.com/ + no_verify = 1 + [http://openeuler-build.huawei.com/] + user=userName + pass=passWord + ``` + + +#### 构建已有软件包 + +**创建工程** + +1. 通过拷贝已有工程,创建属于用户自己的子工程。例如将openEuler:Mainline工程下的zlib软件包到新分支,参考命令如下: + + ``` + # osc branch openEuler:Mainline zlib + ``` + + 回显如下所示,说明在用户testUser下创建了新的分支工程home:testUser:branches:openEuler:Mainline。 + + ``` + A working copy of the branched package can be checked out with: + osc co home:testUser:branches:openEuler:Mainline/zlib + ``` + +2. 将需要修改软件包的相关配置文件(例如\_service)下载到本地当前路径。其中 _testUser_ 为\~/.oscrc配置文件中配置的账户名称,请根据实际情况修改。 + + ``` + # osc co home:testUser:branches:openEuler:Mainline/zlib + ``` + + 回显如下所示: + + ``` + A home:testUser:branches:openEuler:Mainline + A home:testUser:branches:openEuler:Mainline/zlib + A home:testUser:branches:openEuler:Mainline/zlib/_service + ``` + +3. 进入本地子工程目录,并将软件包远程代码同步到本地。 + + ``` + # cd home:testUser:branches:openEuler:Mainline/zlib + # osc up -S + ``` + + 回显如下所示: + + ``` + A _service:tar_scm_kernel_repo:0001-Neon-Optimized-hash-chain-rebase.patch + A _service:tar_scm_kernel_repo:0002-Porting-optimized-longest_match.patch + A _service:tar_scm_kernel_repo:0003-arm64-specific-build-patch.patch + A _service:tar_scm_kernel_repo:zlib-1.2.11-optimized-s390.patch + A _service:tar_scm_kernel_repo:zlib-1.2.11.tar.xz + A _service:tar_scm_kernel_repo:zlib-1.2.5-minizip-fixuncrypt.patch + A _service:tar_scm_kernel_repo:zlib.spec + ``` + + +**构建RPM包** + +1. 重命名源文件,然后将重命名后的源文件添加到OBS暂存中。 + + ``` + # rm -f _service;for file in `ls | grep -v .osc`;do new_file=${file##*:};mv $file $new_file;done + # osc addremove * + ``` + +2. 修改源代码和spec文件,并将对应软件包的所有修改同步到OBS服务器。参考命令如下,-m参数后的信息为提交记录。 + + ``` + # osc ci -m "commit log" + ``` + +3. 获取当前工程的仓库名称和架构,参考命令如下: + + ``` + # osc repos home:testUser:branches:openEuler:Mainline + ``` + +4. 修改提交成功后,OBS会自动开始编译软件包。可以通过如下命令,查看对应仓库的编译日志,其中 _standard_aarch64_ 、 _aarch64_ 分别为查询所得仓库名称和架构。 + + ``` + # osc buildlog standard_aarch64 aarch64 + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >用户也可以通过网页端打开自己创建的对应工程,查看构建日志。 + + +#### 新增软件包 + +使用OBS的osc工具新增一个全新软件包的操作方法如下: + +**创建工程** + +1. 根据新增软件包的依赖情况,基于合适的工程,创建属于用户自己的个人工程。例如基于 _openEuler:Mainline_ 工程的 zlib 创建工程的参考命令如下,zlib 为工程下的任一软件包。 + + ``` + # osc branch openEuler:Mainline zlib + ``` + +2. 删除创建工程时新增的无用软件包。例如删除zlib软件包的参考命令如下: + + ``` + # cd home:testUser:branches:openEuler:Mainline + # osc rm zlib + # osc commit -m "commit log" + ``` + +3. 在个人工程下创建新增的软件包。例如新增软件包 my-first-obs-package命令如下: + + ``` + # mkdir my-first-obs-package + # cd my-first-obs-package + ``` + + +**构建RPM包** + +1. 添加准备的源文件和spec文件到软件包目录。 +2. 修改源代码和spec文件,并将对应软件包的所有文件上传到OBS服务器。参考命令如下,-m 参数后的信息为提交记录。 + + ``` + # cd home:testUser:branches:openEuler:Mainline + # osc add my-first-obs-package + # osc ci -m "commit log" + ``` + +3. 获取当前工程的仓库名称和架构,参考命令如下: + + ``` + # osc repos home:testUser:branches:openEuler:Mainline + ``` + +4. 修改提交成功后,OBS会自动开始编译软件包。可以通过如下命令,查看对应仓库的编译日志,其中 _standard_aarch64_ 、 _aarch64_ 分别为查询所得仓库名称和架构。 + + ``` + # cd home:testUser:branches:openEuler:Mainline/my-first-obs-package + # osc buildlog standard_aarch64 aarch64 + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >用户也可以通过网页端打开自己创建的对应工程,查看构建日志。 + + +#### 获取软件包 + +RPM软件包构建完成后,使用osc获取对应RPM软件包的命令如下: + +``` +# osc getbinaries home:testUser:branches:openEuler:Mainline my-first-obs-package standard_aarch64 aarch64 +``` + +命令中的各参数含义如下,请用户根据实际情况修改: + +- _home:testUser:branches:openEuler:Mainline_ :软件包所在工程名称 +- _my-first-obs-package_ :软件包名称 +- _standard\_aarch64_ :仓库名称 +- _aarch64_ :仓库架构名称 + +>![](public_sys-resources/icon-note.gif) **说明:** +>使用osc构建的软件包也可以在网页端获取,获取方式请参见[获取软件包](#获取软件包)。 diff --git "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272\345\267\262\346\234\211\350\275\257\344\273\266\345\214\205-9.md" "b/content/zh/docs/ApplicationDev/\346\236\204\345\273\272\345\267\262\346\234\211\350\275\257\344\273\266\345\214\205-9.md" deleted file mode 100644 index da9b69e477b5132b14c142c4f957bc40e0aa2a75..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272\345\267\262\346\234\211\350\275\257\344\273\266\345\214\205-9.md" +++ /dev/null @@ -1,82 +0,0 @@ -# 构建已有软件包 - -**创建工程** - -1. 通过拷贝已有工程,创建属于用户自己的子工程。例如将openEuler:Mainline工程下的zlib软件包到新分支,参考命令如下: - - ``` - # osc branch openEuler:Mainline zlib - ``` - - 回显如下所示,说明在用户testUser下创建了新的分支工程home:testUser:branches:openEuler:Mainline。 - - ``` - A working copy of the branched package can be checked out with: - osc co home:testUser:branches:openEuler:Mainline/zlib - ``` - -2. 将需要修改软件包的相关配置文件(例如\_service)下载到本地当前路径。其中 _testUser_ 为\~/.oscrc配置文件中配置的账户名称,请根据实际情况修改。 - - ``` - # osc co home:testUser:branches:openEuler:Mainline/zlib - ``` - - 回显如下所示: - - ``` - A home:testUser:branches:openEuler:Mainline - A home:testUser:branches:openEuler:Mainline/zlib - A home:testUser:branches:openEuler:Mainline/zlib/_service - ``` - -3. 进入本地子工程目录,并将软件包远程代码同步到本地。 - - ``` - # cd home:testUser:branches:openEuler:Mainline/zlib - # osc up -S - ``` - - 回显如下所示: - - ``` - A _service:tar_scm_kernel_repo:0001-Neon-Optimized-hash-chain-rebase.patch - A _service:tar_scm_kernel_repo:0002-Porting-optimized-longest_match.patch - A _service:tar_scm_kernel_repo:0003-arm64-specific-build-patch.patch - A _service:tar_scm_kernel_repo:zlib-1.2.11-optimized-s390.patch - A _service:tar_scm_kernel_repo:zlib-1.2.11.tar.xz - A _service:tar_scm_kernel_repo:zlib-1.2.5-minizip-fixuncrypt.patch - A _service:tar_scm_kernel_repo:zlib.spec - ``` - - -**构建RPM包** - -1. 重命名源文件,然后将重命名后的源文件添加到OBS暂存中。 - - ``` - # rm -f _service;for file in `ls | grep -v .osc`;do new_file=${file##*:};mv $file $new_file;done - # osc addremove * - ``` - -2. 修改源代码和spec文件,并将对应软件包的所有修改同步到OBS服务器。参考命令如下,-m参数后的信息为提交记录。 - - ``` - # osc ci -m "commit log" - ``` - -3. 获取当前工程的仓库名称和架构,参考命令如下: - - ``` - # osc repos home:testUser:branches:openEuler:Mainline - ``` - -4. 修改提交成功后,OBS会自动开始编译软件包。可以通过如下命令,查看对应仓库的编译日志,其中 _standard\_aarch64_ _、_ _aarch64_ 分别为查询所得仓库名称和架构。 - - ``` - # osc buildlog standard_aarch64 aarch64 - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >用户也可以通过网页端打开自己创建的对应工程,查看构建日志。 - - diff --git "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272\345\267\262\346\234\211\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\346\236\204\345\273\272\345\267\262\346\234\211\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index d01d79659935554ccd1c607ecb3535ffa7041d7c..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\236\204\345\273\272\345\267\262\346\234\211\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,48 +0,0 @@ -# 构建已有软件包 - ->![](public_sys-resources/icon-note.gif) **说明:** ->- 若为首次使用,请首先在OBS网页注册个人账号。 ->- 该方法需要拷贝修改后的代码,因此,请在执行下述操作前完成代码修改并提交到正确的代码路径。代码路径会在\_service文件中指定。 - -使用OBS网页端,修改已有软件的源代码,并将修改后的源文件构建为RPM软件包的操作方法如下: - -1. 登录OBS界面,地址为:[http://openeuler-build.huawei.com/](http://openeuler-build.huawei.com/)。 -2. 单击“All Projects”进入所有工程页面。 -3. 单击需要修改的对应工程,进入该工程的详情页面,例如单击“openEuler:Mainline”。 -4. 在工程详情页面的搜索框查找需要修改的软件包,然后单击该软件包包名,进入该软件包详请页面。 -5. 单击“Branch package”,在弹出的确认页面单击“Accept”确认创建子工程,如[图1](#fig77646143214)所示。 - - **图 1** Branch Confirmation页面 - ![](figures/Branch-Confirmation页面.png "Branch-Confirmation页面") - -6. 单击“\_service”文件进入编辑页面,修改\_service内容后点击“Save”保存该文件。\_service内容示例如下,其中_userCodeURL、__userCommitID_分别为用户代码托管路径、用户代码提交版本号或分支。 - - ``` - - - git - userCodeURL - userCommitID - - - bz2 - *.tar - - - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >单击“Save”保存\_service文件后,OBS服务会根据\_service文件描述,从指定的url下载源码到OBS对应工程的软件目录下并替换原有文件,例如上述例子中 “openEuler:Mainline”工程的kernel目录。 - -7. 文件拷贝并替换完成后,OBS会自动开始构建RPM软件包。等待构建完成,并查看右侧状态栏的构建状态。 - - succeeded:构建成功。用户可以单击“succeeded”查看构建日志,如[图2](#fig10319114217337)所示。 - - **图 2** succeeded的页面 - ![](figures/succeeded的页面.png "succeeded的页面") - - - failed:构建失败。请单击“failed”查看错误日志进行问题定位后重新构建。 - - unresolvable:未进行构建,可能由于缺失依赖。 - - disabled:构建被手动关闭或正在排队构建。 - - excluded:构建被禁止,可能由于缺少spec文件或者spec文件中禁止了目标架构的编译。 - - diff --git "a/content/zh/docs/ApplicationDev/\346\263\225\345\276\213\345\243\260\346\230\216.md" "b/content/zh/docs/ApplicationDev/\346\263\225\345\276\213\345\243\260\346\230\216.md" deleted file mode 100644 index 15f9150943ce7084308f8faa7e8b0bcd47aea22a..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\346\263\225\345\276\213\345\243\260\346\230\216.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 法律声明 - -**版权所有 © 2020 华为技术有限公司。** - -您对“本文档”的复制、使用、修改及分发受知识共享\(Creative Commons\)署名—相同方式共享4.0国际公共许可协议\(以下简称“CC BY-SA 4.0”\)的约束。为了方便用户理解,您可以通过访问[https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/) 了解CC BY-SA 4.0的概要 \(但不是替代\)。CC BY-SA 4.0的完整协议内容您可以访问如下网址获取:[https://creativecommons.org/licenses/by-sa/4.0/legalcode](https://creativecommons.org/licenses/by-sa/4.0/legalcode)。 - -**商标声明** - -openEuler为华为技术有限公司的商标。本文档提及的其他所有商标或注册商标,由各自的所有人拥有。 - -**免责声明** - -本文档仅作为使用指导,除非适用法强制规定或者双方有明确书面约定, 华为技术有限公司对本文档中的所有陈述、信息和建议不做任何明示或默示的声明或保证,包括但不限于不侵权,时效性或满足特定目的的担保。 - diff --git "a/content/zh/docs/ApplicationDev/\347\216\257\345\242\203\350\246\201\346\261\202.md" "b/content/zh/docs/ApplicationDev/\347\216\257\345\242\203\350\246\201\346\261\202.md" deleted file mode 100644 index 74e50afe5791ac1d7180279ef167d8c58690f231..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\216\257\345\242\203\350\246\201\346\261\202.md" +++ /dev/null @@ -1,97 +0,0 @@ -# 环境要求 - -- 若使用的是物理机,则开发环境所需的最小硬件要求如[表1](#table154419352610)所示。 - - **表 1** 最小硬件要求 - - - - - - - - - - - - - - - - - - - - - - - - -

部件名称

-

最小硬件要求

-

说明

-

架构

-
  • AArch64
  • x86_64
-
  • 支持Arm的64位架构。
  • 支持Intel的x86 64位架构。
-

CPU

-
  • 华为鲲鹏920系列CPU
  • Intel® Xeon®处理器
-

-

-

内存

-

不小于4GB(为了获得更好的应用体验,建议不小于8GB)

-

-

-

硬盘

-

为了获得更好的应用体验,建议不小于120GB)

-

支持IDE、SATA、SAS等接口的硬盘。

-
- -- 若使用的是虚拟机,则开发环境所需的小虚拟化空间要求如[表2](#table780410493819)所示。 - - **表 2** 最小虚拟化空间要求 - - - - - - - - - - - - - - - - - - - - - - - - -

部件名称

-

最小虚拟化空间要求

-

说明

-

架构

-
  • AArch64
  • x86_64
-

-

-

CPU

-

2个CPU

-

-

-

内存

-

不小于4GB(为了获得更好的应用体验,建议不小于8GB)

-

-

-

硬盘

-

不小于32GB(为了获得更好的应用体验,建议不小于120GB)

-

-

-
- - -## 操作系统要求 - -操作系统要求为openEuler操作系统。 - -openEuler操作系统具体安装方法请参考《openEuler 20.03 LTS 安装指南》,其中“软件选择”页面的“已选环境的附加选项”中将“开发工具”勾选。 - diff --git "a/content/zh/docs/ApplicationDev/\347\244\272\344\276\213-4.md" "b/content/zh/docs/ApplicationDev/\347\244\272\344\276\213-4.md" deleted file mode 100644 index 83b089738afc330d92a8091f245a78b4c96614c2..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\244\272\344\276\213-4.md" +++ /dev/null @@ -1,4 +0,0 @@ -# 示例 - - - diff --git "a/content/zh/docs/ApplicationDev/\347\244\272\344\276\213-7.md" "b/content/zh/docs/ApplicationDev/\347\244\272\344\276\213-7.md" deleted file mode 100644 index 50e65de6397fcf4cc262ce66b0747fca0e13e233..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\244\272\344\276\213-7.md" +++ /dev/null @@ -1,3 +0,0 @@ -# 示例 - - diff --git "a/content/zh/docs/ApplicationDev/\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\347\244\272\344\276\213.md" deleted file mode 100644 index 24b7a54a9569a95558552ff2073031803c8740da..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\244\272\344\276\213.md" +++ /dev/null @@ -1,3 +0,0 @@ -# 示例 - - diff --git "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-0.md" "b/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-0.md" deleted file mode 100644 index 3d8d87d367eb010ac70c56d5f1f1a73619cb71f0..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-0.md" +++ /dev/null @@ -1,4 +0,0 @@ -# 简介 - -GCC(GNU Compiler Collection)是GNU推出的功能强大、性能优越的多平台编译器。GCC编译器能将C、C++语言源程序、汇编程序和目标程序编译、连接成可执行文件。openEuler操作系统中已默认安装了GCC软件包。 - diff --git "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-1.md" "b/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-1.md" deleted file mode 100644 index 60e689ae82ee615601bfbe9a8ee2ec18ec3b82c1..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-1.md" +++ /dev/null @@ -1,4 +0,0 @@ -# 简介 - -GNU make实用程序(通常缩写为make)是一种用于控制从源文件生成可执行文件的工具。 make会自动确定复杂程序的哪些部分已更改并需要重新编译。 make使用称为Makefiles的配置文件来控制程序的构建方式。 - diff --git "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-5.md" "b/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-5.md" deleted file mode 100644 index 7f65d9edc31b51cf74495dcfcd16618f21b142b2..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213-5.md" +++ /dev/null @@ -1,4 +0,0 @@ -# 简介 - -JDK(Java Development Kit)是 Java 开发者进行 Java 开发所必须的软件包,包含 JRE(Java Runtime Environment)和编译、调测工具。openEuler在OpenJDK 的基础上进行了 GC 优化、并发稳定性增强、安全性增强等修改,提高了 Java 应用程序在 ARM 上的性能和稳定性。 - diff --git "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213.md" "b/content/zh/docs/ApplicationDev/\347\256\200\344\273\213.md" deleted file mode 100644 index 78f5ea6d7d772f67b77c76b726aa4a6e22aef4f4..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\256\200\344\273\213.md" +++ /dev/null @@ -1,4 +0,0 @@ -# 简介 - -IntelliJ IDEA是一款非常流行的Java IDE,其社区版可以免费下载使用。目前openEuler支持使用IntelliJ IDEA集成开发环境(IDE)进行Java程序的开发,从而可以提升开发人员的工作效率。 - diff --git "a/content/zh/docs/ApplicationDev/\347\261\273\345\272\223.md" "b/content/zh/docs/ApplicationDev/\347\261\273\345\272\223.md" deleted file mode 100644 index 5d21b808d04e268bee02e232288a4b6c17a41f3d..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\261\273\345\272\223.md" +++ /dev/null @@ -1,51 +0,0 @@ -# 类库 - -java类库是以包的形式实现的,包是类和接口的集合。java编译器为每个类生成一个字节码文件,且文件名与类名相同,因此同名的类之间就有可能发生冲突。java语言中,把一组类和接口封装在一个包内,包可以有效地管理类名空间,位于不同包中的类即使同名也不会冲突,从而解决了同名类之间可能发生的冲突问题,为管理大量的类和接口提供了方便,也有利于类和接口的安全。 - -除java提供的许多包外,开发者也可以自定义包,把自己编写的类和接口等组成程序包的形式,以便后续使用。 - -自定义包需要先声明包,然后在使用包。 - -## 包的声明 - -包的声明格式为:package pkg1\[.pkg2\[.pkg3...\]\]; - -为了声明一个包,首先必须建立一个相应的目录结构,子目录与包名一致,然后在需要放入该包的类文件开头声明包,表示该文件的全部类都属于这个包。包声明中的“.”指明了目录的层次。如果源程序文件中没有package语句,则指定为无名包。无名包没有路径,一般情况下,java仍然会把源文件中的类存储在当前工作目录(即存放java源文件的目录)下。 - -包声明语句必须被加到源程序文件的起始部分,而且前面不能有注释和空格。如果在不同源程序文件中使用相同的包声明语句,就可以将不同源程序文件中的类都包含在相同的包中。 - -## 包的引用 - -在 Java 中,为了能使用java提供的包中的公用类,或者使用自定义的包中的类,有两种方法。 - -- 在要引用的类名前带上包名。 - - 如:name.A obj=new name.A \(\); - - 其中,name为包名,A为类名,obj为对象。表示程序中用name包中的A类定义一个对象obj。 - - 示例:新建一个example包中Test类的test对象。 - - ``` - example.Test test = new example.Test(); - ``` - -- 在文件开头使用import来导入包中的类。 - - import语句的格式为:import pkg1\[.pkg2\[.pkg3...\]\].\(classname | \*\); - - 其中,pkg1\[.pkg2\[.pkg3...\]\]表明包的层次,classname为所要导入的类。如果要从一个包中导入多个类,则可以使用通配符“\*”来替代。 - - 示例:导入example包中的Test类。 - - ``` - import example.Test; - ``` - - 示例:将example 整个包导入。 - - ``` - import example.*; - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\344\270\215\345\270\246\345\214\205\347\232\204java\347\250\213\345\272\217\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\344\270\215\345\270\246\345\214\205\347\232\204java\347\250\213\345\272\217\347\244\272\344\276\213.md" deleted file mode 100644 index 90cf3ae4044919f762c525316611749e7aaf005d..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\344\270\215\345\270\246\345\214\205\347\232\204java\347\250\213\345\272\217\347\244\272\344\276\213.md" +++ /dev/null @@ -1,40 +0,0 @@ -# 编译不带包的java程序示例 - -1. cd到代码目录,此处以用户“/home/code”进行举例。如下所示: - - ``` - # cd /home/code - ``` - -2. 编写Hello World程序,保存为HelloWorld.java,此处以编译Hello World程序进行举例说明。示例如下: - - ``` - # vi HelloWorld.java - ``` - - 代码内容示例: - - ``` - public class HelloWorld { - public static void main(String[] args) { - System.out.println("Hello World"); - } - } - ``` - -3. 在代码目录,执行编译,使用命令: - - ``` - # javac HelloWorld.java - ``` - - 编译执行未报错,表明执行通过。 - -4. 编译完成后,会生成 HelloWorld.class 文件,通过java命令可执行查看结果,示例如下: - - ``` - # java HelloWorld - Hello World - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\345\270\246\345\214\205\347\232\204java\347\250\213\345\272\217\347\244\272\344\276\213.md" "b/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\345\270\246\345\214\205\347\232\204java\347\250\213\345\272\217\347\244\272\344\276\213.md" deleted file mode 100644 index 581be061f9c1385e02f726273cb9a4dbae7824f0..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\345\270\246\345\214\205\347\232\204java\347\250\213\345\272\217\347\244\272\344\276\213.md" +++ /dev/null @@ -1,95 +0,0 @@ -# 编译带包的java程序示例 - -1. cd到代码目录,此处以用户“/home/code”进行举例。并在该目录下创建“/home/code/Test/my/example”、“/home/code/Hello/world/developers”、“/home/code/Hi/openos/openeuler”子目录,分别用于存放源文件。 - - ``` - cd /home/code - - mkdir -p Test/my/example - mkdir -p Hello/world/developers - mkdir -p Hi/openos/openeuler - ``` - -2. cd到/home/code/Test/my/example目录,创建Test.java。 - - ``` - cd /home/code/Test/my/example - vi Test.java - ``` - - Test.java代码内容示例: - - ``` - package my.example; - import world.developers.Hello; - import openos.openeuler.Hi; - public class Test { - public static void main(String[] args) { - Hello me = new Hello(); - me.hello(); - Hi you = new Hi(); - you.hi(); - } - } - ``` - -3. cd到/home/code/Hello/world/developers目录,创建Hello.java。 - - ``` - cd /home/code/Hello/world/developers - vi Hello.java - ``` - - Hello.java代码内容示例: - - ``` - package world.developers; - public class Hello { - public void hello(){ - System.out.println("Hello, openEuler."); - } - } - ``` - -4. cd到/home/code/Hi/openos/openeuler目录,创建Hi.java。 - - ``` - cd /home/code/Hi/openos/openeuler - vi Hi.java - ``` - - Hi.java代码内容示例: - - ``` - package openos.openeuler; - public class Hi { - public void hi(){ - System.out.println("Hi, the global developers."); - } - } - ``` - -5. cd到/home/code,使用javac编译源文件。 - - ``` - cd /home/code - javac -classpath Hello:Hi Test/my/example/Test.java - ``` - - 执行完命令后,会在“/home/code/Test/my/example”、“/home/code/Hello/world/developers”、“/home/code/Hi/openos/openeuler”目录下分别生成Test.class、Hello.class、Hi.class文件。 - -6. cd到/home/code,使用java运行Test程序。 - - ``` - cd /home/code - java -classpath Test:Hello:Hi my/example/Test - ``` - - 执行结果如下所示: - - ``` - Hello, openEuler. - Hi, the global developers. - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\346\265\201\347\250\213.md" "b/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\346\265\201\347\250\213.md" deleted file mode 100644 index 6e81ff56669e251874be13134112403d3a747b8e..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\346\265\201\347\250\213.md" +++ /dev/null @@ -1,11 +0,0 @@ -# 编译流程 - -使用GCC将源代码文件生成可执行文件,需要经过预处理、编译、汇编和链接。 - -1. 预处理:将源程序(如**.c**文件)预处理,生成**.i**文件。 -2. 编译:将预处理后的**.i**文件编译成为汇编语言,生成**.s**文件。 -3. 汇编:将汇编语言文件经过汇编,生成目标文件**.o**文件。 -4. 链接:将各个模块的**.o**文件链接起来生成一个可执行程序文件。 - -其中**.i**文件、**.s**文件、**.o**文件是中间文件或临时文件,如果使用GCC一次性完成C语言程序的编译,则这些文件会被删除。 - diff --git "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\351\200\211\351\241\271.md" "b/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\351\200\211\351\241\271.md" deleted file mode 100644 index 1a2e36334a9eff2307774e1077c5545ca9dd19da..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\274\226\350\257\221\351\200\211\351\241\271.md" +++ /dev/null @@ -1,113 +0,0 @@ -# 编译选项 - -GCC编译的命令格式为:**gcc** \[_options_\] \[_filenames_\] - -其中: - -_options_:编译选项。 - -_filenames_:文件名称。 - -GCC是一个功能强大的编译器,其_options_参数取值很多,但有些大部分并不常用,常用的_options_取值如[表1](#table1342946175212)所示。 - -**表 1** GCC常用的编译选项 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

options取值

-

说明

-

示例

-

-c

-

编译、汇编指定的源文件生成目标文件,但不进行链接。通常用于编译不包含主程序的子程序文件。

-

#使用-c选项编译test1.c、test2.c源文件

-

gcc -c test1.c test2.c

-

-S

-

编译指定的源文件生成以.s作为后缀的汇编语言文件,但不进行汇编。

-

#编译器预处理 circle.c,将其翻译成汇编语言,并将结果存储在 circle.s 文件中。

-

gcc -S circle.c

-

-E

-

预处理指定的源文件,但不进行编译。

-

默认情况下,预处理器的输出会被导入到标准输出流(如显示器),可以利用-o选项把它导入到某个输出文件。

-

#预处理的结果导出到 circle.i 文件。

-

gcc -E circle.c -o circle.i

-

-o file

-

用在生成可执行文件时,生成指定的输出文件file。同时该名称不能和源文件同名。如果不给出这个选项,gcc就给出预设的可执行文件a.out。

-

#将源文件作为输入文件,将可执行文件作为输出文件,也即完整地编译整个程序。

-

gcc main.c func.c -o app.out

-

-g

-

在可执行程序中包含标准调试信息。

-

-

-

-L libary_path

-

在库文件的搜索路径列表中添加libary_path路径。

-

-

-

-Ilibrary

-

链接时搜索指定的函数库library

-

使用 GCC 编译和链接程序时,GCC 默认会链接 libc.a 或者 libc.so,但是对于其他的库(例如非标准库、第三方库等),就需要手动添加。

-

#使用-l选项,以链接数学库。

-

gcc main.c -o main.out -lm

-
说明:

数学库的文件名是 libm.a。前缀lib和后缀.a是标准的,m是基本名称,GCC 会在-l选项后紧跟着的基本名称的基础上自动添加这些前缀、后缀,本例中,基本名称为 m。

-
-

-I head_path

-

在头文件的搜索路径列表中添加head_path路径。

-

-

-

-static

-

进行静态编译,及链接静态库,禁止链接动态库。

-

-

-

-shared

-

默认选项,可省略。

-
  • 可以生成动态库文件。
  • 进行动态编译,优先链接动态库,只有没有动态库是才会链接同名的静态库。
-

-

-

-fPIC(或-fpic)

-

生成使用相对地址的位置无关的目标代码。通常使用-static选项从该PIC目标文件生成动态库文件。

-

-

-
- diff --git "a/content/zh/docs/ApplicationDev/\347\274\226\350\276\221SPEC\346\226\207\344\273\266.md" "b/content/zh/docs/ApplicationDev/\347\274\226\350\276\221SPEC\346\226\207\344\273\266.md" deleted file mode 100644 index 3c1413af6f50ec66f39e516b4c47f630b260751b..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\347\274\226\350\276\221SPEC\346\226\207\344\273\266.md" +++ /dev/null @@ -1,73 +0,0 @@ -# 编辑SPEC文件 - -新建spec文件,参考命令如下: - -``` -# vi hello.spec -``` - -在文件中写入对应内容后保存文件。文件内容示例如下,请根据实际情况修改相应字段。 - -``` -Name: hello -Version: 2.10 -Release: 1%{?dist} -Summary: The "Hello World" program from GNU -Summary(zh_CN): GNU "Hello World" 程序 -License: GPLv3+ -URL: http://ftp.gnu.org/gnu/hello -Source0: http://ftp.gnu.org/gnu/hello/%{name}-%{version}.tar.gz - -BuildRequires: gettext -Requires(post): info -Requires(preun): info - -%description -The "Hello World" program, done with all bells and whistles of a proper FOSS -project, including configuration, build, internationalization, help files, etc. - -%description -l zh_CN -"Hello World" 程序, 包含 FOSS 项目所需的所有部分, 包括配置, 构建, 国际化, 帮助文件等. - -%prep -%setup -q - -%build -%configure -make %{?_smp_mflags} - -%install -make install DESTDIR=%{buildroot} -%find_lang %{name} -rm -f %{buildroot}/%{_infodir}/dir - -%post -/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || : - -%preun -if [ $1 = 0 ] ; then -/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || : -fi - -%files -f %{name}.lang -%doc AUTHORS ChangeLog NEWS README THANKS TODO -%license COPYING -%{_mandir}/man1/hello.1.* -%{_infodir}/hello.info.* -%{_bindir}/hello - -%changelog -* Thu Dec 26 2019 Your Name - 2.10-1 -- Update to 2.10 -* Sat Dec 3 2016 Your Name - 2.9-1 -- Update to 2.9 -``` - -- Name 标签是软件名,Version 标签是版本号,而 Release 标签是发布编号。 -- Summary 标签是简要说明,英文的话第一个字母应大写,以避免 rpmlint 工具(打包检查工具)警告。 -- License 标签说明软件包的协议版本,审查软件的 License 状态是打包者的职责,这可以通过检查源码或 LICENSE 文件,或与作者沟通来完成。 -- Group 标签过去用于按照 /usr/share/doc/rpm-/GROUPS 分类软件包。目前该标记已丢弃,vim的模板还有这一条,删掉即可,不过添加该标记也不会有任何影响。%changelog 标签应包含每个 Release 所做的更改日志,尤其应包含上游的安全/漏洞补丁的说明。%changelog 条目应包含版本字符串,以避免 rpmlint 工具警告。 -- 多行的部分,如 %changelog 或 %description 由指令下一行开始,空行结束。 -- 一些不需要的行 \(如 BuildRequires 和 Requires\) 可在行首使用 ‘\#’ 注释。 -- %prep、%build、%install、%file暂时用默认的,未做任何修改。 - diff --git "a/content/zh/docs/ApplicationDev/\350\216\267\345\217\226\350\275\257\344\273\266\345\214\205-11.md" "b/content/zh/docs/ApplicationDev/\350\216\267\345\217\226\350\275\257\344\273\266\345\214\205-11.md" deleted file mode 100644 index d4b533c1ac1308e905b5a39b14a2a524cb49b613..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\350\216\267\345\217\226\350\275\257\344\273\266\345\214\205-11.md" +++ /dev/null @@ -1,18 +0,0 @@ -# 获取软件包 - -RPM软件包构建完成后,使用osc获取对应RPM软件包的命令如下: - -``` -# osc getbinaries home:testUser:branches:openEuler:Mainline my-first-obs-package standard_aarch64 aarch64 -``` - -命令中的各参数含义如下,请用户根据实际情况修改: - -- _home:testUser:branches:openEuler:Mainline_ :软件包所在工程名称 -- _my-first-obs-package_ :软件包名称 -- _standard\_aarch64_ :仓库名称 -- _aarch64_ :仓库架构名称 - ->![](public_sys-resources/icon-note.gif) **说明:** ->使用osc构建的软件包也可以在网页端获取,获取方式请参见网页端获取软件包相关内容。 - diff --git "a/content/zh/docs/ApplicationDev/\350\216\267\345\217\226\350\275\257\344\273\266\345\214\205.md" "b/content/zh/docs/ApplicationDev/\350\216\267\345\217\226\350\275\257\344\273\266\345\214\205.md" deleted file mode 100644 index 45bb4bd2f87b7880b6c94b8a5f84619b67ad1464..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\350\216\267\345\217\226\350\275\257\344\273\266\345\214\205.md" +++ /dev/null @@ -1,19 +0,0 @@ -# 获取软件包 - -RPM软件包构建完成后,通过网页端获取对应RPM软件包的方法如下: - -1. 登录OBS界面。 -2. 单击“All Projects”找到所需软件包的对应工程,例如“openEuler:Mainline”。 -3. 在工程下单击所需软件包的包名,进入该软件包详请页面。例如上述例子中的kernel页面。 - -1. 选择Repositories页签进入软件包的软件仓库管理页面,在Publish Flag中通过单击选择“Enable”开启(状态由![](figures/zh-cn_image_0229243704.png)变为![](figures/zh-cn_image_0229243702.png))对应的RPM软件包下载功能,如[图1](#fig17480830144217)所示。 - - **图 1** Repositories页面 - ![](figures/Repositories页面.png "Repositories页面") - -2. 单击Repository列的构建工程名称,进入RPM软件包下载页面,单击RPM软件包右侧的“Download”即可下载对应RPM软件包,如[图2](#fig12152145615438)所示。 - - **图 2** RPM软件包下载页面 - ![](figures/RPM软件包下载页面.png "RPM软件包下载页面") - - diff --git "a/content/zh/docs/ApplicationDev/\350\256\276\347\275\256JDK\347\216\257\345\242\203.md" "b/content/zh/docs/ApplicationDev/\350\256\276\347\275\256JDK\347\216\257\345\242\203.md" deleted file mode 100644 index 5f39cedcf8cfe3bc6a55579c667348a4bdfc51b3..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\350\256\276\347\275\256JDK\347\216\257\345\242\203.md" +++ /dev/null @@ -1,27 +0,0 @@ -# 设置JDK环境 - -在设置JAVA\_HOME之前您需要先找到JDK的安装路径。在“开发环境准备 \> 安装软件包 \> 安装JDK软件包”章节中您已经学会了如何安装JDK,如果您还没安装好JDK,请提前安好。 - -查看java路径,命令如下: - -``` -# which java -/usr/bin/java -``` - -查看软链接的实际指向目录,命令如下: - -``` -# ls -la /usr/bin/java -lrwxrwxrwx. 1 root root 22 Mar 6 20:28 /usr/bin/java -> /etc/alternatives/java -# ls -la /etc/alternatives/java -lrwxrwxrwx. 1 root root 83 Mar 6 20:28 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64/jre/bin/java -``` - -发现JDK的真实路径为/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64,设置JAVA\_HOME和PATH,命令如下: - -``` -# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.h2.aarch64 -# export PATH=$JAVA_HOME/bin:$PATH -``` - diff --git "a/content/zh/docs/ApplicationDev/\350\256\276\347\275\256X11-Forwarding.md" "b/content/zh/docs/ApplicationDev/\350\256\276\347\275\256X11-Forwarding.md" deleted file mode 100644 index 3dbb60c836002b9aaaf2b320fc129a295e147dfe..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\350\256\276\347\275\256X11-Forwarding.md" +++ /dev/null @@ -1,31 +0,0 @@ -# 设置X11 Forwarding - -切换到sshd配置目录 - -``` -# cd ~/.ssh -``` - -如果该目录不存在,则创建目录后再进行切换,创建目录命令如下: - -``` -# mkdir ~/.ssh -``` - -然后在.ssh目录下编辑config文件并保存: - -1. 使用vim打卡config文件 - - ``` - # vim config - ``` - -2. 将以下内容添加到文件末尾并保存: - - ``` - Host * - ForwardAgent yes - ForwardX11 yes - ``` - - diff --git "a/content/zh/docs/ApplicationDev/\351\205\215\347\275\256repo\346\272\220.md" "b/content/zh/docs/ApplicationDev/\351\205\215\347\275\256repo\346\272\220.md" deleted file mode 100644 index 062fd2646babf2fcecc07be64e3e47aaa517719b..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\351\205\215\347\275\256repo\346\272\220.md" +++ /dev/null @@ -1,156 +0,0 @@ -# 配置repo源 - -可以通过直接获取repo源文件的方式配置repo源或通过挂载ISO的方式配置repo源。 - -## 通过直接获取repo源文件的方式配置repo源 - ->![](public_sys-resources/icon-note.gif) **说明:** ->openEuler提供了多种repo源文件,本操作以AArch64架构的OS repo源文件为例。 - -1. 进入到yum源目录。 - - ``` - cd /etc/yum.repos.d - ``` - -2. 新建local.repo文件并编辑local.repo,将repo源文件配置为yum源。 - - ``` - vi local.repo - ``` - - 编辑local.repo文件的内容如下: - - \[basiclocal\] - - name=basiclocal - - baseurl=http://repo.openeuler.org/openEuler-20.03-LTS/OS/aarch64/ - - enabled=1 - - gpgcheck=0 - - -## 通过挂载ISO的方式配置repo源 - ->![](public_sys-resources/icon-note.gif) **说明:** ->本操作以openEuler-20.03-LTS-aarch64-dvd.iso镜像文件和openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum校验文件为例,请根据实际需要的镜像文件和校验文件进行修改。 - -1. 下载ISO镜像。 - - 通过跨平台文件传输工具下载ISO镜像 - 1. 登录openEuler社区,网址为:[https://openeuler.org](https://openeuler.org)。 - 2. 单击“下载”,进入下载页面。 - 3. 单击“获取ISO:”后面的“Link”,显示版本列表。 - 4. 选择需要下载的版本,如openEuler 20.03 LTS,则单击“openEuler-20.03-LTS”,进入下载列表。 - 5. 单击“ISO”,进入ISO下载列表。 - - aarch64:AArch64架构的ISO。 - - x86\_64:x86\_64架构的ISO。 - - source:openEuler源码ISO。 - - 6. 单击“aarch64”。 - 7. 单击“openEuler-20.03-LTS-aarch64-dvd.iso”,将openEuler发布包下载到本地。 - 8. 单击“openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum”,将openEuler校验文件下载到本地。 - 9. 登录openEuler操作系统,新建用于存放发布包和检验文件的目录,如“/home/iso”。 - - ``` - mkdir /home/iso - ``` - - 10. 使用跨平台文件传输工具(如WinSCP)将本地的openEuler发布包和校验文件上传到openEuler操作系统。 - - - 通过wget命令下载ISO镜像。 - 1. 登录openEuler社区,网址为:[https://openeuler.org](https://openeuler.org)。 - 2. 单击“下载”,进入下载页面。 - 3. 单击“获取ISO:”后面的“Link”,显示版本列表。 - 4. 选择需要下载的版本,如openEuler 20.03 LTS,则单击“openEuler-20.03-LTS”,进入下载列表。 - 5. 单击“ISO”,进入ISO下载列表。 - - aarch64:AArch64架构的ISO。 - - x86\_64:x86\_64架构的ISO。 - - source:openEuler源码ISO。 - - 6. 单击“aarch64”。 - 7. 右键单击“openEuler-20.03-LTS-aarch64-dvd.iso”,单击“复制链接地址”,将openEuler发布包地址记录好。 - 8. 右键单击“openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum”,单击“复制链接地址”,将openEuler校验文件地址记录好。 - 9. 登录openEuler操作系统,新建用于存放发布包和检验文件的目录,如“/home/iso”,并切换到该目录。 - - ``` - mkdir /home/iso - cd /home/iso - ``` - - 10. 使用**wget**命令远程下载发布包和检验文件,命令中的 _ipaddriso_ 和 _ipaddrisosum_ 分别为[1.g](#li62369349505)和[1.h](#li9236203405015)中记录的地址。 - - ``` - wget ipaddriso - wget ipaddrisosum - ``` - - -2. 发布包完整性校验。 - 1. 获取校验文件中的校验值。 - - ``` - cat openEuler-20.03-LTS-aarch64-dvd.iso.sha256sum - ``` - - 2. 计算openEuler发布包的sha256校验值。 - - ``` - sha256sum openEuler-20.03-LTS-aarch64-dvd.iso - ``` - - 命令执行完成后,输出校验值。 - - 3. 对比步骤1和步骤2计算的校验值是否一致。 - - 如果校验值一致说明iso文件完整性没有破坏,如果校验值不一致则可以确认文件完整性已被破坏,需要重新获取。 - -3. 挂载ISO并配置为repo源。 - - 使用mount命令挂载镜像文件。 - - 示例如下: - - ``` - # mount /home/iso/openEuler-20.03-LTS-aarch64-dvd.iso /mnt/ - ``` - - 挂载好的mnt目录如下: - - ``` - . - │── boot.catalog - │── docs - │── EFI - │── images - │── Packages - │── repodata - │── TRANS.TBL - └── RPM-GPG-KEY-openEuler - ``` - - 其中,Packages为rpm包所在的目录,repodata为repo源元数据所在的目录,RPM-GPG-KEY-openEuler为openEuler的签名公钥。。 - - 挂载后的目录可以配置为yum源使用,在/etc/yum.repos.d/目录下创建\*\*\*.repo的配置文件(必须以.repo为扩展名)。 - - 示例如下: - - 在/etc/yum.repos.d目录下创建openEuler.repo 文件,使用本地镜像挂载目录作为yum源,openEuler.repo的内容如下: - - ``` - [base] - name=base - baseurl=file:///mnt - enabled=1 - gpgcheck=1 - gpgkey=file:///mnt/RPM-GPG-KEY-openEuler - ``` - - **** - - >![](public_sys-resources/icon-note.gif) **说明:** - >- gpgcheck可设置为1或0,1表示进行gpg(GNU Private Guard)校验,0表示不进行gpg校验,gpgcheck可以确定rpm包的来源是有效和安全的。 - >- gpgkey为签名公钥的存放路径。 - - diff --git "a/content/zh/docs/ApplicationDev/\351\235\231\346\200\201\351\223\276\346\216\245\345\272\223.md" "b/content/zh/docs/ApplicationDev/\351\235\231\346\200\201\351\223\276\346\216\245\345\272\223.md" deleted file mode 100644 index 19161d4127675a96ce017d6d5a52334cfbb21531..0000000000000000000000000000000000000000 --- "a/content/zh/docs/ApplicationDev/\351\235\231\346\200\201\351\223\276\346\216\245\345\272\223.md" +++ /dev/null @@ -1,31 +0,0 @@ -# 静态链接库 - -创建一个静态链接库,需要先将源文件编译为目标文件,然后在使用ar命令将目标文件打包成静态链接库。 - -示例:将源文件test1.c,test2.c,test3.c编译并打包成静态库。 - -``` -gcc -c test1.c test2.c test3.c -ar rcs libtest.a test1.o test2.o test3.o -``` - -其中ar是一个备份压缩命令,可以将多个文件打包成一个备份文件(也叫归档文件),也可以从备份文件中提取成员文件。ar最常见的用法是将目标文件打包为静态链接库。 - -ar将目标文件打包成静态链接库的命令格式为: - -ar rcs _Sllfilename_ _Targetfilelist_ - -- _Sllfilename_: 静态库文件名。 -- _Targetfilelist_:目标文件列表。 -- r: 替换库中已有的目标文件,或者加入新的目标文件。 -- c: 创建一个库,不管库否存在,都将创建。 -- s: 创建目标文件索引,在创建较大的库时能提高速度。 - -示例:创建一个main.c文件来使用静态库 - -``` -gcc main.c -L libraryDIR -ltest -o test.out -``` - -其中libraryDIR为libtest.a库的路径。 - diff --git "a/content/zh/docs/SecHarden/SELinux\351\205\215\347\275\256.md" "b/content/zh/docs/SecHarden/SELinux\351\205\215\347\275\256.md" index 3c8d1fcde02ec9895ee8b8652b003611358c4c42..e9b34daa0b67b573256c4b49c6189260be548ee2 100644 --- "a/content/zh/docs/SecHarden/SELinux\351\205\215\347\275\256.md" +++ "b/content/zh/docs/SecHarden/SELinux\351\205\215\347\275\256.md" @@ -1,6 +1,6 @@ -# SELinux配置 +# SELinux配置 -## 概述 +## 概述 自由访问控制DAC(Discretionary Access Control)基于用户、组和其他权限,决定一个资源是否能被访问的因素是某个资源是否拥有对应用户的权限,它不能使系统管理员创建全面和细粒度的安全策略。SELinux(Security-Enhanced Linux)是Linux内核的一个模块,也是Linux的一个安全子系统。SELinux的实现了强制访问控制MAC(Mandatory Access Control ),每个进程和系统资源都有一个特殊的安全标签,资源能否被访问除了DAC规定的原则外,还需要判断每一类进程是否拥有对某一类资源的访问权限。 @@ -10,8 +10,7 @@ openEuler默认使用SELinux提升系统安全性。SELinux分为三种模式: - enforcing:SELinux安全策略被强制执行。 - disabled:不加载SELinux安全策略。 -## 配置说明 - +## 配置说明 openEuler默认开启SELinux,且默认模式为enforcing,用户可以通过修改/etc/selinux/config中配置项SELINUX的值变更SELinux模式。 - 关闭SELinux策略的配置如下: @@ -33,7 +32,7 @@ openEuler默认开启SELinux,且默认模式为enforcing,用户可以通过 ># reboot >``` -## SELinux相关命令 +## SELinux相关命令 - 查询SELinux模式。例如下述查询的SELinux模式为Permissive: diff --git a/content/zh/docs/SecHarden/secHarden.md b/content/zh/docs/SecHarden/secHarden.md index d5219a4e308a3e025010aef06948537a0113c54b..c600efce0c96f2ab49969d3a0ee47160acdf02c9 100644 --- a/content/zh/docs/SecHarden/secHarden.md +++ b/content/zh/docs/SecHarden/secHarden.md @@ -1 +1,5 @@ -本文档给出openEuler 1.0 Base版本的加固介绍和加固方法,指导用户进行安全加固。 \ No newline at end of file +# 安全加固指南 + +本文档给出openEuler的加固介绍和加固方法,指导用户进行安全加固。 + +本文档主要适用于需要对openEuler进行安全加固的管理员。管理员需要熟悉操作系统安全架构和安全技术。 \ No newline at end of file diff --git "a/content/zh/docs/SecHarden/umask\345\200\274\345\220\253\344\271\211.md" "b/content/zh/docs/SecHarden/umask\345\200\274\345\220\253\344\271\211.md" deleted file mode 100644 index a5785808792ebac2172b54643ca28bd194a97af0..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/umask\345\200\274\345\220\253\344\271\211.md" +++ /dev/null @@ -1,6 +0,0 @@ -# umask值含义 - -当用户新创建文件或目录时,该文件或目录具有一个缺省权限。该缺省权限由umask值来指定。 - -umask值代表的是权限的“补码”,即用缺省最大权限值减去umask值得到实际权限值。文件的缺省最大权限为可读可写,目录的缺省最大权限为可读可写可执行。即一个文件的实际缺省权限为666减去umask值。目录的实际缺省权限为777减去umask值。 - diff --git "a/content/zh/docs/SecHarden/\344\270\272\345\205\250\345\261\200\345\217\257\345\206\231\347\233\256\345\275\225\346\267\273\345\212\240\347\262\230\346\273\236\344\275\215\345\261\236\346\200\247.md" "b/content/zh/docs/SecHarden/\344\270\272\345\205\250\345\261\200\345\217\257\345\206\231\347\233\256\345\275\225\346\267\273\345\212\240\347\262\230\346\273\236\344\275\215\345\261\236\346\200\247.md" deleted file mode 100644 index 9c1f719df68c64527c9179c9ecbce8304f49126f..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\344\270\272\345\205\250\345\261\200\345\217\257\345\206\231\347\233\256\345\275\225\346\267\273\345\212\240\347\262\230\346\273\236\344\275\215\345\261\236\346\200\247.md" +++ /dev/null @@ -1,21 +0,0 @@ -# 为全局可写目录添加粘滞位属性 - -## 说明 - -任意用户可以删除、修改全局可写目录中的文件和目录,为了确保全局可写目录中的文件和目录不会被任意删除,需要为全局可写目录添加粘滞位属性。 - -## 实现 - -1. 搜索全局可写目录。 - - ``` - find / -type d -perm -0002 ! -perm -1000 -ls | grep -v proc - ``` - -2. 为全局可写目录添加粘滞位属性。_dirname_为实际查找到的目录名。 - - ``` - chmod +t dirname - ``` - - diff --git "a/content/zh/docs/SecHarden/\345\206\205\346\240\270\345\217\202\346\225\260.md" "b/content/zh/docs/SecHarden/\345\206\205\346\240\270\345\217\202\346\225\260.md" index fd485addc48907fd5548179e9d12001df5120cca..c5627ac31c1e94616c3564508a54df4d9fa3b8a7 100644 --- "a/content/zh/docs/SecHarden/\345\206\205\346\240\270\345\217\202\346\225\260.md" +++ "b/content/zh/docs/SecHarden/\345\206\205\346\240\270\345\217\202\346\225\260.md" @@ -1,2 +1,230 @@ -# 内核参数 +# 内核参数 +- [内核参数](#内核参数) + - [加固内核参数](#加固内核参数) + + + +## 加固内核参数 + +### 说明 + +内核参数决定配置和应用特权的状态。内核提供用户可配置的系统控制,这一系统控制可微调或配置,该功能特性可通过控制各种可配置的内核参数,来提高操作系统的安全特性。比如:通过微调或配置网络选项,可有效提高系统的安全性。 + +### 实现 + +1. 将[表3](#zh-cn_topic_0152100187_t69b5423c26644b26abe94d88d38878eb)中的加固项写入/etc/sysctl.conf文件中。 + + >![](public_sys-resources/icon-note.gif) **说明:** + >写入方式如下: + >``` + >net.ipv4.icmp_echo_ignore_broadcasts = 1 + >net.ipv4.conf.all.rp_filter = 1 + >net.ipv4.conf.default.rp_filter = 1 + >``` + + **表 3** 内核参数加固策略说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

加固项

+

加固项说明

+

加固建议

+

openEuler默认是否已加固为建议值

+

net.ipv4.icmp_echo_ignore_broadcasts

+

是否接受ICMP广播报文。加固策略为不接受。

+

1

+

+

net.ipv4.conf.all.rp_filter

+

验证数据包使用的实际源地址是否与路由表相关,以及使用该特定源IP地址的数据包是否通过接口获取其响应。加固策略为启用该项。

+

1

+

+

net.ipv4.conf.default.rp_filter

+

1

+

+

net.ipv4.ip_forward

+

IP Forwarding可阻止未授权的IP数据包渗透至网络。加固策略为禁用该特性。

+

0

+

+

net.ipv4.conf.all.accept_source_route

+

accept_source_route指允许数据包的发送者指定数据包的发送路径,以及返回给发送者的数据包所走的路径。加固策略为禁用该特性。

+

0

+

+

net.ipv4.conf.default.accept_source_route

+

0

+

+

net.ipv4.conf.all.accept_redirects

+

是否发送ICMP重定向报文。加固策略为禁止发送。

+

0

+

+

net.ipv4.conf.default.accept_redirects

+

0

+

+

net.ipv6.conf.all.accept_redirects

+

0

+

+

net.ipv6.conf.default.accept_redirects

+

0

+

+

net.ipv4.conf.all.send_redirects

+

是否将ICMP重定向报文发送至其他主机。只有当主机作为路由时,应启用该策略。加固策略为禁用该项。

+

0

+

+

net.ipv4.conf.default.send_redirects

+

0

+

+

net.ipv4.icmp_ignore_bogus_error_responses

+

忽略伪造的ICMP数据包,不会将其记录到日志,将节省大量的硬盘空间。加固策略为启用该项。

+

1

+

+

net.ipv4.tcp_syncookies

+

SYN Attack是一种通过占用系统资源迫使系统重启的DoS攻击。加固策略为开启TCP-SYN cookie保护。

+

1

+

+

kernel.dmesg_restrict

+

加固dmesg信息,仅允许管理员查看。

+

1

+

+

kernel.sched_autogroup_enabled

+

该选项决定内核是否对线程进行自动分组调度。开启后调度组之间互相竞争时间片,调度组内的线程再竞争调度组分配到的时间片。加固策略为不启用该项。

+

0

+

+

kernel.sysrq

+

禁用魔术键。

+
说明:

建议禁用魔术键,避免由于直接发送命令到内核对系统造成影响,增强内核安全性。

+
+

0

+

+

net.ipv4.conf.all.secure_redirects

+

设置系统是接收来自任何主机的ICMP重定向消息还是从默认网关列表中的网关处接收ICMP重定向消息。加固策略为采用前者。

+

0

+

+

net.ipv4.conf.default.secure_redirects

+

0

+

+
+ +2. 加载sysctl.conf文件中设置的内核参数。 + + ``` + sysctl -p /etc/sysctl.conf + ``` + + +### 其它安全建议 + +- net.ipv4.icmp\_echo\_ignore\_all:忽略ICMP请求。 + + 出于安全考虑,建议开启此项(当前默认值为0,开启将值设为1)。 + + 但开启后会忽略所有接收到的icmp echo请求的包\(会导致机器无法ping通\),建议用户根据实际组网场景决定是否开启此项。 + +- net.ipv4.conf.all.log\_martians/net.ipv4.conf.default.log\_martians:对于仿冒/源路由/重定向数据包开启日志记录。 + + 出于安全考虑,建议开启此项(当前默认值为0,开启将值设为1)。 + + 但是开启后会记录带有不允许的地址的数据到内核日志中,存在冲日志风险,建议用户根据实际使用场景决定是否开启此项。 + +- net.ipv4.tcp\_timestamps:关闭tcp\_timestamps。 + + 出于安全考虑,建议关闭tcp\_timestamps(当前默认值为1,关闭将值设为0)。 + + 但是关闭此项会影响TCP超时重发的性能,建议用户根据实际使用场景决定是否关闭此项。 + +- net.ipv4.tcp\_max\_syn\_backlog:决定了SYN\_RECV状态队列的数量。 + + 该参数决定了SYN\_RECV状态队列的数量,超过这个数量,系统将不再接受新的TCP连接请求,一定程度上可以防止系统资源耗尽。建议由用户根据实际使用场景配置合适的值。 \ No newline at end of file diff --git "a/content/zh/docs/SecHarden/\345\210\240\351\231\244\346\227\240\344\270\273\346\226\207\344\273\266.md" "b/content/zh/docs/SecHarden/\345\210\240\351\231\244\346\227\240\344\270\273\346\226\207\344\273\266.md" deleted file mode 100644 index 652d346bda4b4a7761872b718a543bf98f1d3060..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\210\240\351\231\244\346\227\240\344\270\273\346\226\207\344\273\266.md" +++ /dev/null @@ -1,38 +0,0 @@ -# 删除无主文件 - -## 说明 - -系统管理员在删除用户/群组时,存在着忘记删除该用户/该群组所拥有文件的问题。如果后续新创建的用户/群组与被删除的用户/群组同名,则新用户/新群组会拥有部分不属于其权限的文件,建议将此类文件删除。 - -## 实现 - -删除用户ID不存在的文件 - -1. 查找用户ID不存在的文件。 - - ``` - find / -nouser - ``` - -2. 删除查找到的文件。其中_filename_为用户ID不存在文件的文件名。 - - ``` - rm -f filename - ``` - - -删除群组ID不存在的文件 - -1. 查找用户ID不存在的文件。 - - ``` - find / -nogroup - ``` - -2. 删除查找到的文件。其中_filename_为用户ID不存在文件的文件名。 - - ``` - rm -f filename - ``` - - diff --git "a/content/zh/docs/SecHarden/\345\210\240\351\231\244\351\235\236\346\216\210\346\235\203\346\226\207\344\273\266\347\232\204\345\205\250\345\261\200\345\217\257\345\206\231\345\261\236\346\200\247.md" "b/content/zh/docs/SecHarden/\345\210\240\351\231\244\351\235\236\346\216\210\346\235\203\346\226\207\344\273\266\347\232\204\345\205\250\345\261\200\345\217\257\345\206\231\345\261\236\346\200\247.md" deleted file mode 100644 index 591ecf7880213098c33f7b869f89ae370237302e..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\210\240\351\231\244\351\235\236\346\216\210\346\235\203\346\226\207\344\273\266\347\232\204\345\205\250\345\261\200\345\217\257\345\206\231\345\261\236\346\200\247.md" +++ /dev/null @@ -1,27 +0,0 @@ -# 删除非授权文件的全局可写属性 - -## 说明 - -全局可写文件可被系统中的任意用户修改,影响系统完整性。 - -## 实现 - -1. 列举系统中所有的全局可写文件。 - - ``` - find / -type d \( -perm -o+w \) | grep -v procfind / -type f \( -perm -o+w \) | grep -v proc - ``` - -2. 查看步骤1列举的所有文件\(粘滞位位的文件和目录可以排除在外\),删除文件或去掉其全局可写权限。使用以下命令去掉权限,其中_filename_为对应文件名: - - ``` - chmod o-w filename - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >可通过如下命令确定对应文件或目录是否设置了粘滞位,若回显中包含T标记,则为粘滞位文件或目录。命令中的_filename_为需要查询文件或目录的名称。 - >``` - >ls -l filename - >``` - - diff --git "a/content/zh/docs/SecHarden/\345\211\215\350\250\200.md" "b/content/zh/docs/SecHarden/\345\211\215\350\250\200.md" deleted file mode 100644 index 3d3ab6ce6a2f9367220c72ffb97a56e7075af6b6..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\211\215\350\250\200.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 前言 - -## 概述 - -本文档给出openEuler的加固介绍和加固方法,指导用户进行安全加固。 - -## 读者对象 - -本文档主要适用于需要对openEuler进行安全加固的管理员。管理员需要熟悉操作系统安全架构和安全技术。 - -## 符号约定 - -在本文中可能出现下列标志,它们所代表的含义如下。 - - - - - - - - - - - - - -

符号

-

说明

-

-

用于传递设备或环境安全警示信息。如不避免则可能会导致设备损坏、数据丢失、设备性能降低或其它不可预知的结果。

-

“须知”不涉及人身伤害。

-

-

对正文中重点信息的补充说明。

-

“说明”不是安全警示信息,不涉及人身、设备及环境伤害信息。

-
- diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272SSH\346\234\215\345\212\241.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272SSH\346\234\215\345\212\241.md" deleted file mode 100644 index b08a41192b438176ae6125503a5d089e77d45138..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272SSH\346\234\215\345\212\241.md" +++ /dev/null @@ -1,471 +0,0 @@ -# 加固SSH服务 - -## 说明 - -SSH(Secure Shell)是目前较可靠,专为远程登录会话和其他网络服务提供安全性保障的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。透过SSH可以对所有传输的数据进行加密,并防止DNS欺骗和IP欺骗。OpenSSH是SSH协议的免费开源实现。 - -加固SSH服务,是指修改SSH服务中的配置来设置系统使用OpenSSH协议时的算法、认证等参数,从而提高系统的安全性。[表1](#zh-cn_topic_0152100390_ta2fdb8e4931b4c1a8f502b3c7d887b95)中详细说明了各加固项含义、建议加固值及其默认策略。 - -## 实现 - -服务端加固操作如下: - -1. 打开服务端SSH服务的配置文件/etc/ssh/sshd\_config,在该文件中修改或添加对应加固项及其加固值。 -2. 保存/etc/ssh/sshd\_config文件。 -3. 重启SSH服务,命令如下: - - ``` - systemctl restart sshd - ``` - - -客户端加固操作如下: - -1. 打开客户端SSH服务的配置文件/etc/ssh/ssh\_config,在该文件中修改或添加对应加固项及其加固值。 -2. 保存/etc/ssh/ssh\_config文件。 -3. 重启SSH服务,命令如下: - - ``` - systemctl restart sshd - ``` - - -## 加固项说明 - -- 服务端加固策略 - - SSH服务的所有加固项均保存在配置文件/etc/ssh/sshd\_config中,服务端各加固项的含义、加固建议以及openEuler默认是否已经加固为建议加固值请参见[表1](#zh-cn_topic_0152100390_ta2fdb8e4931b4c1a8f502b3c7d887b95)。 - - **表 1** SSH服务端加固项说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

加固项

-

加固项说明

-

加固建议

-

openEuler默认是否已加固为建议值

-

Protocol

-

设置使用SSH协议的版本

-

2

-

-

SyslogFacility

-

设置SSH服务的日志类型。加固策略将其设置为“AUTH”,即认证类日志

-

AUTH

-

-

LogLevel

-

设置记录sshd日志消息的层次

-

VERBOSE

-

-

X11Forwarding

-

设置使用SSH登录后,能否使用图形化界面

-

no

-

-

MaxAuthTries

-

最大认证尝试次数

-

3

-

-

PubkeyAuthentication

-

设置是否允许公钥认证。

-

yes

-

-

RSAAuthentication

-

设置是否允许只有RSA安全验证

-

yes

-

-

IgnoreRhosts

-

设置是否使用rhosts文件和shosts文件进行验证。rhosts文件和shosts文件用于记录可以访问远程计算机的计算机名及关联的登录名

-

yes

-

-

RhostsRSAAuthentication

-

设置是否使用基于rhosts的RSA算法安全验证。rhosts文件记录可以访问远程计算机的计算机名及关联的登录名

-

no

-

-

HostbasedAuthentication

-

设置是否使用基于主机的验证。基于主机的验证是指已信任客户机上的任何用户都可以使用SSH连接

-

no

-

-

PermitRootLogin

-

-

是否允许root账户直接使用SSH登录系统

-
说明:

若需要直接使用root账户通过SSH登录系统,请修改/etc/ssh/sshd_config文件的PermitRootLogin字段的值为yes。

-
-

no

-

-

PermitEmptyPasswords

-

设置是否允许用口令为空的账号登录

-

no

-

-

PermitUserEnvironment

-

设置是否解析 ~/.ssh/environment和~/.ssh/authorized_keys中设定的环境变量

-

no

-

-

Ciphers

-

设置SSH数据传输的加密算法

-

aes128-ctr,aes192-ctr,aes256-ctr,chacha20-poly1305@openssh.com,aes128-gcm@openssh.com,aes256-gcm@openssh.com

-

-

ClientAliveInterval

-

设置系统等待的超时时间(单位秒)。超过指定时间未收到来自客户端的数据,则断开连接

-

300

-

-

ClientAliveCountMax

-

设置超时次数。服务器发出请求后,客户端没有响应的次数达到一定值,连接自动断开

-

0

-

-

Banner

-

指定登录SSH前后显示的提示信息的文件

-

/etc/issue.net

-

-

MACs

-

设置SSH数据校验的哈希算法

-

hmac-sha2-512,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-256-etm@openssh.com,hmac-sha1,hmac-sha1-etm@openssh.com

-

-

StrictModes

-

设置SSH在接收登录请求之前是否检查用户HOME目录和rhosts文件的权限和所有权

-

yes

-

-

UsePAM

-

使用PAM登录认证

-

yes

-

-

AllowTcpForwarding

-

设置是否允许TCP转发

-

no

-

-

Subsystem sftp /usr/libexec/openssh/sftp-server

-

sftp日志记录级别,记录INFO级别以及认证日志。

-

-l INFO -f AUTH

-

-

AllowAgentForwarding

-

设置是否允许SSH Agent转发

-

no

-

-

GatewayPorts

-

设置是否允许连接到转发客户端端口

-

no

-

-

PermitTunnel

-

Tunnel设备是否允许使用

-

no

-

-

KexAlgorithms

-

设置SSH密钥交换算法

-

curve25519-sha256,curve25519-sha256@@libssh.org,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256

-
  

LoginGraceTime

-

限制用户必须在指定的时限内认证成功,0 表示无限制。默认值是 60 秒。

-

60

-

-
- - >![](public_sys-resources/icon-note.gif) **说明:** - >默认情况下,登录SSH前后显示的提示信息保存在/etc/issue.net文件中,/etc/issue.net默认信息为“Authorized users only. All activities may be monitored and reported.”。 - - -- 客户端加固策略 - - SSH服务的所有加固项均保存在配置文件/etc/ssh/ssh\_config中,客户端各加固项的含义、加固建议以及openEuler默认是否已经加固为建议加固值请参见[表2](#zh-cn_topic_0152100390_tb289c5a6f1c7420ab4339187f9018ea4)。 - - **表 2** SSH客户端加固项说明 - - - - - - - - - - - - - - - - - - - -

加固项

-

加固项说明

-

加固建议

-

openEuler默认是否已加固为建议值

-

KexAlgorithms

-

设置SSH密钥交换算法

-

ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1

-

-

VerifyHostKeyDNS

-

是否使用DNS或者SSHFP资源记录验证HostKey

-

ask

-

-
- - >![](public_sys-resources/icon-note.gif) **说明:** - >对于使用dh算法进行密钥交换的第三方客户端和服务端工具,要求允许建立连接的最低长度为2048bits。 - - -## 其他安全建议 - -- SSH服务仅侦听指定IP地址 - - 出于安全考虑,建议用户在使用SSH服务时,仅在必需的IP上进行绑定侦听,而不是侦听0.0.0.0,可修改/etc/ssh/sshd\_config文件中的ListenAddress配置项。 - - 1. 打开并修改/etc/ssh/sshd\_config文件 - - ``` - vi /etc/ssh/sshd_config - ``` - - 修改内容如下,表示绑定侦听IP为 _192.168.1.100_,用户可根据实际情况修改需要侦听的IP - - ``` - ... - ListenAddress 192.168.1.100 - ... - ``` - - 2. 重启SSH服务 - - ``` - systemctl restart sshd.service - ``` - - - -- 限制SFTP用户向上跨目录访问 - - SFTP是FTP over SSH的安全FTP协议,对于访问SFTP的用户建议使用专用账号,只能上传或下载文件,不能用于SSH登录,同时对SFTP可以访问的目录进行限定,防止目录遍历攻击,具体配置如下: - - >![](public_sys-resources/icon-note.gif) **说明:** - >sftpgroup为示例用户组,sftpuser为示例用户名。 - - 1. 创建SFTP用户组 - - ``` - groupadd sftpgroup - ``` - - 2. 创建SFTP根目录 - - ``` - mkdir /sftp - ``` - - 3. 修改SFTP根目录属主和权限 - - ``` - chown root:root /sftp - chmod 755 /sftp - ``` - - 4. 创建SFTP用户 - - ``` - useradd -g sftpgroup -s /sbin/nologin sftpuser - ``` - - 5. 设置SFTP用户的口令 - - ``` - passwd sftpuser - ``` - - 6. 创建SFTP用户上传目录 - - ``` - mkdir /sftp/sftpuser - ``` - - 7. 修改SFTP用户上传目录属主和权限 - - ``` - chown root:root /sftp/sftpuser - chmod 777 /sftp/sftpuser - ``` - - 8. 修改/etc/ssh/sshd\_config文件 - - ``` - vi /etc/ssh/sshd_config - ``` - - 修改内容如下: - - ``` - #Subsystem sftp /usr/libexec/openssh/sftp-server -l INFO -f AUTH - Subsystem sftp internal-sftp -l INFO -f AUTH - ... - - Match Group sftpgroup - ChrootDirectory /sftp/%u - ForceCommand internal-sftp - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >- %u代表当前sftp用户的用户名,这是一个通配符,用户原样输入即可。 - >- 以下内容必须加在/etc/ssh/sshd\_config文件的末尾。 - > ``` - > Match Group sftpgroup - > ChrootDirectory /sftp/%u - > ForceCommand internal-sftp - > ``` - - 9. 重启SSH服务 - - ``` - systemctl restart sshd.service - ``` - - - -- SSH远程执行命令 - - OpenSSH通用机制,在远程执行命令时,默认不开启tty,如果执行需要密码的命令,密码会明文回显。出于安全考虑,建议用户增加-t选项,确保密码输入安全。如下: - - ``` - ssh -t testuser@192.168.1.100 su - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >192.168.1.100为示例IP,testuser为示例用户。 - - diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272su\345\221\275\344\273\244.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272su\345\221\275\344\273\244.md" deleted file mode 100644 index 1edfdd6c61564b0cbbc350a1d1eb9c5a0d92a50f..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272su\345\221\275\344\273\244.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 加固su命令 - -## 说明 - -为了增强系统安全性,防止使用“su”切换用户时将当前用户环境变量带入其他环境,openEuler默认已做配置。总是在使用su切换用户时初始化PATH。 - -## 实现 - -通过修改/etc/login.defs实现,配置如下: - -``` -ALWAYS_SET_PATH=yes -``` - diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\345\206\205\346\240\270\345\217\202\346\225\260.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\345\206\205\346\240\270\345\217\202\346\225\260.md" deleted file mode 100644 index a7e64a825c0cd83989ad45be3fa75624966784ae..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\345\206\205\346\240\270\345\217\202\346\225\260.md" +++ /dev/null @@ -1,225 +0,0 @@ -# 加固内核参数 - -## 说明 - -内核参数决定配置和应用特权的状态。内核提供用户可配置的系统控制,这一系统控制可微调或配置,该功能特性可通过控制各种可配置的内核参数,来提高操作系统的安全特性。比如:通过微调或配置网络选项,可有效提高系统的安全性。 - -## 实现 - -1. 将[表1](#zh-cn_topic_0152100187_t69b5423c26644b26abe94d88d38878eb)中的加固项写入/etc/sysctl.conf文件中。 - - >![](public_sys-resources/icon-note.gif) **说明:** - >写入方式如下: - >``` - >net.ipv4.icmp_echo_ignore_broadcasts = 1 - >net.ipv4.conf.all.rp_filter = 1 - >net.ipv4.conf.default.rp_filter = 1 - >``` - - **表 1** 内核参数加固策略说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

加固项

-

加固项说明

-

加固建议

-

openEuler默认是否已加固为建议值

-

net.ipv4.icmp_echo_ignore_broadcasts

-

是否接受ICMP广播报文。加固策略为不接受。

-

1

-

-

net.ipv4.conf.all.rp_filter

-

验证数据包使用的实际源地址是否与路由表相关,以及使用该特定源IP地址的数据包是否通过接口获取其响应。加固策略为启用该项。

-

1

-

-

net.ipv4.conf.default.rp_filter

-

1

-

-

net.ipv4.ip_forward

-

IP Forwarding可阻止未授权的IP数据包渗透至网络。加固策略为禁用该特性。

-

0

-

-

net.ipv4.conf.all.accept_source_route

-

accept_source_route指允许数据包的发送者指定数据包的发送路径,以及返回给发送者的数据包所走的路径。加固策略为禁用该特性。

-

0

-

-

net.ipv4.conf.default.accept_source_route

-

0

-

-

net.ipv4.conf.all.accept_redirects

-

是否发送ICMP重定向报文。加固策略为禁止发送。

-

0

-

-

net.ipv4.conf.default.accept_redirects

-

0

-

-

net.ipv6.conf.all.accept_redirects

-

0

-

-

net.ipv6.conf.default.accept_redirects

-

0

-

-

net.ipv4.conf.all.send_redirects

-

是否将ICMP重定向报文发送至其他主机。只有当主机作为路由时,应启用该策略。加固策略为禁用该项。

-

0

-

-

net.ipv4.conf.default.send_redirects

-

0

-

-

net.ipv4.icmp_ignore_bogus_error_responses

-

忽略伪造的ICMP数据包,不会将其记录到日志,将节省大量的硬盘空间。加固策略为启用该项。

-

1

-

-

net.ipv4.tcp_syncookies

-

SYN Attack是一种通过占用系统资源迫使系统重启的DoS攻击。加固策略为开启TCP-SYN cookie保护。

-

1

-

-

kernel.dmesg_restrict

-

加固dmesg信息,仅允许管理员查看。

-

1

-

-

kernel.sched_autogroup_enabled

-

该选项决定内核是否对线程进行自动分组调度。开启后调度组之间互相竞争时间片,调度组内的线程再竞争调度组分配到的时间片。加固策略为不启用该项。

-

0

-

-

kernel.sysrq

-

禁用魔术键。

-
说明:

建议禁用魔术键,避免由于直接发送命令到内核对系统造成影响,增强内核安全性。

-
-

0

-

-

net.ipv4.conf.all.secure_redirects

-

设置系统是接收来自任何主机的ICMP重定向消息还是从默认网关列表中的网关处接收ICMP重定向消息。加固策略为采用前者。

-

0

-

-

net.ipv4.conf.default.secure_redirects

-

0

-

-
- -2. 加载sysctl.conf文件中设置的内核参数。 - - ``` - sysctl -p /etc/sysctl.conf - ``` - - -## 其它安全建议 - -- net.ipv4.icmp\_echo\_ignore\_all:忽略ICMP请求。 - - 出于安全考虑,建议开启此项(当前默认值为0,开启将值设为1)。 - - 但开启后会忽略所有接收到的icmp echo请求的包\(会导致机器无法ping通\),建议用户根据实际组网场景决定是否开启此项。 - -- net.ipv4.conf.all.log\_martians/net.ipv4.conf.default.log\_martians:对于仿冒/源路由/重定向数据包开启日志记录。 - - 出于安全考虑,建议开启此项(当前默认值为0,开启将值设为1)。 - - 但是开启后会记录带有不允许的地址的数据到内核日志中,存在冲日志风险,建议用户根据实际使用场景决定是否开启此项。 - -- net.ipv4.tcp\_timestamps:关闭tcp\_timestamps。 - - 出于安全考虑,建议关闭tcp\_timestamps(当前默认值为1,关闭将值设为0)。 - - 但是关闭此项会影响TCP超时重发的性能,建议用户根据实际使用场景决定是否关闭此项。 - -- net.ipv4.tcp\_max\_syn\_backlog:决定了SYN\_RECV状态队列的数量。 - - 该参数决定了SYN\_RECV状态队列的数量,超过这个数量,系统将不再接受新的TCP连接请求,一定程度上可以防止系统资源耗尽。建议由用户根据实际使用场景配置合适的值。 - - diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\345\275\261\345\223\215.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\345\275\261\345\223\215.md" deleted file mode 100644 index 7077598e872caa9289e00d09f62607f52a08d9cd..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\345\275\261\345\223\215.md" +++ /dev/null @@ -1,94 +0,0 @@ -# 加固影响 - -对文件权限、账户口令等安全加固,可能造成用户使用习惯变更,从而影响系统的易用性。影响系统易用性的常见加固项请参见[表1](#zh-cn_topic_0152100325_ta4a48f54ff2849ada7845e2380209917)。 - -**表 1** 加固影响说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

加固项

-

建议加固

-

易用性影响

-

openEuler默认是否设置了该加固项

-

字符界面等待超时限制

-

当字符界面长时间处在空闲状态,字符界面会自动退出。

-
说明:

当用户通过SSH登录,超时时间由/etc/profile文件的TMOUT字段和/etc/ssh/sshd_config文件的ClientAliveInterval字段两个值中较小的值决定。建议加固为300秒。

-
-

用户长时间不操作字符界面,字符界面会自动退出。

-

-

口令复杂度限制

-

口令长度最小为8位,口令至少包含大写字母、小写字母、数字和特殊字符中的3种。

-

系统中所有用户不能设置简单的口令,口令必须符合复杂度要求。

-

-

限定登录失败时的尝试次数

-

当用户登录系统时,口令连续输错3次,账户将被锁定60秒,锁定期间不能登录系统。

-

用户不能随意登录系统,账户被锁定后必须等待60秒。

-

-

用户默认umask值限制

-

设置所有用户的默认umask值为077,使用户创建文件的默认权限为600、目录权限为700。

-

用户需要按照需求修改指定文件或目录的权限。

-

-

口令有效期

-

口令有效期的设置通过修改/etc/login.defs文件实现,加固默认值为口令最大有效期90天,两次修改口令的最小间隔时间为0,口令过期前开始提示天数为7。

-

口令过期后用户重新登录时,提示口令过期并强制要求修改,不修改则无法进入系统。

-

-

su权限限制

-

su命令用于在不同账户之间切换。为了增强系统安全性,有必要对su命令的使用权进行控制,只允许root和wheel群组的账户使用su命令,限制其他账户使用。

-

普通账户执行su命令失败,必须加入wheel群组才可以su成功。

-

-

禁止root账户直接SSH登录系统

-

设置/etc/ssh/sshd_config文件的PermitRootLogin字段的值为no,用户无法使用root账户直接SSH登录系统。

-

用户需要先使用普通账户SSH登录后,再切换至root账户。

-

-

SSH强加密算法

-

SSH服务的MACs和Ciphers配置,禁止对CBC、MD5、SHA1算法的支持,修改为CTR、SHA2算法。

-

当前windows下使用的部分低版本的Xshell、PuTTY不支持aes128-ctr、aes192-ctr、aes256-ctr、hmac-sha2-256、hmac-sha2-512算法,可能会出现无法通过SSH登录系统的情况,请使用最新的PuTTY(0.63版本以上)、Xshell(5.0版本及以上版本)登录。

-

-
- diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\214\207\345\257\274.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\214\207\345\257\274.md" index 7c77a99bf444381d6054257dbb8cc27f5a9f2ab9..b2a8312d288f8bba8cd72b1239b61126b0875887 100644 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\214\207\345\257\274.md" +++ "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\214\207\345\257\274.md" @@ -1,4 +1,5 @@ -# 加固指导 +# 加固指导 用户可以通过修改加固策略配置文件或加固脚本进行系统加固。本节介绍各加固项的含义以及openEuler是否已默认加固,并给出加固方法,指导用户进行安全加固。 + diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\223\215\344\275\234.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\223\215\344\275\234.md" deleted file mode 100644 index c245a861a11bef31edd6ace0aa3d8fde061abab8..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\223\215\344\275\234.md" +++ /dev/null @@ -1,115 +0,0 @@ -# 加固操作 - -## 概述 - -安全加固工具会根据usr-security.conf设置加固策略,使用加固工具设置加固策略需要用户修改usr-security.conf。本节介绍usr-security.conf的修改规则。用户可配置的加固项请参见[加固指导](加固指导.md)对应内容。 - -## 注意事项 - -- 修改配置后,需要重启安全加固服务使配置生效。重启方法请参见[加固生效](加固生效.md)对应内容。 -- 用户修改加固配置时,仅修改/etc/openEuler\_security/usr-security.conf文件,不建议修改/etc/openEuler\_security/security.conf。security.conf中为基本加固项,仅运行一次。 -- 当重启安全加固服务使配置生效后,在usr-security.conf中删除对应加固项并重启安全加固服务并不能清除之前的配置。 -- 安全加固操作记录在日志文件/var/log/openEuler-security.log中。 - -## 配置格式 - -usr-security.conf中的每一行代表一项配置,根据配置内容的不同有不同配置格式,这里给出各类配置的格式说明。 - ->![](public_sys-resources/icon-note.gif) **说明:** ->- 所有配置项以执行ID开头,执行ID仅为了方便用户识别配置内容,取值为正整数,由用户自行定义。 ->- 配置项的各内容之间使用@作为分隔符。 ->- 若实际配置内容中包含@,需要使用@@表示以和分隔符区分,例如实际内容为xxx@yyy,则配置为xxx@@yyy。目前不支持@位于配置内容的开头和结尾。 - -- d:注释 - - 格式:执行ID@d@对象文件@匹配项 - - 功能:将对象文件中以匹配项开头(行首可以有空格)的行注释(在行首添加\#)。 - - 示例:执行ID为401,注释/etc/sudoers文件中以%wheel开头的行。 - - ``` - 401@d@/etc/sudoers@%wheel - ``` - - -- m:替换 - - 格式:执行ID@m@对象文件@匹配项@替换目标值 - - 功能:将对象文件中以匹配项开头(行首可以有空格)的行替换为“匹配项加替换目标值 ”。若匹配行开头有空格,替换后将删除这些空格。 - - 示例:执行ID为101,将/etc/ssh/sshd\_config文件中以Protocol 开头的行替换为Protocol 2。匹配和替换时也会考虑Protocol后的空格。 - - ``` - 101@m@/etc/ssh/sshd_config@Protocol @2 - ``` - -- sm:精确修改 - - 格式:执行ID@sm@对象文件@匹配项@替换目标值 - - 功能:将对象文件中以匹配项开头(行首可以有空格)的行替换为“匹配项加替换目标值 ”。若匹配行开头有空格,替换后将保留这些空格,这是sm和m的区别。 - - 示例:执行ID为201,将/etc/audit/hzqtest文件中以size开头的行替换为size 2048。 - - ``` - 201@sm@/etc/audit/hzqtest@size @2048 - ``` - - -- M:修改子项 - - 格式:执行ID@M@对象文件@匹配项@匹配子项\[@匹配子项的值\] - - 功能:匹配对象文件中以匹配项开头(行首可以有空格)的行,并将该行中以匹配子项开始的内容替换为“匹配子项和匹配子项的值”,其中匹配子项的值可选。 - - 示例:执行ID为101,找到file文件中以key开头的行,并将这些行中以key2开始的内容替换为key2value2。 - - ``` - 101@M@file@key@key2@value2 - ``` - -- systemctl:管理服务 - - 格式:执行ID@systemctl@对象服务@具体操作 - - 功能:使用systemctl管理对象服务,具体操作可取值为start、stop、restart、disable等systemctl所有可用的命令。 - - 示例:执行ID为218,停止cups.service服务,等同于systemctl stop cups.service的配置行。 - - ``` - 218@systemctl @cups.service@stop - ``` - -- 其他命令 - - 格式:执行ID@命令@对象文件 - - 功能:执行对应命令,即执行命令行“命令 对象文件”。 - - 示例一:执行ID为402,使用rm -f命令删除文件/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem。 - - ``` - 402@rm -f @/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem - ``` - - 示例二:执行ID为215,使用touch命令创建文件/etc/cron.allow。 - - ``` - 215@touch @/etc/cron.allow - ``` - - 示例三:执行ID为214,使用chown命令将文件/etc/at.allow的属主改为root:root。 - - ``` - 214@chown root:root @/etc/at.allow - ``` - - 示例四:执行ID为214,使用chmod命令去除文件/etc/at.allow属主所在群组及其他非属主用户的rwx权限。 - - ``` - 214@chmod og-rwx @/etc/at.allow - ``` - - diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\226\271\346\241\210.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\226\271\346\241\210.md" deleted file mode 100644 index fac8853801902bb9d8f4453576d21f59fd9e9007..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\346\226\271\346\241\210.md" +++ /dev/null @@ -1,20 +0,0 @@ -# 加固方案 - -本章描述openEuler的安全加固方案,包括加固方式和加固内容。 - -## 加固方式 - -用户可以通过手动修改加固配置或执行相关命令对系统进行加固,也可以通过加固工具批量修改加固项。openEuler的安全加固工具security tool以openEuler-security.service服务的形式运行。系统首次启动时会自动运行该服务去执行默认加固策略,且自动设置后续开机不启动该服务。 - -用户可以通过修改security.conf,使用安全加固工具实现个性化安全加固的效果。 - -## 加固内容 - -openEuler系统加固内容主要分为以下5个部分: - -- 系统服务 -- 文件权限 -- 内核参数 -- 授权认证 -- 账号口令 - diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\347\224\237\346\225\210.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\347\224\237\346\225\210.md" deleted file mode 100644 index f27767b47915a86142772a73d8341c4a18e2ea38..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\347\224\237\346\225\210.md" +++ /dev/null @@ -1,8 +0,0 @@ -# 加固生效 - -完成修改usr-security.conf文件后,请运行如下命令使新添加的配置生效。 - -``` -systemctl restart openEuler-security.service -``` - diff --git "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\347\233\256\347\232\204.md" "b/content/zh/docs/SecHarden/\345\212\240\345\233\272\347\233\256\347\232\204.md" deleted file mode 100644 index a61f1d3a1f81c6e307f8135e3edf8484fa0a2238..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\212\240\345\233\272\347\233\256\347\232\204.md" +++ /dev/null @@ -1,6 +0,0 @@ -# 加固目的 - -操作系统作为信息系统的核心,承担着管理硬件资源和软件资源的重任,是整个信息系统安全的基础。操作系统之上的各种应用,要想获得信息的完整性、机密性、可用性和可控性,必须依赖于操作系统。脱离了对操作系统的安全保护,仅依靠其他层面的防护手段来阻止黑客和病毒等对网络信息系统的攻击,是无法满足安全需求的。 - -因此,需要对操作系统进行安全加固,构建动态、完整的安全体系,增强产品的安全性,提升产品的竞争力。 - diff --git "a/content/zh/docs/SecHarden/\345\244\204\347\220\206\347\251\272\351\223\276\346\216\245\346\226\207\344\273\266.md" "b/content/zh/docs/SecHarden/\345\244\204\347\220\206\347\251\272\351\223\276\346\216\245\346\226\207\344\273\266.md" deleted file mode 100644 index 1a5daef47743469e7a64acd3dc17d0104bd8384d..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\244\204\347\220\206\347\251\272\351\223\276\346\216\245\346\226\207\344\273\266.md" +++ /dev/null @@ -1,33 +0,0 @@ -# 处理空链接文件 - -## 说明 - -无指向的空链接文件,可能会被恶意用户利用,影响系统安全性。建议用户删除无效的空链接文件,提高系统安全性。 - -## 特殊场景 - -openEuler系统安装完成后,可能存在空链接文件,这些空链接文件可能有对应用途(有些空链接文件是预制的,会被其他组件依赖)。请用户根据实际环境进行处理,处理方式请参见[实现](#zh-cn_topic_0152100319_s1b24647cdd834a8eaca3032611baf072)。 - -例如,openEuler支持UEFI和legacy BIOS两种安装模式,两种引导场景支持的grub相关包默认都安装,当用户选择legacy BIOS模式安装时,形成空链接文件“/etc/grub2-efi.cfg”;当用户选择UEFI模式安装时,会形成空链接文件“/etc/grub2.cfg”,需要用户根据实际情况处理空链接。 - -## 实现 - -1. 通过如下命令查找系统中的空链接文件。 - - ``` - find dirname -type l -follow 2>/dev/null - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >_dir__name_为搜索目录的名称,通常需要关注系统关键目录:/bin、/boot、/usr、/lib64、/lib、/var等。 - -2. 如果此类文件无实际作用,可通过如下命令删除。 - - ``` - rm -f filename - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >_filename_为[步骤1](#zh-cn_topic_0152100319_l4dc74664c4fb400aaf91fb314c4f9da6)找出的文件名。 - - diff --git "a/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\212\240\345\233\272\345\267\245\345\205\267.md" "b/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\212\240\345\233\272\345\267\245\345\205\267.md" index 2bbdb274f843fe32099daf861205cdc5f70abff5..2d2de8ab659f0c7990af9a9c117d2a50ffdf5e7a 100644 --- "a/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\212\240\345\233\272\345\267\245\345\205\267.md" +++ "b/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\212\240\345\233\272\345\267\245\345\205\267.md" @@ -1 +1,131 @@ -# 安全加固工具 +# 安全加固工具 + + +- [安全加固工具](#安全加固工具) + - [加固操作](#加固操作) + - [加固生效](#加固生效) + + +## 加固操作 + +### 概述 + +安全加固工具会根据usr-security.conf设置加固策略,使用加固工具设置加固策略需要用户修改usr-security.conf。本节介绍usr-security.conf的修改规则。用户可配置的加固项请参见[加固指导](https://openeuler.org/zh/docs/20.03_LTS/docs/SecHarden/%E5%8A%A0%E5%9B%BA%E6%8C%87%E5%AF%BC.html)对应内容。 + +### 注意事项 + +- 修改配置后,需要重启安全加固服务使配置生效。重启方法请参见[加固生效](#加固生效)对应内容。 +- 用户修改加固配置时,仅修改/etc/openEuler\_security/usr-security.conf文件,不建议修改/etc/openEuler\_security/security.conf。security.conf中为基本加固项,仅运行一次。 +- 当重启安全加固服务使配置生效后,在usr-security.conf中删除对应加固项并重启安全加固服务并不能清除之前的配置。 +- 安全加固操作记录在日志文件/var/log/openEuler-security.log中。 + +### 配置格式 + +usr-security.conf中的每一行代表一项配置,根据配置内容的不同有不同配置格式,这里给出各类配置的格式说明。 + +>![](public_sys-resources/icon-note.gif) **说明:** +>- 所有配置项以执行ID开头,执行ID仅为了方便用户识别配置内容,取值为正整数,由用户自行定义。 +>- 配置项的各内容之间使用@作为分隔符。 +>- 若实际配置内容中包含@,需要使用@@表示以和分隔符区分,例如实际内容为xxx@yyy,则配置为xxx@@yyy。目前不支持@位于配置内容的开头和结尾。 + +- d:注释 + + 格式:执行ID@d@对象文件@匹配项 + + 功能:将对象文件中以匹配项开头(行首可以有空格)的行注释(在行首添加\#)。 + + 示例:执行ID为401,注释/etc/sudoers文件中以%wheel开头的行。 + + ``` + 401@d@/etc/sudoers@%wheel + ``` + + +- m:替换 + + 格式:执行ID@m@对象文件@匹配项@替换目标值 + + 功能:将对象文件中以匹配项开头(行首可以有空格)的行替换为“匹配项加替换目标值 ”。若匹配行开头有空格,替换后将删除这些空格。 + + 示例:执行ID为101,将/etc/ssh/sshd\_config文件中以Protocol 开头的行替换为Protocol 2。匹配和替换时也会考虑Protocol后的空格。 + + ``` + 101@m@/etc/ssh/sshd_config@Protocol @2 + ``` + +- sm:精确修改 + + 格式:执行ID@sm@对象文件@匹配项@替换目标值 + + 功能:将对象文件中以匹配项开头(行首可以有空格)的行替换为“匹配项加替换目标值 ”。若匹配行开头有空格,替换后将保留这些空格,这是sm和m的区别。 + + 示例:执行ID为201,将/etc/audit/hzqtest文件中以size开头的行替换为size 2048。 + + ``` + 201@sm@/etc/audit/hzqtest@size @2048 + ``` + + +- M:修改子项 + + 格式:执行ID@M@对象文件@匹配项@匹配子项\[@匹配子项的值\] + + 功能:匹配对象文件中以匹配项开头(行首可以有空格)的行,并将该行中以匹配子项开始的内容替换为“匹配子项和匹配子项的值”,其中匹配子项的值可选。 + + 示例:执行ID为101,找到file文件中以key开头的行,并将这些行中以key2开始的内容替换为key2value2。 + + ``` + 101@M@file@key@key2@value2 + ``` + +- systemctl:管理服务 + + 格式:执行ID@systemctl@对象服务@具体操作 + + 功能:使用systemctl管理对象服务,具体操作可取值为start、stop、restart、disable等systemctl所有可用的命令。 + + 示例:执行ID为218,停止cups.service服务,等同于systemctl stop cups.service的配置行。 + + ``` + 218@systemctl @cups.service@stop + ``` + +- 其他命令 + + 格式:执行ID@命令@对象文件 + + 功能:执行对应命令,即执行命令行“命令 对象文件”。 + + 示例一:执行ID为402,使用rm -f命令删除文件/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem。 + + ``` + 402@rm -f @/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem + ``` + + 示例二:执行ID为215,使用touch命令创建文件/etc/cron.allow。 + + ``` + 215@touch @/etc/cron.allow + ``` + + 示例三:执行ID为214,使用chown命令将文件/etc/at.allow的属主改为root:root。 + + ``` + 214@chown root:root @/etc/at.allow + ``` + + 示例四:执行ID为214,使用chmod命令去除文件/etc/at.allow属主所在群组及其他非属主用户的rwx权限。 + + ``` + 214@chmod og-rwx @/etc/at.allow + ``` + + +## 加固生效 + +完成修改usr-security.conf文件后,请运行如下命令使新添加的配置生效。 + +``` +systemctl restart openEuler-security.service +``` + diff --git "a/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\215\225\347\224\250\346\210\267\346\250\241\345\274\217.md" "b/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\215\225\347\224\250\346\210\267\346\250\241\345\274\217.md" deleted file mode 100644 index 08c9a8fdb8662125e4ab0cec5254195872278eb7..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\256\211\345\205\250\345\215\225\347\224\250\346\210\267\346\250\241\345\274\217.md" +++ /dev/null @@ -1,10 +0,0 @@ -# 安全单用户模式 - -## 说明 - -单用户模式是以root权限进入系统,如不设置密码,将存在较大安全隐患。 - -## 实现 - -该设置可以通过修改/etc/sysconfig/init文件内容实现。将SINGLE选项配置为SINGLE=/sbin/sulogin。 - diff --git "a/content/zh/docs/SecHarden/\345\261\217\350\224\275\347\263\273\347\273\237\345\270\220\346\210\267.md" "b/content/zh/docs/SecHarden/\345\261\217\350\224\275\347\263\273\347\273\237\345\270\220\346\210\267.md" deleted file mode 100644 index 29d976c6f70f30899cd8cd6721a138bcc164bdda..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\345\261\217\350\224\275\347\263\273\347\273\237\345\270\220\346\210\267.md" +++ /dev/null @@ -1,17 +0,0 @@ -# 屏蔽系统帐户 - -## 说明 - -除了用户帐户外,其他账号称为系统账户。系统账户仅系统内部使用,禁止用于登录系统或其他操作,因此屏蔽系统账户。 - -## 实现 - -将系统帐户的Shell修改为/sbin/nologin。 - -``` -usermod -L -s /sbin/nologin $systemaccount -``` - ->![](public_sys-resources/icon-note.gif) **说明:** ->_$systemaccount_指系统帐户。 - diff --git "a/content/zh/docs/SecHarden/\346\216\210\346\235\203\350\256\244\350\257\201.md" "b/content/zh/docs/SecHarden/\346\216\210\346\235\203\350\256\244\350\257\201.md" index c8cd8276a10036ec553102dcd1e78611558bd30f..f2024ab02475f3e818d1a5b20c0524ab3ca02dab 100644 --- "a/content/zh/docs/SecHarden/\346\216\210\346\235\203\350\256\244\350\257\201.md" +++ "b/content/zh/docs/SecHarden/\346\216\210\346\235\203\350\256\244\350\257\201.md" @@ -1,3 +1,155 @@ -# 授权认证 +# 授权认证 +- [授权认证](#授权认证) + - [设置网络远程登录的警告信息](#设置网络远程登录的警告信息) + - [禁止通过Ctrl+Alt+Del重启系统](#禁止通过Ctrl+Alt+Del重启系统) + - [设置终端的自动退出时间](#设置终端的自动退出时间) + - [设置用户的默认umask值为077](#设置用户的默认umask值为077) + - [设置GRUB2加密口令](#设置GRUB2加密口令) + - [安全单用户模式](#安全单用户模式) + - [禁止交互式启动](#禁止交互式启动) + +## 设置网络远程登录的警告信息 + +### 说明 + +设置网络远程登录的警告信息,用于在登录进入系统之前向用户提示警告信息,明示非法侵入系统可能受到的惩罚,吓阻潜在的攻击者。同时也可以隐藏系统架构及其他系统信息,避免招致对系统的目标性攻击。 + +### 实现 + +该设置可以通过修改/etc/issue.net文件的内容实现。将/etc/issue.net文件原有内容替换为如下信息(openEuler默认已设置): + +``` +Authorized users only. All activities may be monitored and reported. +``` + +## 禁止通过Ctrl+Alt+Del重启系统.md">禁止通过Ctrl+Alt+Del重启系统 + +### 说明 + +操作系统默认能够通过“Ctrl+Alt+Del”进行重启,禁止该项特性可以防止因为误操作而导致数据丢失。 + +### 实现 + +禁止通过“Ctrl+Alt+Del”重启系统的操作步骤如下: + +1. 删除两个ctrl-alt-del.target文件,参考命令如下: + + ``` + rm -f /etc/systemd/system/ctrl-alt-del.target + rm -f /usr/lib/systemd/system/ctrl-alt-del.target + ``` + +2. 修改/etc/systemd/system.conf文件,将\#CtrlAltDelBurstAction=reboot-force修改为CtrlAltDelBurstAction=none。 +3. 重启systemd,使修改生效,参考命令如下: + + ``` + systemctl daemon-reexec + ``` + +## 设置终端的自动退出时间 + +### 说明 + +无人看管的终端容易被侦听或被攻击,可能会危及系统安全。因此需要终端在停止运行一段时间后能够自动退出。 + +### 实现 + +自动退出时间由/etc/profile文件的TMOUT字段(单位为秒)控制,在/etc/profile的尾部添加如下配置: + +``` +export TMOUT=300 +``` + +## 设置用户的默认umask值为077 + +### 说明 + +umask值用于为用户新创建的文件和目录设置缺省权限。如果umask的值设置过小,会使群组用户或其他用户的权限过大,给系统带来安全威胁。因此设置所有用户默认的umask值为0077,即用户创建的目录默认权限为700,文件的默认权限为600。umask值代表的是权限的“补码”,umask值和权限的换算方法请参见[umask值含义](#umask值含义)。 + +>![](public_sys-resources/icon-note.gif) **说明:** +>openEuler默认已设置用户的默认umask值为077。 + +### 实现 + +1. 分别在/etc/bashrc文件和/etc/profile.d/目录下的所有文件中加入“umask 0077”。 + + ``` + echo "umask 0077" >> $FILE + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >_$FILE_ 为具体的文件名,例如:echo "umask 0077" \>\> /etc/bashrc + +2. 设置/etc/bashrc文件和/etc/profile.d/目录下所有文件的属主为root,群组为root。 + + ``` + chown root.root $FILE + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >_$FILE_ 为具体的文件名,例如:chown root.root /etc/bashrc + + +## 设置GRUB2加密口令 + +### 说明 + +GRUB是GRand UnifiedBootloader的缩写,它是一个操作系统启动管理器,用来引导不同系统(如Windows、Linux),GRUB2是GRUB的升级版。 + +系统启动时,可以通过GRUB2界面修改系统的启动参数。为了确保系统的启动参数不被任意修改,需要对GRUB2界面进行加密,仅在输入正确的GRUB2口令时才能修改启动参数。 + +>![](public_sys-resources/icon-note.gif) **说明:** +>GRUB2默认设置的口令为openEuler\#12,建议用户首次登录时修改默认密码并定期更新,避免密码泄露后,启动选项被篡改,导致系统启动异常。 + +### 实现 + +1. 使用grub2-mkpasswd-pbkdf2命令生成加密的口令 + + >![](public_sys-resources/icon-note.gif) **说明:** + >GRUB2加密算法使用sha512。 + + ``` + # grub2-mkpasswd-pbkdf2 + Enter password: + Reenter password: + PBKDF2 hash of your password is + grub.pbkdf2.sha512.10000.5A45748D892672FDA02DD3B6F7AE390AC6E6D532A600D4AC477D25C7D087644697D8A0894DFED9D86DC2A27F4E01D925C46417A225FC099C12DBD3D7D49A7425.2BD2F5BF4907DCC389CC5D165DB85CC3E2C94C8F9A30B01DACAA9CD552B731BA1DD3B7CC2C765704D55B8CD962D2AEF19A753CBE9B8464E2B1EB39A3BB4EAB08 + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >在Enter password和Reenter password输入相同的口令。 + >grub.pbkdf2.sha512.10000.5A45748D892672FDA02DD3B6F7AE390AC6E6D532A600D4AC477D25C7D087644697D8A0894DFED9D86DC2A27F4E01D925C46417A225FC099C12DBD3D7D49A7425.2BD2F5BF4907DCC389CC5D165DB85CC3E2C94C8F9A30B01DACAA9CD552B731BA1DD3B7CC2C765704D55B8CD962D2AEF19A753CBE9B8464E2B1EB39A3BB4EAB08为openEuler\#12经过grub2-mkpasswd-pbkdf2加密后的输出,每次输出的密文不同。 + +2. 使用vi工具打开/boot/efi/EFI/openEuler/grub.cfg的开始位置追加如下字段: + + ``` + set superusers="root" + password_pbkdf2 root grub.pbkdf2.sha512.10000.5A45748D892672FDA02DD3B6F7AE390AC6E6D532A600D4AC477D25C7D087644697D8A0894DFED9D86DC2A27F4E01D925C46417A225FC099C12DBD3D7D49A7425.2BD2F5BF4907DCC389CC5D165DB85CC3E2C94C8F9A30B01DACAA9CD552B731BA1DD3B7CC2C765704D55B8CD962D2AEF19A753CBE9B8464E2B1EB39A3BB4EAB08 + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >- superusers字段用于设置GRUB2的超级管理员的账户名。 + >- password\_pbkdf2字段后的参数,第1个参数为GRUB2的账户名,第2个为该账户的加密口令。 + + +## 安全单用户模式 + +### 说明 + +单用户模式是以root权限进入系统,如不设置密码,将存在较大安全隐患。 + +### 实现 + +该设置可以通过修改/etc/sysconfig/init文件内容实现。将SINGLE选项配置为SINGLE=/sbin/sulogin。 + +## 禁止交互式启动 + +### 说明 + +使用交互式引导,控制台用户可以禁用审计、防火墙或其他服务,削弱了系统安全性。用户可以禁止使用交互式引导,提升安全性。openEuler默认已禁止。 + +### 实现 + +该设置可以通过修改/etc/sysconfig/init文件内容实现。将PROMPT选项配置为PROMPT=no。 \ No newline at end of file diff --git "a/content/zh/docs/SecHarden/\346\223\215\344\275\234\347\263\273\347\273\237\345\212\240\345\233\272\346\246\202\350\277\260.md" "b/content/zh/docs/SecHarden/\346\223\215\344\275\234\347\263\273\347\273\237\345\212\240\345\233\272\346\246\202\350\277\260.md" index c81e70d8eec6c90c9f624bf8dc4ff1beda818e07..a41f404b605447eaf987855d6e78260237ba4454 100644 --- "a/content/zh/docs/SecHarden/\346\223\215\344\275\234\347\263\273\347\273\237\345\212\240\345\233\272\346\246\202\350\277\260.md" +++ "b/content/zh/docs/SecHarden/\346\223\215\344\275\234\347\263\273\347\273\237\345\212\240\345\233\272\346\246\202\350\277\260.md" @@ -1,3 +1,133 @@ -# 操作系统加固概述 + +# 操作系统加固概述 介绍对openEuler系统进行加固的目的和加固方案。 + + +- [操作系统加固概述](#操作系统加固概述) + - [加固目的](#加固目的) + - [加固方案](#加固方案) + - [加固影响](#加固影响) + + + +## 加固目的 + +操作系统作为信息系统的核心,承担着管理硬件资源和软件资源的重任,是整个信息系统安全的基础。操作系统之上的各种应用,要想获得信息的完整性、机密性、可用性和可控性,必须依赖于操作系统。脱离了对操作系统的安全保护,仅依靠其他层面的防护手段来阻止黑客和病毒等对网络信息系统的攻击,是无法满足安全需求的。 + +因此,需要对操作系统进行安全加固,构建动态、完整的安全体系,增强产品的安全性,提升产品的竞争力。 + +## 加固方案 + +本章描述openEuler的安全加固方案,包括加固方式和加固内容。 + +### 加固方式 + +用户可以通过手动修改加固配置或执行相关命令对系统进行加固,也可以通过加固工具批量修改加固项。openEuler的安全加固工具security tool以openEuler-security.service服务的形式运行。系统首次启动时会自动运行该服务去执行默认加固策略,且自动设置后续开机不启动该服务。 + +用户可以通过修改security.conf,使用安全加固工具实现个性化安全加固的效果。 + +### 加固内容 + +openEuler系统加固内容主要分为以下5个部分: + +- 系统服务 +- 文件权限 +- 内核参数 +- 授权认证 +- 账号口令 + +## 加固影响 + +对文件权限、账户口令等安全加固,可能造成用户使用习惯变更,从而影响系统的易用性。影响系统易用性的常见加固项请参见[表1](#zh-cn_topic_0152100325_ta4a48f54ff2849ada7845e2380209917)。 + +**表 1** 加固影响说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

加固项

+

建议加固

+

易用性影响

+

openEuler默认是否设置了该加固项

+

字符界面等待超时限制

+

当字符界面长时间处在空闲状态,字符界面会自动退出。

+
说明:

当用户通过SSH登录,超时时间由/etc/profile文件的TMOUT字段和/etc/ssh/sshd_config文件的ClientAliveInterval字段两个值中较小的值决定。建议加固为300秒。

+
+

用户长时间不操作字符界面,字符界面会自动退出。

+

+

口令复杂度限制

+

口令长度最小为8位,口令至少包含大写字母、小写字母、数字和特殊字符中的3种。

+

系统中所有用户不能设置简单的口令,口令必须符合复杂度要求。

+

+

限定登录失败时的尝试次数

+

当用户登录系统时,口令连续输错3次,账户将被锁定60秒,锁定期间不能登录系统。

+

用户不能随意登录系统,账户被锁定后必须等待60秒。

+

+

用户默认umask值限制

+

设置所有用户的默认umask值为077,使用户创建文件的默认权限为600、目录权限为700。

+

用户需要按照需求修改指定文件或目录的权限。

+

+

口令有效期

+

口令有效期的设置通过修改/etc/login.defs文件实现,加固默认值为口令最大有效期90天,两次修改口令的最小间隔时间为0,口令过期前开始提示天数为7。

+

口令过期后用户重新登录时,提示口令过期并强制要求修改,不修改则无法进入系统。

+

+

su权限限制

+

su命令用于在不同账户之间切换。为了增强系统安全性,有必要对su命令的使用权进行控制,只允许root和wheel群组的账户使用su命令,限制其他账户使用。

+

普通账户执行su命令失败,必须加入wheel群组才可以su成功。

+

+

禁止root账户直接SSH登录系统

+

设置/etc/ssh/sshd_config文件的PermitRootLogin字段的值为no,用户无法使用root账户直接SSH登录系统。

+

用户需要先使用普通账户SSH登录后,再切换至root账户。

+

+

SSH强加密算法

+

SSH服务的MACs和Ciphers配置,禁止对CBC、MD5、SHA1算法的支持,修改为CTR、SHA2算法。

+

当前windows下使用的部分低版本的Xshell、PuTTY不支持aes128-ctr、aes192-ctr、aes256-ctr、hmac-sha2-256、hmac-sha2-512算法,可能会出现无法通过SSH登录系统的情况,请使用最新的PuTTY(0.63版本以上)、Xshell(5.0版本及以上版本)登录。

+

+
+ diff --git "a/content/zh/docs/SecHarden/\346\226\207\344\273\266\345\222\214\347\233\256\345\275\225\346\235\203\351\231\220\345\220\253\344\271\211.md" "b/content/zh/docs/SecHarden/\346\226\207\344\273\266\345\222\214\347\233\256\345\275\225\346\235\203\351\231\220\345\220\253\344\271\211.md" deleted file mode 100644 index f590cb7fc4d1311a80519b63754268e6f096a74e..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\346\226\207\344\273\266\345\222\214\347\233\256\345\275\225\346\235\203\351\231\220\345\220\253\344\271\211.md" +++ /dev/null @@ -1,18 +0,0 @@ -# 文件和目录权限含义 - -Linux系统中文件和目录权限用于限定谁能通过何种方式对文件和目录进行访问和操作。文件和目录的访问权限分为只读,只写和可执行三种。 - -有三种不同类型的用户可对文件和目录进行访问: - -- 文件所有者:文件的创建者。 -- 同组用户:与文件所有者在同一个属组的用户。 -- 其他用户:与文件所有者不在同一个属组的用户。 - -文件和目录的权限含义通过以下例子说明: - -假设/usr/src的权限为755,将每位数字转化为二进制后为:111101101,含义如下: - -- 左侧三个bit位111表示文件所有者的权限依次为:可读、可写、可执行。 -- 中间三个bit位101表示同组用户的权限依次为:可读、不可写、可执行。 -- 右侧三个bit位101表示其他用户的权限依次为:可读、不可写、可执行。 - diff --git "a/content/zh/docs/SecHarden/\346\226\207\344\273\266\346\235\203\351\231\220.md" "b/content/zh/docs/SecHarden/\346\226\207\344\273\266\346\235\203\351\231\220.md" index 0dbe215b014d57964f21981d7c036107b176b54d..bbbbe82029437960f196ad57512c2a3217a2fccf 100644 --- "a/content/zh/docs/SecHarden/\346\226\207\344\273\266\346\235\203\351\231\220.md" +++ "b/content/zh/docs/SecHarden/\346\226\207\344\273\266\346\235\203\351\231\220.md" @@ -1 +1,239 @@ -# 文件权限 +# 文件权限 + +- [文件权限](#文件权限) + - [设置文件的权限和属主](#设置文件的权限和属主) + - [删除无主文件](#删除无主文件) + - [处理空链接文件](#处理空链接文件) + - [设置守护进程的umask值](#设置守护进程的umask值) + - [为全局可写目录添加粘滞位属性](#为全局可写目录添加粘滞位属性) + - [删除非授权文件的全局可写属性](#删除非授权文件的全局可写属性) + - [限制at命令的使用权限](#限制at命令的使用权限) + - [限制cron命令的使用权限](#限制cron命令的使用权限) + - [限制sudo命令的使用权限](#限制sudo命令的使用权限) + + + +## 设置文件的权限和属主 + +### 说明 + +Linux将所有对象都当作文件来处理,即使一个目录也被看作是包含有多个其他文件的大文件。因此,Linux中最重要的就是文件和目录的安全性。文件和目录的安全性主要通过权限和属主来保证。 + +openEuler默认对系统中的常用目录、可执行文件和配置文件设置了权限和属主。 + +### 实现 + +以/bin目录为例,修改文件权限和文件属主的操作如下: + +- 修改文件权限。例如将/bin目录权限设置为755。 + + ``` + chmod 755 /bin + ``` + +- 修改文件属主。例如将/bin目录的拥有者和群组设置为root:root。 + + ``` + chown root:root /bin + ``` + + +## 删除无主文件 + +### 说明 + +系统管理员在删除用户/群组时,存在着忘记删除该用户/该群组所拥有文件的问题。如果后续新创建的用户/群组与被删除的用户/群组同名,则新用户/新群组会拥有部分不属于其权限的文件,建议将此类文件删除。 + +### 实现 + +删除用户ID不存在的文件 + +1. 查找用户ID不存在的文件。 + + ``` + find / -nouser + ``` + +2. 删除查找到的文件。其中 filename 为用户ID不存在文件的文件名。 + + ``` + rm -f filename + ``` + + +删除群组ID不存在的文件 + +1. 查找用户ID不存在的文件。 + + ``` + find / -nogroup + ``` + +2. 删除查找到的文件。其中 filename 为用户ID不存在文件的文件名。 + + ``` + rm -f filename + ``` + + +## 处理空链接文件 + +### 说明 + +无指向的空链接文件,可能会被恶意用户利用,影响系统安全性。建议用户删除无效的空链接文件,提高系统安全性。 + +### 特殊场景 + +openEuler系统安装完成后,可能存在空链接文件,这些空链接文件可能有对应用途(有些空链接文件是预制的,会被其他组件依赖)。请用户根据实际环境进行处理,处理方式请参见[实现](#zh-cn_topic_0152100319_s1b24647cdd834a8eaca3032611baf072)。 + +例如,openEuler支持UEFI和legacy BIOS两种安装模式,两种引导场景支持的grub相关包默认都安装,当用户选择legacy BIOS模式安装时,形成空链接文件“/etc/grub2-efi.cfg”;当用户选择UEFI模式安装时,会形成空链接文件“/etc/grub2.cfg”,需要用户根据实际情况处理空链接。 + +### 实现 + +1. 通过如下命令查找系统中的空链接文件。 + + ``` + find dirname -type l -follow 2>/dev/null + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + > dirname为搜索目录的名称,通常需要关注系统关键目录:/bin、/boot、/usr、/lib64、/lib、/var等。 + +2. 如果此类文件无实际作用,可通过如下命令删除。 + + ``` + rm -f filename + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >filename为[步骤1](#zh-cn_topic_0152100319_l4dc74664c4fb400aaf91fb314c4f9da6)找出的文件名。 + + +## 设置守护进程的umask值 + +### 说明 + +umask值用来为新创建的文件和目录设置缺省权限。如果没有设定umask值,则生成的文件具有全局可写权限,存在一定的风险。守护进程负责系统上某个服务,让系统可以接受来自用户或者是网络客户的要求。为了提高守护进程所创建文件和目录的安全性,建议设置其umask值为0027。umask值代表的是权限的“补码”,umask值和权限的换算方法请参见 "附录 > umask值含义" 。 + +>![](public_sys-resources/icon-note.gif) **说明:** +>openEuler默认已设置守护进程的umask值为0027。 + +### 实现 + +在配置文件/etc/sysconfig/init中新增一行:umask 0027。 + +## 为全局可写目录添加粘滞位属性 + +### 说明 + +任意用户可以删除、修改全局可写目录中的文件和目录,为了确保全局可写目录中的文件和目录不会被任意删除,需要为全局可写目录添加粘滞位属性。 + +### 实现 + +1. 搜索全局可写目录。 + + ``` + find / -type d -perm -0002 ! -perm -1000 -ls | grep -v proc + ``` + +2. 为全局可写目录添加粘滞位属性。dirname 为实际查找到的目录名。 + + ``` + chmod +t dirname + ``` + + +## 删除非授权文件的全局可写属性 + +### 说明 + +全局可写文件可被系统中的任意用户修改,影响系统完整性。 + +### 实现 + +1. 列举系统中所有的全局可写文件。 + + ``` + find / -type d \( -perm -o+w \) | grep -v procfind / -type f \( -perm -o+w \) | grep -v proc + ``` + +2. 查看步骤1列举的所有文件\(粘滞位位的文件和目录可以排除在外\),删除文件或去掉其全局可写权限。使用以下命令去掉权限,其中filename为对应文件名: + + ``` + chmod o-w filename + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >可通过如下命令确定对应文件或目录是否设置了粘滞位,若回显中包含T标记,则为粘滞位文件或目录。命令中的filename为需要查询文件或目录的名称。 + >``` + >ls -l filename + >``` + + +## 限制at命令的使用权限 + +### 说明 + +at命令用于创建在指定时间自动执行的任务。为避免任意用户通过at命令安排工作,造成系统易受攻击,需要指定可使用该命令的用户。 + +### 实现 + +1. 删除/etc/at.deny文件。 + + ``` + rm -f /etc/at.deny + ``` + +2. 将/etc/at.allow的文件属主改为root:root。 + + ``` + chown root:root /etc/at.allow + ``` + +3. 控制/etc/at.allow的文件权限,仅root可操作。 + + ``` + chmod og-rwx /etc/at.allow + ``` + + +## 限制cron命令的使用权限 + +### 说明 + +cron命令用于创建例行性任务。为避免任意用户通过cron命令安排工作,造成系统易受攻击,需要指定可使用该命令的用户。 + +### 实现 + +1. 删除/etc/cron.deny文件。 + + ``` + rm -f /etc/at.deny + ``` + +2. 将/etc/cron.allow的文件属主改为root:root。 + + ``` + chown root:root /etc/cron.allow + ``` + +3. 控制/etc/cron.allow的文件权限,仅root可操作。 + + ``` + chmod og-rwx /etc/cron.allow + ``` + + +## 限制sudo命令的使用权限 + +### 说明 + +sudo命令用于普通用户以root权限执行命令。为了增强系统安全性,有必要对sudo命令的使用权进行控制,只允许roo使用sudo命令,限制其他帐户使用。 + +### 实现 + +sudo命令的使用控制通过修改/etc/sudoers文件实现,需要注释掉如下配置行: + +``` +#%wheel ALL=(ALL) ALL +``` diff --git "a/content/zh/docs/SecHarden/\346\263\225\345\276\213\345\243\260\346\230\216.md" "b/content/zh/docs/SecHarden/\346\263\225\345\276\213\345\243\260\346\230\216.md" deleted file mode 100644 index d2ceedbd8bd3409e052cd420991a5343ef63116d..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\346\263\225\345\276\213\345\243\260\346\230\216.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 法律声明 - -**版权所有 © 2020 华为技术有限公司。** - -您对“本文档”的复制、使用、修改及分发受知识共享\(Creative Commons\)署名—相同方式共享4.0国际公共许可协议\(以下简称“CC BY-SA 4.0”\)的约束。为了方便用户理解,您可以通过访问[https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/) 了解CC BY-SA 4.0的概要 \(但不是替代\)。CC BY-SA 4.0的完整协议内容您可以访问如下网址获取:[https://creativecommons.org/licenses/by-sa/4.0/legalcode](https://creativecommons.org/licenses/by-sa/4.0/legalcode)。 - -**商标声明** - -openEuler为华为技术有限公司的商标。本文档提及的其他所有商标或注册商标,由各自的所有人拥有。 - -**免责声明** - -本文档仅作为使用指导,除非适用法强制规定或者双方有明确书面约定, 华为技术有限公司对本文档中的所有陈述、信息和建议不做任何明示或默示的声明或保证,包括但不限于不侵权,时效性或满足特定目的的担保。 - diff --git "a/content/zh/docs/SecHarden/\347\231\273\345\275\225\345\244\261\350\264\245\350\266\205\350\277\207\344\270\211\346\254\241\345\220\216\351\224\201\345\256\232.md" "b/content/zh/docs/SecHarden/\347\231\273\345\275\225\345\244\261\350\264\245\350\266\205\350\277\207\344\270\211\346\254\241\345\220\216\351\224\201\345\256\232.md" deleted file mode 100644 index b57d7961ddaae27542ab2324561ed4a91f228354..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\347\231\273\345\275\225\345\244\261\350\264\245\350\266\205\350\277\207\344\270\211\346\254\241\345\220\216\351\224\201\345\256\232.md" +++ /dev/null @@ -1,53 +0,0 @@ -# 登录失败超过三次后锁定 - -## 说明 - -为了保障用户系统的安全,建议用户设置口令出错次数的阈值(建议3次),以及由于口令尝试被锁定用户的自动解锁时间(建议300秒)。 - -用户锁定期间,任何输入被判定为无效,锁定时间不因用户的再次输入而重新计时;解锁后,用户的错误输入记录被清空。通过上述设置可以有效防范口令被暴力破解,增强系统的安全性。 - ->![](public_sys-resources/icon-note.gif) **说明:** ->openEuler默认口令出错次数的阈值为3次,系统被锁定后自动解锁时间为60秒。 - -## 实现 - -口令复杂度的设置通过修改/etc/pam.d/password-auth和/etc/pam.d/system-auth文件实现,设置口令最大的出错次数3次,系统锁定后的解锁时间为300秒的配置如下: - -``` -auth required pam_faillock.so preauth audit deny=3 even_deny_root unlock_time=300 -auth [default=die] pam_faillock.so authfail audit deny=3 even_deny_root unlock_time=300 -auth sufficient pam_faillock.so authsucc audit deny=3 even_deny_root unlock_time=300 -``` - -**表 1** pam\_faillock.so配置项说明 - - - - - - - - - - - - - - - - - - - -

配置项

-

说明

-

authfail

-

捕获用户登录失败的事件。

-

deny=3

-

用户连续登录失败次数超过3次即被锁定。

-

unlock_time=300

-

普通用户自动解锁时间为300秒(即5分钟)。

-

even_deny_root

-

同样限制root帐户。

-
- diff --git "a/content/zh/docs/SecHarden/\347\246\201\346\255\242\344\272\244\344\272\222\345\274\217\345\220\257\345\212\250.md" "b/content/zh/docs/SecHarden/\347\246\201\346\255\242\344\272\244\344\272\222\345\274\217\345\220\257\345\212\250.md" deleted file mode 100644 index ac0b4dd98d72d48ceea00505a202afa3a49bb88e..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\347\246\201\346\255\242\344\272\244\344\272\222\345\274\217\345\220\257\345\212\250.md" +++ /dev/null @@ -1,10 +0,0 @@ -# 禁止交互式启动 - -## 说明 - -使用交互式引导,控制台用户可以禁用审计、防火墙或其他服务,削弱了系统安全性。用户可以禁止使用交互式引导,提升安全性。openEuler默认已禁止。 - -## 实现 - -该设置可以通过修改/etc/sysconfig/init文件内容实现。将PROMPT选项配置为PROMPT=no。 - diff --git "a/content/zh/docs/SecHarden/\347\246\201\346\255\242\351\200\232\350\277\207Ctrl+Alt+Del\351\207\215\345\220\257\347\263\273\347\273\237.md" "b/content/zh/docs/SecHarden/\347\246\201\346\255\242\351\200\232\350\277\207Ctrl+Alt+Del\351\207\215\345\220\257\347\263\273\347\273\237.md" deleted file mode 100644 index 5c96ecf9ad5cc8b3430a8c102570c35b2b180baf..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\347\246\201\346\255\242\351\200\232\350\277\207Ctrl+Alt+Del\351\207\215\345\220\257\347\263\273\347\273\237.md" +++ /dev/null @@ -1,24 +0,0 @@ -# 禁止通过Ctrl+Alt+Del重启系统 - -## 说明 - -操作系统默认能够通过“Ctrl+Alt+Del”进行重启,禁止该项特性可以防止因为误操作而导致数据丢失。 - -## 实现 - -禁止通过“Ctrl+Alt+Del”重启系统的操作步骤如下: - -1. 删除两个ctrl-alt-del.target文件,参考命令如下: - - ``` - rm -f /etc/systemd/system/ctrl-alt-del.target - rm -f /usr/lib/systemd/system/ctrl-alt-del.target - ``` - -2. 修改/etc/systemd/system.conf文件,将\#CtrlAltDelBurstAction=reboot-force修改为CtrlAltDelBurstAction=none。 -3. 重启systemd,使修改生效,参考命令如下: - - ``` - systemctl daemon-reexec - ``` - diff --git "a/content/zh/docs/SecHarden/\347\263\273\347\273\237\346\234\215\345\212\241.md" "b/content/zh/docs/SecHarden/\347\263\273\347\273\237\346\234\215\345\212\241.md" index ba10e997a2e730907799b252eb47314e1e829476..1ec94d69695ab52eb16507065003e6fabe97627c 100644 --- "a/content/zh/docs/SecHarden/\347\263\273\347\273\237\346\234\215\345\212\241.md" +++ "b/content/zh/docs/SecHarden/\347\263\273\347\273\237\346\234\215\345\212\241.md" @@ -1,4 +1,476 @@ -# 系统服务 +# 系统服务 +- [系统服务](#系统服务) + - [加固SSH服务](#加固SSH服务) +## 加固SSH服务 + +### 说明 + +SSH(Secure Shell)是目前较可靠,专为远程登录会话和其他网络服务提供安全性保障的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。透过SSH可以对所有传输的数据进行加密,并防止DNS欺骗和IP欺骗。OpenSSH是SSH协议的免费开源实现。 + +加固SSH服务,是指修改SSH服务中的配置来设置系统使用OpenSSH协议时的算法、认证等参数,从而提高系统的安全性。[表1](#zh-cn_topic_0152100390_ta2fdb8e4931b4c1a8f502b3c7d887b95)中详细说明了各加固项含义、建议加固值及其默认策略。 + +### 实现 + +服务端加固操作如下: + +1. 打开服务端SSH服务的配置文件/etc/ssh/sshd\_config,在该文件中修改或添加对应加固项及其加固值。 +2. 保存/etc/ssh/sshd\_config文件。 +3. 重启SSH服务,命令如下: + + ``` + systemctl restart sshd + ``` + + +客户端加固操作如下: + +1. 打开客户端SSH服务的配置文件/etc/ssh/ssh\_config,在该文件中修改或添加对应加固项及其加固值。 +2. 保存/etc/ssh/ssh\_config文件。 +3. 重启SSH服务,命令如下: + + ``` + systemctl restart sshd + ``` + + +### 加固项说明 + +- 服务端加固策略 + + SSH服务的所有加固项均保存在配置文件/etc/ssh/sshd\_config中,服务端各加固项的含义、加固建议以及openEuler默认是否已经加固为建议加固值请参见[表1](#zh-cn_topic_0152100390_ta2fdb8e4931b4c1a8f502b3c7d887b95)。 + + **表 1** SSH服务端加固项说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

加固项

+

加固项说明

+

加固建议

+

openEuler默认是否已加固为建议值

+

Protocol

+

设置使用SSH协议的版本

+

2

+

+

SyslogFacility

+

设置SSH服务的日志类型。加固策略将其设置为“AUTH”,即认证类日志

+

AUTH

+

+

LogLevel

+

设置记录sshd日志消息的层次

+

VERBOSE

+

+

X11Forwarding

+

设置使用SSH登录后,能否使用图形化界面

+

no

+

+

MaxAuthTries

+

最大认证尝试次数

+

3

+

+

PubkeyAuthentication

+

设置是否允许公钥认证。

+

yes

+

+

RSAAuthentication

+

设置是否允许只有RSA安全验证

+

yes

+

+

IgnoreRhosts

+

设置是否使用rhosts文件和shosts文件进行验证。rhosts文件和shosts文件用于记录可以访问远程计算机的计算机名及关联的登录名

+

yes

+

+

RhostsRSAAuthentication

+

设置是否使用基于rhosts的RSA算法安全验证。rhosts文件记录可以访问远程计算机的计算机名及关联的登录名

+

no

+

+

HostbasedAuthentication

+

设置是否使用基于主机的验证。基于主机的验证是指已信任客户机上的任何用户都可以使用SSH连接

+

no

+

+

PermitRootLogin

+

+

是否允许root账户直接使用SSH登录系统

+
说明:

若需要直接使用root账户通过SSH登录系统,请修改/etc/ssh/sshd_config文件的PermitRootLogin字段的值为yes。

+
+

no

+

+

PermitEmptyPasswords

+

设置是否允许用口令为空的账号登录

+

no

+

+

PermitUserEnvironment

+

设置是否解析 ~/.ssh/environment和~/.ssh/authorized_keys中设定的环境变量

+

no

+

+

Ciphers

+

设置SSH数据传输的加密算法

+

aes128-ctr,aes192-ctr,aes256-ctr,chacha20-poly1305@openssh.com,aes128-gcm@openssh.com,aes256-gcm@openssh.com

+

+

ClientAliveInterval

+

设置系统等待的超时时间(单位秒)。超过指定时间未收到来自客户端的数据,则断开连接

+

300

+

+

ClientAliveCountMax

+

设置超时次数。服务器发出请求后,客户端没有响应的次数达到一定值,连接自动断开

+

0

+

+

Banner

+

指定登录SSH前后显示的提示信息的文件

+

/etc/issue.net

+

+

MACs

+

设置SSH数据校验的哈希算法

+

hmac-sha2-512,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-256-etm@openssh.com,hmac-sha1,hmac-sha1-etm@openssh.com

+

+

StrictModes

+

设置SSH在接收登录请求之前是否检查用户HOME目录和rhosts文件的权限和所有权

+

yes

+

+

UsePAM

+

使用PAM登录认证

+

yes

+

+

AllowTcpForwarding

+

设置是否允许TCP转发

+

no

+

+

Subsystem sftp /usr/libexec/openssh/sftp-server

+

sftp日志记录级别,记录INFO级别以及认证日志。

+

-l INFO -f AUTH

+

+

AllowAgentForwarding

+

设置是否允许SSH Agent转发

+

no

+

+

GatewayPorts

+

设置是否允许连接到转发客户端端口

+

no

+

+

PermitTunnel

+

Tunnel设备是否允许使用

+

no

+

+

KexAlgorithms

+

设置SSH密钥交换算法

+

curve25519-sha256,curve25519-sha256@@libssh.org,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256

+
  

LoginGraceTime

+

限制用户必须在指定的时限内认证成功,0 表示无限制。默认值是 60 秒。

+

60

+

+
+ + >![](public_sys-resources/icon-note.gif) **说明:** + >默认情况下,登录SSH前后显示的提示信息保存在/etc/issue.net文件中,/etc/issue.net默认信息为“Authorized users only. All activities may be monitored and reported.”。 + + +- 客户端加固策略 + + SSH服务的所有加固项均保存在配置文件/etc/ssh/ssh\_config中,客户端各加固项的含义、加固建议以及openEuler默认是否已经加固为建议加固值请参见[表2](#zh-cn_topic_0152100390_tb289c5a6f1c7420ab4339187f9018ea4)。 + + **表 2** SSH客户端加固项说明 + + + + + + + + + + + + + + + + + + + +

加固项

+

加固项说明

+

加固建议

+

openEuler默认是否已加固为建议值

+

KexAlgorithms

+

设置SSH密钥交换算法

+

ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1

+

+

VerifyHostKeyDNS

+

是否使用DNS或者SSHFP资源记录验证HostKey

+

ask

+

+
+ + >![](public_sys-resources/icon-note.gif) **说明:** + >对于使用dh算法进行密钥交换的第三方客户端和服务端工具,要求允许建立连接的最低长度为2048bits。 + + +### 其他安全建议 + +- SSH服务仅侦听指定IP地址 + + 出于安全考虑,建议用户在使用SSH服务时,仅在必需的IP上进行绑定侦听,而不是侦听0.0.0.0,可修改/etc/ssh/sshd\_config文件中的ListenAddress配置项。 + + 1. 打开并修改/etc/ssh/sshd\_config文件 + + ``` + vi /etc/ssh/sshd_config + ``` + + 修改内容如下,表示绑定侦听IP为 _192.168.1.100_,用户可根据实际情况修改需要侦听的IP + + ``` + ... + ListenAddress 192.168.1.100 + ... + ``` + + 2. 重启SSH服务 + + ``` + systemctl restart sshd.service + ``` + + + +- 限制SFTP用户向上跨目录访问 + + SFTP是FTP over SSH的安全FTP协议,对于访问SFTP的用户建议使用专用账号,只能上传或下载文件,不能用于SSH登录,同时对SFTP可以访问的目录进行限定,防止目录遍历攻击,具体配置如下: + + >![](public_sys-resources/icon-note.gif) **说明:** + >sftpgroup为示例用户组,sftpuser为示例用户名。 + + 1. 创建SFTP用户组 + + ``` + groupadd sftpgroup + ``` + + 2. 创建SFTP根目录 + + ``` + mkdir /sftp + ``` + + 3. 修改SFTP根目录属主和权限 + + ``` + chown root:root /sftp + chmod 755 /sftp + ``` + + 4. 创建SFTP用户 + + ``` + useradd -g sftpgroup -s /sbin/nologin sftpuser + ``` + + 5. 设置SFTP用户的口令 + + ``` + passwd sftpuser + ``` + + 6. 创建SFTP用户上传目录 + + ``` + mkdir /sftp/sftpuser + ``` + + 7. 修改SFTP用户上传目录属主和权限 + + ``` + chown root:root /sftp/sftpuser + chmod 777 /sftp/sftpuser + ``` + + 8. 修改/etc/ssh/sshd\_config文件 + + ``` + vi /etc/ssh/sshd_config + ``` + + 修改内容如下: + + ``` + #Subsystem sftp /usr/libexec/openssh/sftp-server -l INFO -f AUTH + Subsystem sftp internal-sftp -l INFO -f AUTH + ... + + Match Group sftpgroup + ChrootDirectory /sftp/%u + ForceCommand internal-sftp + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >- %u代表当前sftp用户的用户名,这是一个通配符,用户原样输入即可。 + >- 以下内容必须加在/etc/ssh/sshd\_config文件的末尾。 + > ``` + > Match Group sftpgroup + > ChrootDirectory /sftp/%u + > ForceCommand internal-sftp + > ``` + + 9. 重启SSH服务 + + ``` + systemctl restart sshd.service + ``` + + + +- SSH远程执行命令 + + OpenSSH通用机制,在远程执行命令时,默认不开启tty,如果执行需要密码的命令,密码会明文回显。出于安全考虑,建议用户增加-t选项,确保密码输入安全。如下: + + ``` + ssh -t testuser@192.168.1.100 su + ``` + + >![](public_sys-resources/icon-note.gif) **说明:** + >192.168.1.100为示例IP,testuser为示例用户。 + diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256GRUB2\345\212\240\345\257\206\345\217\243\344\273\244.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256GRUB2\345\212\240\345\257\206\345\217\243\344\273\244.md" deleted file mode 100644 index 6c044bc11faa481e57de93eb16cf85e7f957a046..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256GRUB2\345\212\240\345\257\206\345\217\243\344\273\244.md" +++ /dev/null @@ -1,42 +0,0 @@ -# 设置GRUB2加密口令 - -## 说明 - -GRUB是GRand UnifiedBootloader的缩写,它是一个操作系统启动管理器,用来引导不同系统(如Windows、Linux),GRUB2是GRUB的升级版。 - -系统启动时,可以通过GRUB2界面修改系统的启动参数。为了确保系统的启动参数不被任意修改,需要对GRUB2界面进行加密,仅在输入正确的GRUB2口令时才能修改启动参数。 - ->![](public_sys-resources/icon-note.gif) **说明:** ->GRUB2默认设置的口令为openEuler\#12,建议用户首次登录时修改默认密码并定期更新,避免密码泄露后,启动选项被篡改,导致系统启动异常。 - -## 实现 - -1. 使用grub2-mkpasswd-pbkdf2命令生成加密的口令 - - >![](public_sys-resources/icon-note.gif) **说明:** - >GRUB2加密算法使用sha512。 - - ``` - # grub2-mkpasswd-pbkdf2 - Enter password: - Reenter password: - PBKDF2 hash of your password is - grub.pbkdf2.sha512.10000.5A45748D892672FDA02DD3B6F7AE390AC6E6D532A600D4AC477D25C7D087644697D8A0894DFED9D86DC2A27F4E01D925C46417A225FC099C12DBD3D7D49A7425.2BD2F5BF4907DCC389CC5D165DB85CC3E2C94C8F9A30B01DACAA9CD552B731BA1DD3B7CC2C765704D55B8CD962D2AEF19A753CBE9B8464E2B1EB39A3BB4EAB08 - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >在Enter password和Reenter password输入相同的口令。 - >grub.pbkdf2.sha512.10000.5A45748D892672FDA02DD3B6F7AE390AC6E6D532A600D4AC477D25C7D087644697D8A0894DFED9D86DC2A27F4E01D925C46417A225FC099C12DBD3D7D49A7425.2BD2F5BF4907DCC389CC5D165DB85CC3E2C94C8F9A30B01DACAA9CD552B731BA1DD3B7CC2C765704D55B8CD962D2AEF19A753CBE9B8464E2B1EB39A3BB4EAB08为openEuler\#12经过grub2-mkpasswd-pbkdf2加密后的输出,每次输出的密文不同。 - -2. 使用vi工具打开/boot/efi/EFI/openEuler/grub.cfg的开始位置追加如下字段: - - ``` - set superusers="root" - password_pbkdf2 root grub.pbkdf2.sha512.10000.5A45748D892672FDA02DD3B6F7AE390AC6E6D532A600D4AC477D25C7D087644697D8A0894DFED9D86DC2A27F4E01D925C46417A225FC099C12DBD3D7D49A7425.2BD2F5BF4907DCC389CC5D165DB85CC3E2C94C8F9A30B01DACAA9CD552B731BA1DD3B7CC2C765704D55B8CD962D2AEF19A753CBE9B8464E2B1EB39A3BB4EAB08 - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >- superusers字段用于设置GRUB2的超级管理员的账户名。 - >- password\_pbkdf2字段后的参数,第1个参数为GRUB2的账户名,第2个为该账户的加密口令。 - - diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\345\244\215\346\235\202\345\272\246.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\345\244\215\346\235\202\345\272\246.md" deleted file mode 100644 index 320b49a8aaa45149b4f611cf1af6859ab75924bd..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\345\244\215\346\235\202\345\272\246.md" +++ /dev/null @@ -1,117 +0,0 @@ -# 设置口令复杂度 - -## 说明 - -用户可以通过修改对应配置文件设置口令的复杂度要求,建议用户根据实际情况设置口令复杂度。 - -## 实现 - -口令复杂度通过/etc/pam.d/password-auth和/etc/pam.d/system-auth文件中的pam\_pwquality.so和pam\_pwhistory.so模块实现。用户可以通过修改这两个模块中的配置项修改口令复杂度要求。 - -## 设置举例 - -这里给出一个配置口令复杂度的例子,供用户参考。 - -**密码复杂度要求** - -1. 口令长度至少8个字符。 -2. 口令必须包含如下至少3种字符的组合: - - -至少一个小写字母 - - -至少一个大写字母 - - -至少一个数字 - - -至少一个特殊字符:\`\~!@\#$%^&\*\(\)-\_=+\\|\[\{\}\];:'",<.\>/?和空格 - -3. 口令不能和帐号或者帐号的倒写一样。 -4. 不能修改为过去5次使用过的旧口令。 - -**配置实现** - -在/etc/pam.d/password-auth和/etc/pam.d/system-auth文件中添加如下配置内容: - -``` -password requisite pam_pwquality.so minlen=8 minclass=3 enforce_for_root try_first_pass local_users_only retry=3 dcredit=0 ucredit=0 lcredit=0 ocredit=0 -password required pam_pwhistory.so use_authtok remember=5 enforce_for_root -``` - -**配置项说明** - -pam\_pwquality.so和pam\_pwhistory.so的配置项请分别参见[表1](#table201221044172117)和[表2](#table1212544452120)。 - -**表 1** pam\_pwquality.so配置项说明 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

配置项

-

说明

-

minlen=8

-

口令长度至少包含8个字符

-

minclass=3

-

口令至少包含大写字母、小写字母、数字和特殊字符中的任意3种

-

ucredit=0

-

口令包含任意个大写字母

-

lcredit=0

-

口令包含任意个小写字母

-

dcredit=0

-

口令包含任意个数字

-

ocredit=0

-

口令包含任意个特殊字符

-

retry=3

-

每次修改最多可以尝试3次

-

enforce_for_root

-

本设置对root帐户同样有效

-
- -**表 2** pam\_pwhistory.so配置项说明 - - - - - - - - - - - - - -

配置项

-

说明

-

remember=5

-

口令不能修改为过去5次使用过的旧口令

-

enforce_for_root

-

本设置对root帐户同样有效

-
- diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\346\234\211\346\225\210\346\234\237.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\346\234\211\346\225\210\346\234\237.md" deleted file mode 100644 index d43618e88f224e80f396c5cf8bf87a7499843e72..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\346\234\211\346\225\210\346\234\237.md" +++ /dev/null @@ -1,56 +0,0 @@ -# 设置口令有效期 - -## 说明 - -出于系统安全性考虑,建议设置口令有效期限,且口令到期前通知用户更改口令。 - -## 实现 - -口令有效期的设置通过修改/etc/login.defs文件实现,加固项如[表1](#zh-cn_topic_0152100281_t77b5d0753721450c81911c18b74e82eb)所示。表中所有的加固项都在文件/etc/login.defs中。表中字段直接通过修改配置文件完成。 - -**表 1** login.defs配置项说明所示 - - - - - - - - - - - - - - - - - - - - - - - - -

加固项

-

加固项说明

-

建议加固

-

openEuler默认是否已加固为建议值

-

PASS_MAX_DAYS

-

口令最大有效期

-

90

-

-

PASS_MIN_DAYS

-

两次修改口令的最小间隔时间

-

0

-

-

PASS_WARN_AGE

-

口令过期前开始提示天数

-

7

-

-
- ->![](public_sys-resources/icon-note.gif) **说明:** ->login.defs是设置用户帐号限制的文件,可配置口令的最大过期天数、最大长度约束等。该文件里的配置对root用户无效。如果/etc/shadow文件里有相同的选项,则以/etc/shadow配置为准,即/etc/shadow的配置优先级高于/etc/login.defs。口令过期后用户重新登录时,提示口令过期并强制要求修改,不修改则无法进入系统。 - diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\347\232\204\345\212\240\345\257\206\347\256\227\346\263\225.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\347\232\204\345\212\240\345\257\206\347\256\227\346\263\225.md" deleted file mode 100644 index d030f5618476b907ac7349bf158b9322e14a7c85..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\217\243\344\273\244\347\232\204\345\212\240\345\257\206\347\256\227\346\263\225.md" +++ /dev/null @@ -1,31 +0,0 @@ -# 设置口令的加密算法 - -## 说明 - -出于系统安全考虑,口令不允许明文存储在系统中,应该加密保护。在不需要还原口令的场景,必须使用不可逆算法加密。设置口令的加密算法为sha512,openEuler默认已设置。通过上述设置可以有效防范口令泄露,保证口令安全。 - -## 实现 - -口令的加密算法设置通过修改/etc/pam.d/password-auth和/etc/pam.d/system-auth文件实现,添加如下配置: - -``` -password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok -``` - -**表 1** pam\_unix.so配置项说明 - - - - - - - - - - -

配置项

-

说明

-

sha512

-

使用sha512算法对口令加密。

-
- diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\256\210\346\212\244\350\277\233\347\250\213\347\232\204umask\345\200\274.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\256\210\346\212\244\350\277\233\347\250\213\347\232\204umask\345\200\274.md" deleted file mode 100644 index dd68e15f8e52b7e89d956566e847c62fa3cffa1b..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\345\256\210\346\212\244\350\277\233\347\250\213\347\232\204umask\345\200\274.md" +++ /dev/null @@ -1,13 +0,0 @@ -# 设置守护进程的umask值 - -## 说明 - -umask值用来为新创建的文件和目录设置缺省权限。如果没有设定umask值,则生成的文件具有全局可写权限,存在一定的风险。守护进程负责系统上某个服务,让系统可以接受来自用户或者是网络客户的要求。为了提高守护进程所创建文件和目录的安全性,建议设置其umask值为0027。umask值代表的是权限的“补码”,umask值和权限的换算方法请参见 "附录 > umask值含义" 。 - ->![](public_sys-resources/icon-note.gif) **说明:** ->openEuler默认已设置守护进程的umask值为0027。 - -## 实现 - -在配置文件/etc/sysconfig/init中新增一行:umask 0027。 - diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\346\226\207\344\273\266\347\232\204\346\235\203\351\231\220\345\222\214\345\261\236\344\270\273.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\346\226\207\344\273\266\347\232\204\346\235\203\351\231\220\345\222\214\345\261\236\344\270\273.md" deleted file mode 100644 index ca9fa13de9ba7bf856c61de09351bd4f8acb7ea0..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\346\226\207\344\273\266\347\232\204\346\235\203\351\231\220\345\222\214\345\261\236\344\270\273.md" +++ /dev/null @@ -1,25 +0,0 @@ -# 设置文件的权限和属主 - -## 说明 - -Linux将所有对象都当作文件来处理,即使一个目录也被看作是包含有多个其他文件的大文件。因此,Linux中最重要的就是文件和目录的安全性。文件和目录的安全性主要通过权限和属主来保证。 - -openEuler默认对系统中的常用目录、可执行文件和配置文件设置了权限和属主。 - -## 实现 - -以/bin目录为例,修改文件权限和文件属主的操作如下: - -- 修改文件权限。例如将/bin目录权限设置为755。 - - ``` - chmod 755 /bin - ``` - -- 修改文件属主。例如将/bin目录的拥有者和群组设置为root:root。 - - ``` - chown root:root /bin - ``` - - diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\224\250\346\210\267\347\232\204\351\273\230\350\256\244umask\345\200\274\344\270\272077.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\224\250\346\210\267\347\232\204\351\273\230\350\256\244umask\345\200\274\344\270\272077.md" deleted file mode 100644 index 22b70374e5087ed53dd22ba7434f7d2861c09575..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\224\250\346\210\267\347\232\204\351\273\230\350\256\244umask\345\200\274\344\270\272077.md" +++ /dev/null @@ -1,30 +0,0 @@ -# 设置用户的默认umask值为077 - -## 说明 - -umask值用于为用户新创建的文件和目录设置缺省权限。如果umask的值设置过小,会使群组用户或其他用户的权限过大,给系统带来安全威胁。因此设置所有用户默认的umask值为0077,即用户创建的目录默认权限为700,文件的默认权限为600。umask值代表的是权限的“补码”,umask值和权限的换算方法请参见[umask值含义](umask值含义.md)。 - ->![](public_sys-resources/icon-note.gif) **说明:** ->openEuler默认已设置用户的默认umask值为077。 - -## 实现 - -1. 分别在/etc/bashrc文件和/etc/profile.d/目录下的所有文件中加入“umask 0077”。 - - ``` - echo "umask 0077" >> $FILE - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >_$FILE_ 为具体的文件名,例如:echo "umask 0077" \>\> /etc/bashrc - -2. 设置/etc/bashrc文件和/etc/profile.d/目录下所有文件的属主为root,群组为root。 - - ``` - chown root.root $FILE - ``` - - >![](public_sys-resources/icon-note.gif) **说明:** - >_$FILE_ 为具体的文件名,例如:chown root.root /etc/bashrc - - diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\273\210\347\253\257\347\232\204\350\207\252\345\212\250\351\200\200\345\207\272\346\227\266\351\227\264.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\273\210\347\253\257\347\232\204\350\207\252\345\212\250\351\200\200\345\207\272\346\227\266\351\227\264.md" deleted file mode 100644 index 3ed6f255f76e205c13d009f9c85d58477316b0a7..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\273\210\347\253\257\347\232\204\350\207\252\345\212\250\351\200\200\345\207\272\346\227\266\351\227\264.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 设置终端的自动退出时间 - -## 说明 - -无人看管的终端容易被侦听或被攻击,可能会危及系统安全。因此需要终端在停止运行一段时间后能够自动退出。 - -## 实现 - -自动退出时间由/etc/profile文件的TMOUT字段(单位为秒)控制,在/etc/profile的尾部添加如下配置: - -``` -export TMOUT=300 -``` - diff --git "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\275\221\347\273\234\350\277\234\347\250\213\347\231\273\345\275\225\347\232\204\350\255\246\345\221\212\344\277\241\346\201\257.md" "b/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\275\221\347\273\234\350\277\234\347\250\213\347\231\273\345\275\225\347\232\204\350\255\246\345\221\212\344\277\241\346\201\257.md" deleted file mode 100644 index 0e144204d795db144c3488c9b3d07bbd5668e8c4..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\350\256\276\347\275\256\347\275\221\347\273\234\350\277\234\347\250\213\347\231\273\345\275\225\347\232\204\350\255\246\345\221\212\344\277\241\346\201\257.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 设置网络远程登录的警告信息 - -## 说明 - -设置网络远程登录的警告信息,用于在登录进入系统之前向用户提示警告信息,明示非法侵入系统可能受到的惩罚,吓阻潜在的攻击者。同时也可以隐藏系统架构及其他系统信息,避免招致对系统的目标性攻击。 - -## 实现 - -该设置可以通过修改/etc/issue.net文件的内容实现。将/etc/issue.net文件原有内容替换为如下信息(openEuler默认已设置): - -``` -Authorized users only. All activities may be monitored and reported. -``` - diff --git "a/content/zh/docs/SecHarden/\350\264\246\346\210\267\345\217\243\344\273\244.md" "b/content/zh/docs/SecHarden/\350\264\246\346\210\267\345\217\243\344\273\244.md" index 6da21e3572d9561927788433f4eb129701a87fb6..b87327bd91dc49d349020e5211a66a37e91c31bd 100644 --- "a/content/zh/docs/SecHarden/\350\264\246\346\210\267\345\217\243\344\273\244.md" +++ "b/content/zh/docs/SecHarden/\350\264\246\346\210\267\345\217\243\344\273\244.md" @@ -1,2 +1,330 @@ -# 账户口令 +# 账户口令 +- [账户口令](#账户口令) + - [屏蔽系统帐户](#屏蔽系统帐户) + - [限制使用su命令的帐户](#限制使用su命令的帐户) + - [设置口令复杂度](#设置口令复杂度) + - [设置口令有效期](#设置口令有效期) + - [设置口令的加密算法](#设置口令的加密算法) + - [登录失败超过三次后锁定](#登录失败超过三次后锁定) + - [加固su命令](#加固su命令) + + +## 屏蔽系统帐户 + +### 说明 + +除了用户帐户外,其他账号称为系统账户。系统账户仅系统内部使用,禁止用于登录系统或其他操作,因此屏蔽系统账户。 + +### 实现 + +将系统帐户的Shell修改为/sbin/nologin。 + +``` +usermod -L -s /sbin/nologin $systemaccount +``` + +>![](public_sys-resources/icon-note.gif) **说明:** +> $systemaccount 指系统帐户。 + +## 限制使用su命令的帐户 + +### 说明 + +su命令用于在不同帐户之间切换。为了增强系统安全性,有必要对su命令的使用权进行控制,只允许root和wheel群组的帐户使用su命令,限制其他帐户使用。 + +### 实现 + +su命令的使用控制通过修改/etc/pam.d/su文件实现,配置如下: + +``` +auth required pam_wheel.so use_uid +``` + +**表 1** pam\_wheel.so配置项说明 + + + + + + + + + + +

配置项

+

说明

+

use_uid

+

基于当前帐户的uid。

+
+ +## 设置口令复杂度 + +### 说明 + +用户可以通过修改对应配置文件设置口令的复杂度要求,建议用户根据实际情况设置口令复杂度。 + +### 实现 + +口令复杂度通过/etc/pam.d/password-auth和/etc/pam.d/system-auth文件中的pam\_pwquality.so和pam\_pwhistory.so模块实现。用户可以通过修改这两个模块中的配置项修改口令复杂度要求。 + +### 设置举例 + +这里给出一个配置口令复杂度的例子,供用户参考。 + +**密码复杂度要求** + +1. 口令长度至少8个字符。 +2. 口令必须包含如下至少3种字符的组合: + + -至少一个小写字母 + + -至少一个大写字母 + + -至少一个数字 + + -至少一个特殊字符:\`\~!@\#$%^&\*\(\)-\_=+\\|\[\{\}\];:'",<.\>/?和空格 + +3. 口令不能和帐号或者帐号的倒写一样。 +4. 不能修改为过去5次使用过的旧口令。 + +**配置实现** + +在/etc/pam.d/password-auth和/etc/pam.d/system-auth文件中添加如下配置内容: + +``` +password requisite pam_pwquality.so minlen=8 minclass=3 enforce_for_root try_first_pass local_users_only retry=3 dcredit=0 ucredit=0 lcredit=0 ocredit=0 +password required pam_pwhistory.so use_authtok remember=5 enforce_for_root +``` + +**配置项说明** + +pam\_pwquality.so和pam\_pwhistory.so的配置项请分别参见[表5](#table201221044172117)和[表6](#table1212544452120)。 + +**表 2** pam\_pwquality.so配置项说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

配置项

+

说明

+

minlen=8

+

口令长度至少包含8个字符

+

minclass=3

+

口令至少包含大写字母、小写字母、数字和特殊字符中的任意3种

+

ucredit=0

+

口令包含任意个大写字母

+

lcredit=0

+

口令包含任意个小写字母

+

dcredit=0

+

口令包含任意个数字

+

ocredit=0

+

口令包含任意个特殊字符

+

retry=3

+

每次修改最多可以尝试3次

+

enforce_for_root

+

本设置对root帐户同样有效

+
+ +**表 3** pam\_pwhistory.so配置项说明 + + + + + + + + + + + + + +

配置项

+

说明

+

remember=5

+

口令不能修改为过去5次使用过的旧口令

+

enforce_for_root

+

本设置对root帐户同样有效

+
+ +## 设置口令有效期 + +### 说明 + +出于系统安全性考虑,建议设置口令有效期限,且口令到期前通知用户更改口令。 + +### 实现 + +口令有效期的设置通过修改/etc/login.defs文件实现,加固项如[表7](#zh-cn_topic_0152100281_t77b5d0753721450c81911c18b74e82eb)所示。表中所有的加固项都在文件/etc/login.defs中。表中字段直接通过修改配置文件完成。 + +**表 4** login.defs配置项说明所示 + + + + + + + + + + + + + + + + + + + + + + + + +

加固项

+

加固项说明

+

建议加固

+

openEuler默认是否已加固为建议值

+

PASS_MAX_DAYS

+

口令最大有效期

+

90

+

+

PASS_MIN_DAYS

+

两次修改口令的最小间隔时间

+

0

+

+

PASS_WARN_AGE

+

口令过期前开始提示天数

+

7

+

+
+ +>![](public_sys-resources/icon-note.gif) **说明:** +>login.defs是设置用户帐号限制的文件,可配置口令的最大过期天数、最大长度约束等。该文件里的配置对root用户无效。如果/etc/shadow文件里有相同的选项,则以/etc/shadow配置为准,即/etc/shadow的配置优先级高于/etc/login.defs。口令过期后用户重新登录时,提示口令过期并强制要求修改,不修改则无法进入系统。 + +## 设置口令的加密算法 + +### 说明 + +出于系统安全考虑,口令不允许明文存储在系统中,应该加密保护。在不需要还原口令的场景,必须使用不可逆算法加密。设置口令的加密算法为sha512,openEuler默认已设置。通过上述设置可以有效防范口令泄露,保证口令安全。 + +### 实现 + +口令的加密算法设置通过修改/etc/pam.d/password-auth和/etc/pam.d/system-auth文件实现,添加如下配置: + +``` +password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok +``` + +**表 5** pam\_unix.so配置项说明 + + + + + + + + + + +

配置项

+

说明

+

sha512

+

使用sha512算法对口令加密。

+
+ +## 登录失败超过三次后锁定 + +### 说明 + +为了保障用户系统的安全,建议用户设置口令出错次数的阈值(建议3次),以及由于口令尝试被锁定用户的自动解锁时间(建议300秒)。 + +用户锁定期间,任何输入被判定为无效,锁定时间不因用户的再次输入而重新计时;解锁后,用户的错误输入记录被清空。通过上述设置可以有效防范口令被暴力破解,增强系统的安全性。 + +>![](public_sys-resources/icon-note.gif) **说明:** +>openEuler默认口令出错次数的阈值为3次,系统被锁定后自动解锁时间为60秒。 + +### 实现 + +口令复杂度的设置通过修改/etc/pam.d/password-auth和/etc/pam.d/system-auth文件实现,设置口令最大的出错次数3次,系统锁定后的解锁时间为300秒的配置如下: + +``` +auth required pam_faillock.so preauth audit deny=3 even_deny_root unlock_time=300 +auth [default=die] pam_faillock.so authfail audit deny=3 even_deny_root unlock_time=300 +auth sufficient pam_faillock.so authsucc audit deny=3 even_deny_root unlock_time=300 +``` + +**表 6** pam\_faillock.so配置项说明 + + + + + + + + + + + + + + + + + + + +

配置项

+

说明

+

authfail

+

捕获用户登录失败的事件。

+

deny=3

+

用户连续登录失败次数超过3次即被锁定。

+

unlock_time=300

+

普通用户自动解锁时间为300秒(即5分钟)。

+

even_deny_root

+

同样限制root帐户。

+
+ +## 加固su命令 + +### 说明 + +为了增强系统安全性,防止使用“su”切换用户时将当前用户环境变量带入其他环境,openEuler默认已做配置。总是在使用su切换用户时初始化PATH。 + +### 实现 + +通过修改/etc/login.defs实现,配置如下: + +``` +ALWAYS_SET_PATH=yes +``` diff --git "a/content/zh/docs/SecHarden/\351\231\204\345\275\225.md" "b/content/zh/docs/SecHarden/\351\231\204\345\275\225.md" index ceb5302f63bd17c095f4b2e80e8242ffd0804b88..e5711922813d45488e7fc299c724c80259caad80 100644 --- "a/content/zh/docs/SecHarden/\351\231\204\345\275\225.md" +++ "b/content/zh/docs/SecHarden/\351\231\204\345\275\225.md" @@ -1,4 +1,38 @@ -# 附录 +# 附录 介绍文件权限的含义和umask值的含义。 + + +- [附录](#附录) + - [文件和目录权限含义](#文件和目录权限含义) + - [umask值含义](#umask值含义) + + + + + +## 文件和目录权限含义 + +Linux系统中文件和目录权限用于限定谁能通过何种方式对文件和目录进行访问和操作。文件和目录的访问权限分为只读,只写和可执行三种。 + +有三种不同类型的用户可对文件和目录进行访问: + +- 文件所有者:文件的创建者。 +- 同组用户:与文件所有者在同一个属组的用户。 +- 其他用户:与文件所有者不在同一个属组的用户。 + +文件和目录的权限含义通过以下例子说明: + +假设/usr/src的权限为755,将每位数字转化为二进制后为:111101101,含义如下: + +- 左侧三个bit位111表示文件所有者的权限依次为:可读、可写、可执行。 +- 中间三个bit位101表示同组用户的权限依次为:可读、不可写、可执行。 +- 右侧三个bit位101表示其他用户的权限依次为:可读、不可写、可执行。 + +## umask值含义 + +当用户新创建文件或目录时,该文件或目录具有一个缺省权限。该缺省权限由umask值来指定。 + +umask值代表的是权限的“补码”,即用缺省最大权限值减去umask值得到实际权限值。文件的缺省最大权限为可读可写,目录的缺省最大权限为可读可写可执行。即一个文件的实际缺省权限为666减去umask值。目录的实际缺省权限为777减去umask值。 + diff --git "a/content/zh/docs/SecHarden/\351\231\220\345\210\266at\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" "b/content/zh/docs/SecHarden/\351\231\220\345\210\266at\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" deleted file mode 100644 index e1b2e7fad361bb4a3ebfd7bdff08b5d58982a982..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\351\231\220\345\210\266at\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" +++ /dev/null @@ -1,27 +0,0 @@ -# 限制at命令的使用权限 - -## 说明 - -at命令用于创建在指定时间自动执行的任务。为避免任意用户通过at命令安排工作,造成系统易受攻击,需要指定可使用该命令的用户。 - -## 实现 - -1. 删除/etc/at.deny文件。 - - ``` - rm -f /etc/at.deny - ``` - -2. 将/etc/at.allow的文件属主改为root:root。 - - ``` - chown root:root /etc/at.allow - ``` - -3. 控制/etc/at.allow的文件权限,仅root可操作。 - - ``` - chmod og-rwx /etc/at.allow - ``` - - diff --git "a/content/zh/docs/SecHarden/\351\231\220\345\210\266cron\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" "b/content/zh/docs/SecHarden/\351\231\220\345\210\266cron\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" deleted file mode 100644 index ea09d9cf9c8566bdf9e551d4481b15e8dc8cd296..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\351\231\220\345\210\266cron\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" +++ /dev/null @@ -1,27 +0,0 @@ -# 限制cron命令的使用权限 - -## 说明 - -cron命令用于创建例行性任务。为避免任意用户通过cron命令安排工作,造成系统易受攻击,需要指定可使用该命令的用户。 - -## 实现 - -1. 删除/etc/cron.deny文件。 - - ``` - rm -f /etc/at.deny - ``` - -2. 将/etc/cron.allow的文件属主改为root:root。 - - ``` - chown root:root /etc/cron.allow - ``` - -3. 控制/etc/cron.allow的文件权限,仅root可操作。 - - ``` - chmod og-rwx /etc/cron.allow - ``` - - diff --git "a/content/zh/docs/SecHarden/\351\231\220\345\210\266sudo\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" "b/content/zh/docs/SecHarden/\351\231\220\345\210\266sudo\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" deleted file mode 100644 index 2a7f2637e1e04de415e120d353237ca31c5e1f4b..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\351\231\220\345\210\266sudo\345\221\275\344\273\244\347\232\204\344\275\277\347\224\250\346\235\203\351\231\220.md" +++ /dev/null @@ -1,14 +0,0 @@ -# 限制sudo命令的使用权限 - -## 说明 - -sudo命令用于普通用户以root权限执行命令。为了增强系统安全性,有必要对sudo命令的使用权进行控制,只允许roo使用sudo命令,限制其他帐户使用。 - -## 实现 - -sudo命令的使用控制通过修改/etc/sudoers文件实现,需要注释掉如下配置行: - -``` -#%wheel ALL=(ALL) ALL -``` - diff --git "a/content/zh/docs/SecHarden/\351\231\220\345\210\266\344\275\277\347\224\250su\345\221\275\344\273\244\347\232\204\345\270\220\346\210\267.md" "b/content/zh/docs/SecHarden/\351\231\220\345\210\266\344\275\277\347\224\250su\345\221\275\344\273\244\347\232\204\345\270\220\346\210\267.md" deleted file mode 100644 index 1a14f99fe0cbd21b65324f926b9f3e8cbe0dc3f0..0000000000000000000000000000000000000000 --- "a/content/zh/docs/SecHarden/\351\231\220\345\210\266\344\275\277\347\224\250su\345\221\275\344\273\244\347\232\204\345\270\220\346\210\267.md" +++ /dev/null @@ -1,31 +0,0 @@ -# 限制使用su命令的帐户 - -## 说明 - -su命令用于在不同帐户之间切换。为了增强系统安全性,有必要对su命令的使用权进行控制,只允许root和wheel群组的帐户使用su命令,限制其他帐户使用。 - -## 实现 - -su命令的使用控制通过修改/etc/pam.d/su文件实现,配置如下: - -``` -auth required pam_wheel.so use_uid -``` - -**表 1** pam\_wheel.so配置项说明 - - - - - - - - - - -

配置项

-

说明

-

use_uid

-

基于当前帐户的uid。

-
- diff --git a/content/zh/menu/index.md b/content/zh/menu/index.md index e7e2396ca9335d910677b0771c370a21d322abc0..10685dda23a03a3a949d69b12e426f86276b8d1d 100644 --- a/content/zh/menu/index.md +++ b/content/zh/menu/index.md @@ -1,4 +1,4 @@ ---- +--- headless: true --- - [法律声明]({{< relref "./docs/Releasenotes/法律声明.md" >}}) @@ -24,8 +24,8 @@ headless: true - [FAQ]({{< relref "./docs/Installation/FAQ.md" >}}) - [管理员指南]({{< relref "./docs/Administration/administration.md" >}}) - - [基础配置]({{< relref "./docs/Administration/基础配置.md" >}}) - [查看系统信息]({{< relref "./docs/Administration/查看系统信息.md" >}}) + - [基础配置]({{< relref "./docs/Administration/基础配置.md" >}}) - [管理用户]({{< relref "./docs/Administration/管理用户.md" >}}) - [使用DNF管理软件包]({{< relref "./docs/Administration/使用DNF管理软件包.md" >}}) - [管理服务]({{< relref "./docs/Administration/管理服务.md" >}}) @@ -40,55 +40,17 @@ headless: true - [搭建数据库服务器]({{< relref "./docs/Administration/搭建数据库服务器.md" >}}) - [FAQ]({{< relref "./docs/Administration/FAQ-54.md" >}}) - - [安全加固指南]({{< relref "./docs/SecHarden/secHarden.md" >}}) - - [前言]({{< relref "./docs/SecHarden/前言.md" >}}) - [操作系统加固概述]({{< relref "./docs/SecHarden/操作系统加固概述.md" >}}) - - [加固目的]({{< relref "./docs/SecHarden/加固目的.md" >}}) - - [加固方案]({{< relref "./docs/SecHarden/加固方案.md" >}}) - - [加固影响]({{< relref "./docs/SecHarden/加固影响.md" >}}) - [加固指导]({{< relref "./docs/SecHarden/加固指导.md" >}}) + - [账户口令]({{< relref "./docs/SecHarden/账户口令.md" >}}) + - [授权认证]({{< relref "./docs/SecHarden/授权认证.md" >}}) - [系统服务]({{< relref "./docs/SecHarden/系统服务.md" >}}) - - [加固SSH服务]({{< relref "./docs/SecHarden/加固SSH服务.md" >}}) - [文件权限]({{< relref "./docs/SecHarden/文件权限.md" >}}) - - [设置文件的权限和属主]({{< relref "./docs/SecHarden/设置文件的权限和属主.md" >}}) - - [删除无主文件]({{< relref "./docs/SecHarden/删除无主文件.md" >}}) - - [处理空链接文件]({{< relref "./docs/SecHarden/处理空链接文件.md" >}}) - - [设置守护进程的umask值]({{< relref "./docs/SecHarden/设置守护进程的umask值.md" >}}) - - [为全局可写目录添加粘滞位属性]({{< relref "./docs/SecHarden/为全局可写目录添加粘滞位属性.md" >}}) - - [删除非授权文件的全局可写属性]({{< relref "./docs/SecHarden/删除非授权文件的全局可写属性.md" >}}) - - [限制at命令的使用权限]({{< relref "./docs/SecHarden/限制at命令的使用权限.md" >}}) - - [限制cron命令的使用权限]({{< relref "./docs/SecHarden/限制cron命令的使用权限.md" >}}) - - [限制sudo命令的使用权限]({{< relref "./docs/SecHarden/限制sudo命令的使用权限.md" >}}) - - [内核参数]({{< relref "./docs/SecHarden/内核参数.md" >}}) - - [加固内核参数]({{< relref "./docs/SecHarden/加固内核参数.md" >}}) - - [授权认证]({{< relref "./docs/SecHarden/授权认证.md" >}}) - - [设置网络远程登录的警告信息]({{< relref "./docs/SecHarden/设置网络远程登录的警告信息.md" >}}) - - [禁止通过Ctrl+Alt+Del重启系统]({{< relref "./docs/SecHarden/禁止通过Ctrl+Alt+Del重启系统.md" >}}) - - [设置终端的自动退出时间]({{< relref "./docs/SecHarden/设置终端的自动退出时间.md" >}}) - - [设置用户的默认umask值为077]({{< relref "./docs/SecHarden/设置用户的默认umask值为077.md" >}}) - - [设置GRUB2加密口令]({{< relref "./docs/SecHarden/设置GRUB2加密口令.md" >}}) - - [安全单用户模式]({{< relref "./docs/SecHarden/安全单用户模式.md" >}}) - - [禁止交互式启动]({{< relref "./docs/SecHarden/禁止交互式启动.md" >}}) - - [账户口令]({{< relref "./docs/SecHarden/账户口令.md" >}}) - - [屏蔽系统帐户]({{< relref "./docs/SecHarden/屏蔽系统帐户.md" >}}) - - [限制使用su命令的帐户]({{< relref "./docs/SecHarden/限制使用su命令的帐户.md" >}}) - - [设置口令复杂度]({{< relref "./docs/SecHarden/设置口令复杂度.md" >}}) - - [设置口令有效期]({{< relref "./docs/SecHarden/设置口令有效期.md" >}}) - - [设置口令的加密算法]({{< relref "./docs/SecHarden/设置口令的加密算法.md" >}}) - - [登录失败超过三次后锁定]({{< relref "./docs/SecHarden/登录失败超过三次后锁定.md" >}}) - - [加固su命令]({{< relref "./docs/SecHarden/加固su命令.md" >}}) - - + - [SELinux配置]({{< relref "./docs/SecHarden/SELinux配置.md" >}}) - [安全加固工具]({{< relref "./docs/SecHarden/安全加固工具.md" >}}) - - [加固操作]({{< relref "./docs/SecHarden/加固操作.md" >}}) - - [加固生效]({{< relref "./docs/SecHarden/加固生效.md" >}}) - - - [SELinux配置]({{< relref "./docs/SecHarden/SELinux配置.md" >}}) - [附录]({{< relref "./docs/SecHarden/附录.md" >}}) - - [文件和目录权限含义]({{< relref "./docs/SecHarden/文件和目录权限含义.md" >}}) - - [umask值含义]({{< relref "./docs/SecHarden/umask值含义.md" >}}) - [虚拟化用户指南]({{< relref "./docs/Virtualization/virtualization.md" >}}) - [前言]({{< relref "./docs/Virtualization/前言.md" >}}) @@ -553,69 +515,8 @@ headless: true - [应用开发指南]({{< relref "./docs/ApplicationDev/application-development.md" >}}) - - [前言]({{< relref "./docs/ApplicationDev/前言.md" >}}) - [开发环境准备]({{< relref "./docs/ApplicationDev/开发环境准备.md" >}}) - - [环境要求]({{< relref "./docs/ApplicationDev/环境要求.md" >}}) - - [配置repo源]({{< relref "./docs/ApplicationDev/配置repo源.md" >}}) - - [安装软件包]({{< relref "./docs/ApplicationDev/安装软件包.md" >}}) - - [安装JDK软件包]({{< relref "./docs/ApplicationDev/安装JDK软件包.md" >}}) - - [安装rpm-build软件包]({{< relref "./docs/ApplicationDev/安装rpm-build软件包.md" >}}) - - [使用IDE进行Java开发]({{< relref "./docs/ApplicationDev/使用IDE进行Java开发.md" >}}) - - [简介]({{< relref "./docs/ApplicationDev/简介.md" >}}) - - [使用MobaXterm登录服务器]({{< relref "./docs/ApplicationDev/使用MobaXterm登录服务器.md" >}}) - - [设置JDK环境]({{< relref "./docs/ApplicationDev/设置JDK环境.md" >}}) - - [下载安装GTK库]({{< relref "./docs/ApplicationDev/下载安装GTK库.md" >}}) - - [设置X11 Forwarding]({{< relref "./docs/ApplicationDev/设置X11-Forwarding.md" >}}) - - [下载并运行IntelliJ IDEA]({{< relref "./docs/ApplicationDev/下载并运行IntelliJ-IDEA.md" >}}) - [使用GCC编译]({{< relref "./docs/ApplicationDev/使用GCC编译.md" >}}) - - [简介]({{< relref "./docs/ApplicationDev/简介-0.md" >}}) - - [基本规则]({{< relref "./docs/ApplicationDev/基本规则.md" >}}) - - [文件类型]({{< relref "./docs/ApplicationDev/文件类型.md" >}}) - - [编译流程]({{< relref "./docs/ApplicationDev/编译流程.md" >}}) - - [编译选项]({{< relref "./docs/ApplicationDev/编译选项.md" >}}) - - [多源文件编译]({{< relref "./docs/ApplicationDev/多源文件编译.md" >}}) - - [库]({{< relref "./docs/ApplicationDev/库.md" >}}) - - [动态链接库]({{< relref "./docs/ApplicationDev/动态链接库.md" >}}) - - [静态链接库]({{< relref "./docs/ApplicationDev/静态链接库.md" >}}) - - [示例]({{< relref "./docs/ApplicationDev/示例.md" >}}) - - [使用GCC编译C程序示例]({{< relref "./docs/ApplicationDev/使用GCC编译C程序示例.md" >}}) - - [使用GCC创建和使用动态链接库示例]({{< relref "./docs/ApplicationDev/使用GCC创建和使用动态链接库示例.md" >}}) - - [使用GCC创建和使用静态链接库示例]({{< relref "./docs/ApplicationDev/使用GCC创建和使用静态链接库示例.md" >}}) - [使用make编译]({{< relref "./docs/ApplicationDev/使用make编译.md" >}}) - - [简介]({{< relref "./docs/ApplicationDev/简介-1.md" >}}) - - [基本规则]({{< relref "./docs/ApplicationDev/基本规则-2.md" >}}) - - [文件类型]({{< relref "./docs/ApplicationDev/文件类型-3.md" >}}) - - [make工作流程]({{< relref "./docs/ApplicationDev/make工作流程.md" >}}) - - [make选项]({{< relref "./docs/ApplicationDev/make选项.md" >}}) - - [Makefile]({{< relref "./docs/ApplicationDev/Makefile.md" >}}) - - [示例]({{< relref "./docs/ApplicationDev/示例-4.md" >}}) - - [使用Makefile实现编译的示例]({{< relref "./docs/ApplicationDev/使用Makefile实现编译的示例.md" >}}) - [使用JDK编译]({{< relref "./docs/ApplicationDev/使用JDK编译.md" >}}) - - [简介]({{< relref "./docs/ApplicationDev/简介-5.md" >}}) - - [基本规则]({{< relref "./docs/ApplicationDev/基本规则-6.md" >}}) - - [文件类型及工具]({{< relref "./docs/ApplicationDev/文件类型及工具.md" >}}) - - [java程序生成流程]({{< relref "./docs/ApplicationDev/java程序生成流程.md" >}}) - - [JDK常用工具选项]({{< relref "./docs/ApplicationDev/JDK常用工具选项.md" >}}) - - [类库]({{< relref "./docs/ApplicationDev/类库.md" >}}) - - [示例]({{< relref "./docs/ApplicationDev/示例-7.md" >}}) - - [编译不带包的java程序示例]({{< relref "./docs/ApplicationDev/编译不带包的java程序示例.md" >}}) - - [编译带包的java程序示例]({{< relref "./docs/ApplicationDev/编译带包的java程序示例.md" >}}) - - [构建RPM包]({{< relref "./docs/ApplicationDev/构建RPM包.md" >}}) - - [打包说明]({{< relref "./docs/ApplicationDev/打包说明.md" >}}) - - [本地构建]({{< relref "./docs/ApplicationDev/本地构建.md" >}}) - - [搭建开发环境]({{< relref "./docs/ApplicationDev/搭建开发环境.md" >}}) - - [创建Hello World RPM包]({{< relref "./docs/ApplicationDev/创建Hello-World-RPM包.md" >}}) - - [下载源码]({{< relref "./docs/ApplicationDev/下载源码.md" >}}) - - [编辑SPEC文件]({{< relref "./docs/ApplicationDev/编辑SPEC文件.md" >}}) - - [构建RPM包]({{< relref "./docs/ApplicationDev/构建RPM包-8.md" >}}) - - [使用OBS构建]({{< relref "./docs/ApplicationDev/使用OBS构建.md" >}}) - - [OBS简介]({{< relref "./docs/ApplicationDev/OBS简介.md" >}}) - - [在线构建软件包]({{< relref "./docs/ApplicationDev/在线构建软件包.md" >}}) - - [构建已有软件包]({{< relref "./docs/ApplicationDev/构建已有软件包.md" >}}) - - [新增软件包]({{< relref "./docs/ApplicationDev/新增软件包.md" >}}) - - [获取软件包]({{< relref "./docs/ApplicationDev/获取软件包.md" >}}) - - [使用osc构建软件包]({{< relref "./docs/ApplicationDev/使用osc构建软件包.md" >}}) - - [安装并配置osc]({{< relref "./docs/ApplicationDev/安装并配置osc.md" >}}) - - [构建已有软件包]({{< relref "./docs/ApplicationDev/构建已有软件包-9.md" >}}) - - [新增软件包]({{< relref "./docs/ApplicationDev/新增软件包-10.md" >}}) - - [获取软件包]({{< relref "./docs/ApplicationDev/获取软件包-11.md" >}}) \ No newline at end of file + - [构建RPM包]({{< relref "./docs/ApplicationDev/构建RPM包.md" >}}) \ No newline at end of file