The SLS CLI supports most SLS features, including project management, Logstore management, log queries, automatic paging, and cross-account geo-replication.
Before you start
The SLS CLI requires Python. Download it from the official Python website.
|
Item |
Description |
|
Current CLI version |
0.2.9 Note
Run the install command to upgrade. Always use the latest version. |
|
Source code |
|
|
Supported Python versions |
|
|
Supported operating systems |
Windows, Linux, and macOS. |
|
Dependent components |
After installing Python, install these dependencies with
|
Step 1: Configure Python environment variables
Configure environment variables so that the aliyunlog commands run correctly. After configuration, you may need to restart your IDEs or services for the changes to take effect.
Configure Python environment variables in Linux and macOS
-
Create the
.bash_profilefile.NoteIf this is your first time setting environment variables, run
touch ~/.bash_profileto create the file. If it already exists, runvim ~/.bash_profileto edit it.touch ~/.bash_profile vim ~/.bash_profile -
View the Python installation directory.
which python3 -
Configure the
.bash_profilefile.export PATH=$PATH:/usr/local/python3/bin -
Apply the settings in the
.bash_profilefile.# Make the configuration file take effect. source ~/.bash_profile
Configure Python environment variables in Windows
Set environment variables in the Windows 10 GUI:
-
Find the Python installation path.
On the desktop, right-click This PC and select to find the environment variable for Python.
-
Add the Python environment variable.
On the desktop, right-click This PC, and select , for example, if the variable that you found in Step 1 is
D:\dev\python\python37\, the variable that you need to add isD:\dev\python\python37\bin.
Step 2: Install the CLI
Install the CLI in Linux
-
Log on to a Linux server.
-
Install the CLI:
pip3 install aliyun-log-python-sdk aliyun-log-cli -U --no-cache -
Verify the installation.
Run the following command:
aliyunlog --versionA successful output confirms the installation.
Install the CLI in Windows
-
Log on to a Windows server.
-
Open a command prompt.
If the Python environment variable is set, proceed to the next step. If pip3 is not found, navigate to the Python installation path with cd before running the install command.
-
Install the CLI:
pip3 install aliyun-log-python-sdk aliyun-log-cli -U --no-cache -
Verify the installation.
Run the following command:
aliyunlog --versionA successful output confirms the installation.
Install the CLI in macOS
Install the SLS CLI with pip3:
pip3 install -U aliyun-log-cli --no-cache
Upgrade the CLI
Re-run the install command to upgrade to the latest version.
Uninstall the CLI
To uninstall the CLI:
pip3 uninstall aliyun-log-cli
FAQ
The default Python version on an ECS Linux instance is 3.6. How do I upgrade Python to 3.7 or later?
Do not uninstall the default Python on ECS. Instead, modify the symbolic link or use a multi-version management tool.
-
Modify the symbolic link
-
Install a later Python version. Install Python using a package manager.
-
Run
which python3to find the installation path, for example/usr/bin/python3. -
Modify the symbolic link.
sudo which python3 pip3 rm -rf /usr/bin/python3 /usr/bin/pip3 # Add a symbolic link. /usr/bin/python3.11 is the installation path of the later version. sudo ln -s /usr/bin/python3.11 /usr/bin/python3 sudo ln -s /usr/bin/pip3.11 /usr/bin/pip3 -
Run
python -Vto verify the change.
-