/
๐Ÿ› 
Linux Useful Commands
Search
Try Notion
๐Ÿ› ๐Ÿ› 
Linux Useful Commands
๐Ÿ’ก
Frequently used commands.
1. Modify hostname
vim /etc/hostname
Bash
2. Modify hosts
vim /etc/hosts
Bash
3. JDK installation
java -version ##java version "1.7.0_51" this os old vesrion then remove it rpm -qa| grep openjdk|xargs rpm -e --nodeps ##upload jdk to /usr/java tar /usr/java/xzvf jdk-8u144-linux-x64.tar.gz vim /etc/profile export JAVA_HOME=/usr/java/jdk1.8.0_144 export ##CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin source /etc/profile java -version
Bash
4. Yum install or replace
##1. 1. First, delete the original yum of redhat rpm -aq | grep yum | xargs rpm -e --nodeps rpm -aq | grep python-iniparse | xargs rpm -e --nodeps rpm -aq | grep yum rpm -aq | grep python-iniparse ##2. get Yum installation ##3. Install the downloaded rpm package rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm rpm -ivh yum-*.rpm # If anything is lacking during installation, find it in the downloaded software and install it ## 4. Create the file /etc/yum. repos. d/CentOS-Base. repo touch /etc/yum.repos.d/CentOS-Base.repo ##copy paste in CentOS-Base.repo [base] name=CentOS-$releasever - Base baseurl=https://mirrors.aliyun.com/centos/7/os/$basearch/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.aliyun.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.aliyun.com/centos/7/extras//$basearch/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.aliyun.com/centos/7/centosplus//$basearch/ gpgcheck=1 enabled=0 ####################### yum clean all Yum makecache
Shell
5. SNMP service
rpm -qa|grep snmp #If net-snmp-5.7. 2-1 is not available, it indicates that it has not been installed; ##otherwise, it indicates that it has been successfully installed ## If it is uninstalled, execute rpm -e net-snmp-XXX --nodeps yum list | grep net-snmp yum -y install net-snmp* ## Modify snmpd.conf sed command Cp /etc/snmp/snmpd. conf /etc/snmp/snmpd. conf. bak #First backup the configuration file Sed -i '41 s/public/cmsnmp/' /etc/snmp/snmpd. conf #modify line 41, public is cmsnmp sed -i '207s/#proc mountd/proc mountd/' /etc/snmp/snmpd.conf sed -i '210s/#proc ntalkd 4/proc ntalkd 4/' /etc/snmp/snmpd.conf sed -i '213s/#proc sendmail 10 1/proc sendmail 10 1/' /etc/snmp/snmpd.conf sed -i '272s/#exec echotest/exec echotest/' /etc/snmp/snmpd.conf sed -i '323s/#disk/disk/' /etc/snmp/snmpd.conf sed -i '352s/#load 12 14 14/load 12 14 14/' /etc/snmp/snmpd.conf sed -i '/.1.3.6.1.2.1.1/i\view systemview included .1' /etc/snmp/snmpd.conf #Match to the string ". 1. 3. 6. 1. 2. 1. 1", insert a line of content "view systemview included . 1" before it # Confirm the modification is successful: cat /etc/snmp/snmpd.conf | grep -E "cmsnmp|proc mountd|proc ntalkd|proc sendmail|exec echotest|load 12|view systemview"
Shell
5.2 Start net-snmp
systemctl restart snmpd.service ps -ef | grep snmpd
Bash
5.3 Verify net-snmp
## 1 Verify from the local client side snmpget -v 1 -c cmsnmp localhost sysUpTime. 0 # here localhost can also be replaced by local IP snmpwalk - v 2 c - c cmsnmp - m ALL localhost . 1. 3 | more # here localhost can also be replaced by local IP #### 2 Verify it from the snmp server side
Bash
6. FTP install
6.1 steps
a) Check if it is installed: rpm -qa|grep vsftpd
b) Use yume to install vsftpd: yum install vsftpd
c) After the installation is complete, set power-on self-start: chkconfig vsftpd on
d) Turn off the firewall systemctl stop firewalld. service
e) Configure ftp information
mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_bak grep -v "#" /etc/vsftpd/vsftpd.conf_bak > /etc/vsftpd/vsftpd.conf
Bash
f) Start the service: systemctl start vsftpd
g) Check if the ftp port is listening: netstat -tl
h) Create the ftp directory: mkdir /home/ftp
i) Assign permissions to the directory:
chmod -R 777 /home/ftp chgrp -R ftp /home/ftp
Bash
j) Create user:
useradd -d /home/ftp/scc -g ftp -s /sbin/nologin scc passwd scc
Bash
k) Restrict access to other users
##open config file vim /etc/vsftpd/vsftpd.conf
Bash
## edit config file local_root=/home/ftp/ #User login path chroot_local_user=YES #lock the user to the respective directory as the root directory user_config_dir=/etc/vsftpd/userconfig #user configuration directory ################
Bash
cd /etc/vsftpd/ mkdir userconfig cd userconfig/ vim scc local_root=/home/ftp/scc #copy paste in file systemctl restart vsftpd
Bash
6.2 FTP troubleshooting
getsebool -a | grep ftp # to see what is about ftp in selinux. ########################### ####Set all_ftpd_anon_write and allow_ftpd_full_access to on state setsebool -P allow_ftpd_anon_write on setsebool -P allow_ftpd_full_access on ############################# systemctl restart vsftpd ##restarts the FTP service to transfer files normally ##################################### ## if ftp user cannot log in chmod 644 /etc/shells chmod 664 /etc/vsftpd/ftpusers systemctl restart vsftpd
Bash
7. Docker installation
Copy docker-20.10. 4.tgz to target host user directory.
Use the command tar -zxvf docker-20.10. 4.tgz to decompress and get the docker folder.
Move all files in the docker folder to the /usr/bin directory.
mv /user_define_path/docker/* /usr/bin/
Use the command sudo dockerd & to start the docker daemon.
Copy docker.service to /usr/lib/systemd/system/ directory.
Modify permissions: chmod -R 755 /usr/lib/systemd/system/docker.service.
Run: systemctl enable docker.service.
The start-up and restart functions of docker are configured.
8. Redis cashe database installation
8.1 installation
Set the repository address of redis and execute the command: yum install epel-release
Installing redis yum install redis
Start redis systemctl start redis
If you want to access the database remotely, you shall open firewall port.(optional)
Set Auto-start execution command on power-up chkconfig redis on
firewall-cmd --zone=public --add-port=6379/tcp โ€“permanent firewall-cmd --reload firewall-cmd --list
Bash
6. To set up remote access, you need to modify the configuration file. First, find the location of the redis.config configuration file whereis redis.config then comment bind 127.0.0.1 (change password if you want)
Modify the redis. conf configuration file vim /etc/redis.conf
After the settings are completed systemctl restart redis
8.2 Test redis
Enter the redis interactive command line redis-cli
To add data to the database set 'a' 'bโ€™
8.3 Redis Troubleshootng
SpringBoot connects to the Redis service, DENIED Redis is running in protected mode because protected mode is enabled Soultion in Config file Modify protected-mode yes to NO
There is an authentication problem. Soultion Be Sure that the authentication password is set auth โ€œp@ssw0rdโ€
9. Influxdb installation
Download the installation package influxdb-1.8. 4.x86_64.rpm to the local
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.4.x86_64.rpm
Bash
Execute the installation in the directory where the installation package is located:
rpm -ivh influxdb-1.8.4.x86_64.rpm
Bash
View version influx -version
Start Up systemctl start influxdb.service
Set Power-on self-start systemctl enable influxdb.service
Verify curl http://localhost:8086/query?q=show+databases
Import Data influx -import -path=/root/influxdb_dump_out -precision=ns
Check if import was successful write influx in terminal .
View created databases: show databases.
Export database (this step is not required for deployment):
influx_inspect export -datadir "/var/lib/influxdb/data" -waldir "/var/lib/influxdb/wal" -out "influxdb_dump_out" -database "test" -start "2021-09-10T00:00:00Z"
Bash
Notes: if you want to view the influxdb database under the window system, you can download InfluxDBStudio-0.2. 0. zip, which is an installation-free software. After decompression, double-click "InfluxDBStudio.exe" and fill in the information of the influx database to connect and view.
10. Keepalive installation
yum install -y keepalived ipvsadm ipvsadm --save > /etc/sysconfig/ipvsadm echo 1 > /proc/sys/net/ipv4/ip_forward systemctl enable ipvsadm systemctl start ipvsadm ##Start-up need to configure net.ipv4.ip_forward=1 to /etc/sysctl.conf
Bash
11. Rabbitmq installation
Take the rabbitmq image: docker pull rabbitmq:3.9-management
View image id: docker image ls -a
Run the container:
docker run --name rabbitmq -d -p 15672:15672 -p 5672:5672 4b
23cfb64730, in which 4b23cfb64730 is the container id
Enter the container interactive interface:
docker exec -it "container id" sh
Add User
rabbitmqctl add_user admin admin rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" rabbitmqctl set_user_tags admin administrator
Bash
open browser http://ServerIP:15672 (user :admin , password : admin)
12. The deployment and installation of mysql
Download Mysql version 5.7.31
Mariadb is already installed by the rhel system and needs to be uninstalled. Check Mariadb, code rpm -qa|grep mariadb
Uninstall Mariadb rpm-emariadb-libs-5.5.52-1.el7.x86_64--nodeps
Check if mysql is installed and delete it rpm -aq | grep mysql
uninstall
rpm -ev mysql-community-common-5.7.12-1.el6.x86_64 --nodeps rpm -ev mysql-community-libs-5.7.12-1.el6.x86_64 --nodeps rpm -ev mysql-community-server-5.7.12-1.el6.x86_64 --nodeps rpm -ev mysql-community-client-5.7.12-1.el6.x86_64 --nodeps
Bash
Find MYSQl directory find / -name mysql
Delete MYSQL directory
rm -rf /var/lib/mysql rm -rf /var/lib/mysql/mysql rm -rf /usr/lib64/mysql rm -rf /usr/share/mysql rm -rf /usr/local/mysql #Delete my.cnf rm -rf /etc/my.cnf
Bash
create mysql folder mkdir -p /usr/local/mysql/
cd /usr/local/mysql/
tar -xf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.31-1.el7.x86_64.rpm systemctl start mysqld systemctl status mysqld
Bash
Login mysql -uroot -p
Change password: ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';