In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Linux introduction
1 introduction
The Linux operating system is a clone system based on the UNIX operating system. It was born on October 5, 1991 (this is the first time it has been officially released).
With the help of Internet network and the joint efforts of computer enthusiasts all over the world, it has become the most widely used UNIX operating system in the world today, and the number of users is still growing rapidly.
2 birth
In early 1991, Linus Towaz began to learn the minix operating system on a 386sx compatible microcomputer. Through learning, he gradually could not be satisfied with the existing performance of the minix system, and began to plan to develop a new free operating system.
On October 5, 1991, Linus Torvaz announced the birth of the Linux kernel system (Free minix-like kernel sources for 386-AT) in a news release on the comp.os.minix newsgroup. This news can be called the birth manifesto of Linux and has been widely circulated.
Version 3
Mainstream Linux distributions: Ubuntu, CentOS, Red Hat, DebianGNU/Linux, Fedora,Gentoo,MandrivaLinux, PCLinuxOS,SlackwareLinux, openSUSE,ArchLinux,Puppylinux,Mint, etc.
Mainland distribution: winning Kirin Linux (formerly Puhua Linux), Red Flag Linux (Red-flag Linux), starting point operating system StartOS (formerly Ylmf OS), Qomo Linux (former Everest), Surfing Linux (Xteam Linux), Blue Point Linux, Xinhua Linux, Co-creation Linux, Bai Zi Linux, veket,lucky8k-veket.Open Desktop, Hiweed GNU/Linux, Magic Linux, Engineering Computing GNU/Linux, kylin, medium soft Linux, Xinhua Radium Linux (RaysLX), CD Linux, MC Linux, Instant Linux (Thizlinux) B2D linux, IBOX, MCLOS,FANX, Kubo linux, Linux,Hiweed,Deepin Linux (Deep linux).
4 Application
A large number of servers in data centers around the world are already based on the Linux Server platform. Linux Server offers more advantages than Windows Server. Many international Internet giants, including Google, Twitter, Facebook and Amazon, run their services on Linux Server-based servers.
Android is an open source operating system based on Linux and JAVA, which is mainly used in portable devices. The Android operating system was originally developed by Andy Rubin and was acquired by Google and then led and developed by Google and the Open Mobile Alliance, mainly supporting mobile phones and tablets.
5 characteristics
Free open source operating system
Multi-tasking, multi-user, rich network functions, reliable system security, good portability, standard compatibility, good user interface, excellent speed performance
6 CentOS
is free: RedHat is not much different from CentOS and is based on the enterprise CentOS version of freely available source code provided by RedHat Linux.
mainstream: the current Linux operating system is mainly used in the production environment, the mainstream enterprise Linux system is still RedHat or CentOS.
Easy to update : CentOS's unique yum command supports online upgrades and can update the system instantly, unlike RedHat, which costs money to buy support services!
7 Linux directory structure
Bin (binaries) stores binary executable files
Sbin (super user binaries) stores binary executable files, which only root can access
Etc (etcetera) stores system configuration files
Usr (unix shared resources) is used to store shared system resources
Home root directory where user files are stored
Root superuser directory
Dev (devices) is used to store device files
Lib (library) stores shared libraries and kernel modules needed to run programs in the file system.
Mnt (mount) system administrator mounts the temporary file system mount point
Boot stores all kinds of files used for system boot
Tmp (temporary) is used to store all kinds of temporary files
Var (variable) is used to store files that need to change data at run time
Linux installation
1 prepare the software
Windows7,8,10 [free up 50g space]
CentOS-6.7-x86_64-bin-DVD1.ISO [installation disk]
CentOS-6.7-x86_64-bin-DVD2.ISO [installation disk]
VMWare11-lite.rar [virtual machine software]
SecureCRT_33lc [SSH operating software]
Download address: [find Brother Niu for free: qq-1325821989]
2 install virtual machine software
Decompress: VMWare11-lite.rar
Click install.
3 NAT network planning
4 install linux virtual machine min1
File-create new virtual Machine select Custom, nextNext select I will install the operatin system later, next select linux,version (CentOS 64-bit), next input: Name: min1, location: G:\ Machines\ min1, nextCpu,core, select 1, next select 1G of memory, next select NAT network, next select LSI Logic,next select create a new virtual disk,next enter 20g camera next enter min1.vmdk,next click Finish
5 set up NAT network
Vmware-Edit-virtual network editor
6 min1 install centos system
6.1 Edit virtual machine setting
6.2 Select the installation CD
6.3 Power on starts installation
6.4. enter the installation interface and Ctrl-alt can switch the mouse.
6.5 Select skip
6.6 enter hostname min1
Input password: hadoop
6.8 Select Mininal installation
6.9 complete the installation
Linux network card configuration
1 right-click on Min1, power on starts
2 Log in to linux
User root
Password hadoop
3 configure the network card
vi / etc/sysconfig/network-scripts/ifcfg-eth0
Make the following settings
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.33.61
NETMASK=255.255.255.0
GATEWAY=192.168.33.1
DNS1=192.168.33.1
reboot
4 set the VMnet8 network card of window
5 Ping linux [192.168.33.61] in window, successful
(4) linux cloning
1 Open VMware and right-click on min1-manage-clone
2 Select create a full clone
3 enter min3, and modify the path to g:\ Machines\ min3
4 Click finish
5 start the virtual machine min3 and enter root/hadoop to log in
6 Network Card Settings-min2-IPADDR=192.168.33.62
1: modify vi / etc/sysconfig/network-scripts/ifcfg-eth0 directly
2: delete UUID HWADDR
3: set ONBOOT=YES
4: configure static address:
BOOTPROTO=none
IPADDR=192.168.33.62
NETMASK=255.255.255.0
GATEWAY=192.168.33.1
DNS1=192.168.33.1
5: then delete:
Rm-rf / etc/udev/rules.d/70-persistent-net.rules
6: modify the host name:
Cd / etc/sysconfig
Vi network
NETWORKING=yes
HOSTNAME= min2
7: then reboot
7 Network Card Settings-min3-IPADDR=192.168.33.63
1: modify vi / etc/sysconfig/network-scripts/ifcfg-eth0 directly
2: delete UUID HWADDR
3: set ONBOOT=YES
4: configure static address:
BOOTPROTO=none
IPADDR=192.168.33.63
NETMASK=255.255.255.0
GATEWAY=192.168.33.1
DNS1=192.168.33.1
5: then delete:
Rm-rf / etc/udev/rules.d/70-persistent-net.rules
6: modify the host name:
Cd / etc/sysconfig
Vi network
NETWORKING=yes
HOSTNAME= min3
7: then reboot
(5) the use of SecureCRT
1 decompress the securecrs_33lc
2 Open G:\ soft\ securecrs_33lc and start SecureCRTPortable.exe
3 File-quick connect
4 enter ip:192.168.33.61 and account root
5 Click OK and enter the password
6 Click ok to enter the SSH terminal:
(6) Common commands of linux
1.1 Daily operating commands
View the current working directory
Pwd
View the time of the current system
Date
See who is online (who is logged on to the server)
Who to view the current online
Last to view recent login history
1.2 File system operation
View Fil
Ls / View child nodes (folders and files) information under the root directory
Ls-al-a shows hidden files-l is displayed in a more detailed list
Display in ll list form
Ll-a shows hidden files
Switch directories
Cd / home
Create a folder
Mkdir aaa, this is the relative path.
Mkdir-p aaa/bbb/ccc batch create file path
Mkdir / data this is how to write the absolute path
Delete folder
Rmdir can delete empty directories
Rm-r aaa can delete the entire aaa folder and all its child nodes.
Rm-rf aaa forcibly delete aaa
Modify folder name
Mv aaa aa1
Create a file
Touch fbb.txt creates an empty file
Echo "hello fbb" > fbb.txt uses the redirect ">" function to write the output of an instruction to a file, which will overwrite the contents of the original file.
Echo "hello, liu yi fei" > > lyf.txt appends the output of an instruction to a file without overwriting the contents of the original file.
1.3 Operation of file permissions
Interpretation of the description format of linux File permissions
Drwxr-xr-x (you can also use binary for 111101-> 755)
D: identify the node type (d: folder -: file l: link)
R: readable w: writable x: executable
The first set of rwx: indicates the permissions of the owner of this file to it: readable, writable and executable
The second group rmurx: indicates the permissions of the group to which the file belongs to it: readable, unwritable, executable
The third group rmurx: indicates the permissions of other users of this file (as opposed to the above two types of users) to it: readable, unwritable, executable
Modify file permissions
Chmod g-rw fbb.txt means to revoke fbb.txt 's rw permission on the group to which it belongs.
Chmod o-rw fbb.txt says to revoke fbb.txt 's rw rights to other people.
Chmod uplix fbb.txt means to increase the permissions of fbb.txt to its users by x
Permissions can also be modified digitally.
Chmod 664 fbb.txt
It will be changed to rw-rw-r-: because 1101101000664
If you want to modify all the content permissions of a folder uniformly, you can use the-R parameter
Chmod-R 770 aaa/
Chown changes the owner of the specified file to the specified user or group. The user can be a user name or a user ID; group can be a group name or a group ID.
Chown user name: group name
Chown fbb:fbb aaa/
Note:
Ordinary users cannot enter when the directory does not have execution permission
When the file only has read and write permissions, ordinary users can delete as long as the parent directory has the permission to execute and modify. (to delete a file is not to modify it, but to manipulate the parent directory)
1.4 basic user management
Add user
Useradd fbb
You need to change your password to log in.
Passwd fbb can enter the password as prompted.
Configure sudo permissions for the user
Edit vi / etc/sudoers with root
Add a line for fbb in the following location of the file
Root ALL= (ALL) ALL
Fbb ALL= (ALL) ALL
Fbb users can then use sudo to execute system-level instructions
[fbb@min1~] $sudo useradd hadoop
1.5 system management operations
View hostname
Hostname
Modify hostname (invalid after restart)
Hostname min1fbb
Modify the hostname (take effect permanently after restart)
Vi / etc/sysconfig/network
Modify IP (invalid after restart)
Ifconfig eth0 192.168.33.161
Modify IP (take effect permanently after restart)
Vi / etc/sysconfig/network-scripts/ifcfg-eth0
Mount mounts external storage devices to the file system
Mkdir / mnt/cdrom creates a directory for mounting
Mount-t iso9660-o ro / dev/cdrom / mnt/cdrom/ mount the device / dev/cdrom to the mount point: / mnt/cdrom
Umount
Umount / mnt/cdrom
Count the size of files or folders
Du-sh / mnt/cdrom/Packages
Df-h view disk space
Shutdown
Halt
Restart
Reboot
1.6 configure a domain name server
Modify the mapping between ip address and host name
Vi / etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.33.61 min1192.168.33.62 min2192.168.33.63 min3
1.7 configure secret-free ssh login between hosts
If min1 wants to log in to min2,
Operate on min1:
First generate a key pair
Ssh-keygen (enter directly when prompted)
Then copy and append min1's own public key to min2's authorization list file authorized_keys
Ssh-copy-id min2
Verify the effect:
Ssh min2
[root@min1 ~] # ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/ root/.ssh/id_rsa): Created directory'/ root/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again:Your identification has been saved in / root/.ssh/id_rsa.Your public key has been saved in / root/.ssh/id_rsa.pub.The key fingerprint is:96:b9:d1:66:55:78:cb:36:5e:dd : b2:0e:34:48:7e:00 root@min1The key's randomart image is:+-- [RSA 2048]-+ | E. | | o. | | o.o.o | | + o.o * + | | S + o + = | |. =. O | |. O | |. | +-+ [root@min1 ~] #
[root@min1 ~] # ssh-copy-id min2root@ min2's password: [hadoop] Now try logging into the machine, with "ssh 'min2'", and check in: .ssh / authorized_keys to make sure we haven't added extra keys that you weren't expecting.
[root@min1] # ssh min2 Last login: Wed Jan 9 06:37:44 2019 from 192.168.33.2 [root@min2] # [root@min2] #
1.8 problems with minimal installed systems-missing commands
There will be a lack of commands and dependencies when installing software.
The scp command is not available, but can be obtained by installing: yum install-y openssh-clients
It has to be installed on every machine in the cluster.
(7) the use of vi text editor
1.1 basic usage
Vi fbb.txt
1. First of all, it will enter the "general mode", which only accepts all kinds of shortcut keys and cannot edit the contents of the file.
2. Press the I key, and you will enter the editing mode from the general mode. In this mode, what you type in is the content of the file.
3. After editing, press ESC to exit editing mode and return to normal mode.
4. Press: again to enter the "bottom line command mode", enter the wq command, and enter enter.
1.2 commonly used shortcut keys
Some useful keyboard shortcuts (used in general mode):
A starts inserting one bit after the cursor
An insert at the end of the line
I insert at the front of the line
Gg jumps directly to the first line of the file
G jumps directly to the last line of the file
Dd deletes lines, if 5dd, deletes 5 lines after the cursor at once
If yy copies the current line and copies multiple lines, then 3yy copies the 3 lines near the current line
P paste
V enters character selection mode. Press y to copy and p to paste when the selection is complete.
Ctrl+v enters block selection mode. When the selection is complete, press y to copy and p to paste
Shift+v enters row selection mode. When the selection is complete, press y to copy and p to paste
Find and replace (enter in bottom line command mode)
% s/fbb/lyf effect: find all fbb in the file and replace it with lyf
/ lyf effect: find the lyf that appears in the file, and navigate to the first place to find it, press n to navigate to the next matching location (press N to navigate to the previous one)
(8) Compression and decompression operation
1.gzip compression
Gzip a.txt
two。 Decompression
Gunzip a.txt.gz
Gzip-d a.txt.gz
3.bzip2 compression
Bzip2 a.txt
4. Decompression
Bunzip2 a.txt.bz2
Bzip2-d a.txt.bz2
5. Package the files in the current directory
Tar-cvf bak.tar.
Append / etc/password file to bak.tar (r)
Tar-rvf bak.tar / etc/password
6. Decompression
Tar-xvf bak.tar
7. Package and compress gzip
Tar-zcvf a.tar.gz.
8. Decompress
Tar-zxvf a.tar.gz
Decompress to / usr/
Tar-zxvf a.tar.gz-C / usr
9. View the contents of the package
Tar-ztvf a.tar.gz
Zip/unzip
10. Packaged and compressed into bz2
Tar-jcvf a.tar.bz2
11. Decompress bz2
Tar-jxvf a.tar.bz2
(9) linux service management
1 backend service management
Service network status to view the status of the specified service
Service network stop stops the specified service
Service network start starts the specified service
Service network restart restarts the specified service
Service-status-all to view all backend services in the system
2 set the self-startup configuration of the backend service
Chkconfig to view all server self-boot configurations
Chkconfig iptables off shuts down the automatic startup of the specified service
Chkconfig iptables on enables the automatic startup of the specified service
= = add automatic startup service for mysql = =
Boot:
Chkconfig-add mysqld
Chkconfig mysqld on
3 system startup level management
Vi / etc/inittab
Default runlevel. The runlevels used are:0-halt (Do NOT set initdefault to this) 1-Single user mode2-Multiuser, without NFS (The same as 3, if you do not have networking) 3-Full multiuser mode4-unused5-X116-reboot (Do NOT set initdefault to this)
#
Id:3:initdefault:
(10) Domain name server
1 schematic diagram
2 hostname configuration
Modify hostname
Vi / etc/sysconfig/network
NETWORKING=yes
HOSTNAME=minfbb
3 Hosts configuration
Modify the mapping between ip address and host name
Vi / etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.33.61 min1192.168.33.62 min2192.168.33.63 min3
4 Firewall switch
Turn off iptables and set it to boot / not boot
Service iptables stop, turn off the firewall
Chkconfig iptables on setting to boot boot firewall
Chkconfig iptables off setting to power on and turn off the firewall
(11) Linux software installation-jdk
1 upload installation package
Use the sftp tool: after alt+p is called up, upload it with the put command
1.1 upload (if you do not specify a directory, upload to the current user's home directory):
Sftp > cd / root/
Sftp > put g:\ soft\ jdk\ jdk-7u45-linux-x64.tar.gz
1.2 download (lcd specifies the destination path to download locally)
Sftp > lcd dvl /
Sftp > get / root/jdk-7u45-linux-x64.tar.gz
2 install jdk
2.1 Compression and decompression commands
2.1.1 Compression and decompression
Root@mini1 ~] # gzip access.log
[root@mini1 ~] # ll
The total dosage is 134892
-rw-r--r--. 1 root root 68 April 3 17:37 access.log.gz
Extract the gz file: gzip-d access.log.gz
2.1.2 packing and unpacking
[root@mini1 ~] # tar-cvf actor.tar actor/
Actor /
Actor / fbb.txt
Actor / lyf.txt
Actor / ddrb.txt
2.1.3 unpacking:
[root@mini1 ~] # tar-xvf actor.tar
Actor /
Actor / fbb.txt
Actor / lyf.txt
Actor / ddrb.txt
2.1.4 Packaging and compression is completed at the same time
2.1.5 generate a compressed package:
[root@mini1 ~] # tar-zcvf actor.tar.gz actor /
Actor /
Actor / fbb.txt
Actor / lyf.txt
Actor / ddrb.txt
2.1.6 decompression package:
[root@mini1 ~] # tar-zxvf actor.tar.gz
Actor /
Actor / fbb.txt
Actor / lyf.txt
Actor / ddrb.txt
2.2 the process of installing jdk
2.2.1 extract the installation package
Cd / root
Tar-zxvf jdk-7u45-linux-x64.tar.gz-C apps/
2.2.2 modify environment variables
Vi / etc/profile
2.2.3 Last addition of the file
Export JAVA_HOME=/root/apps/jdk1.7.0_45
Export PATH=$PATH:$JAVA_HOME/bin
2.2.4 Save exit
2.2.5 reload environment variables
Source / etc/profile
2.2.6 Test
[root@min1 jdk1.7.0_45] # java-version
The following indicates that the installation is successful:
Java version "1.7.045"
Java (TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot (TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
3 install tomcat
3.1 upload apache-tomcat-7.0.68.tar.gz to Linux
3.2 decompress tomcat
Tar-zxvf apache-tomcat-7.0.68.tar.gz-C / root/apps/
3.3.Starting tomcat
/ root/apps/apache-tomcat-7.0.68/bin/startup.sh
3.4 check to see if the tomcat process starts
Jps
3.5 View tomcat process port
Netstat-ntlp / / View all current tcp ports
Netstat-anpt | grep 2465 / / View the port occupied by the process
Netstat-ntulp | grep 80 / / View the usage of all ports 80
Netstat-an | grep 3306 / / View the usage of all 3306 ports
3.6 access to tomcat through a browser
Http://192.168.33.61:8080/
(12) the method of installing yum software
1 YUM installation method
Yum (full name Yellow dog Updater, Modified) is a Shell front-end package manager in Fedora and RedHat, as well as in SUSE and CentOS. Based on RPM package management, RPM packages can be downloaded and installed automatically from designated servers, dependencies can be automatically handled, and all dependent software packages can be installed at once without having to download and install them again and again.
example (need to go online):
Yum install gcc-c++
Yum remove gcc-c++
Yum update gcc-c++
2 the CD is mounted to the local file directory
Mount-t iso9660 / dev/cdrom / mnt/cdrom
[- t specifies the type of file system; iso9660 CD or CD image]
To avoid having to manually mount after every restart, you can add a line of mount configuration in / etc/fstab to mount automatically.
Vi / etc/fstab
/ dev/cdrom / mnt/cdrom iso9660 defaults 0 0
3 installation and configuration of the local yum repository
3.1 View existing yum feeds
Yum repolist all
3.2 ideas for creating local sources:
Mount iso to local
Expose yum to the intranet through http services
Modify the repo file of yum to specify the yum dependency of the private network
3.3 create a new local mount directory / mnt/cdrom
Mkdir-p / mnt/cdrom
3.4 Mount ios to / mnt/cdrom
Mount / dev/cdrom / mnt/cdrom
Hang the CD in the local file directory
Mount-t iso9660 / dev/cdrom / mnt/cdrom
To avoid having to manually mount after every restart, you can add a line of mount configuration in / etc/fstab to mount automatically.
Vi / etc/fstab
/ dev/cdrom / mnt/cdrom iso9660 defaults 0 0 =
Problems with minimal installed system: lack of various commands, lack of various dependencies when installing software
There is no scp command: yum install-y openssh-clients
It has to be installed on every machine.
3.5 install httpd
Yum-y install httpd
3.6 start httpd
Service httpd start
3.7 check whether it is enabled successfully after startup
Netstat-nltp | grep httpd
3.8 Open port 80
/ sbin/iptables-I INPUT-p tcp-- dport 80-j ACCEPT
3.9 set the boot to start automatically
Chkconfig-add httpd
Chkconfig httpd on
3.10 yum joins httpd service
The root directory of the default httpd is / var/www/html
Just create a new shortcut key for / mnt/cdrom in this directory
Ln-s / mnt/cdrom / var/www/html/repo
[when the source of the-s soft link (symbolic link) disappears, the link fails]
3.11 Test the http service
Http://ip:80/repo
Http://192.168.33.61/repo/
3.12 modify repo dependent files
.repo file is the abbreviation of repository, which means container, and the container file is what we often call the yum software source configuration file.
The repo file is in / etc/yum.repos.d/
3.13 rename all files, leaving one to modify
Cd / etc/yum.repos.d/
Rename .repo .repo.bak * .repo
Mv CentOS-Media.repo.bak CentOS-Media.repo
Vi CentOS-Media.repo is modified to
[c6-media]
Name=CentOS-$releasever-Media
Baseurl= http://192.168.33.61/repo
File:///media/CentOS/file:///media/cdrom/file:///media/cdrecorder/gpgcheck=1
Enabled=1
# gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Gpgkey= http://192.168.33.61/repo/RPM-GPG-KEY-CentOS-6 or
[c6-media]
Name=CentOS-$releasever-Media
Baseurl= http://192.168.33.61/repo
File:///media/CentOS/file:///media/cdrom/file:///media/cdrecorder/gpgcheck=0
Enabled=1
Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-63.14 checks whether the local source is made successfully.
Yum repolist all loaded plug-in: fastestmirror
Loading mirror speeds from cached hostfile
Warehouse identifies warehouse name status
C6-media CentOS-6-Media enabled: 6575
Repolist: 6Jing 5753.15 finally install telnet through the local yum:
Yum-y install telnet
Loaded plug-in: fastestmirror
Set up the installation process
Loading mirror speeds from cached hostfile
Resolve dependencies
-- > perform transaction check
-> Package telnet.x86_64 1RU 0.17-48.el6 will be installation
-- > complete dependency calculation
Dependency resolution package architecture version repository size
Installing:
Telnet x86x 64 1purl 0.17-48.el6 c6-media 58k
Transaction summary
Install 1 Package (s)
Total downloads: 58k
Installed size: 109 k
Download the software package:
Telnet-0.17-48.el6.x86_64.rpm | 58 kB 00:00
Run rpm_check_debug
Perform transaction testing
Transaction test was successful
Execute a transaction
Installing: 1:telnet-0.17-48.el6.x86_64 1 Compact 1
Verifying: 1:telnet-0.17-48.el6.x86_64 1 Compact 1
Installed:
Telnet.x86_64 1Rank 0.17-48.el6
Over!
4 virtual machine error
The solution to "\.\ Global\ vmx86"
1 look for vmx86.sys (ctrl+f) in the virtual machine installation directory, usually in the C:\ Program Files (x86)\ VMware\ VMware Workstation directory after installation
2 put the vmx86.sys found in the C:\ windows\ system32\ drivers directory
3 start, run, cmd
4. Enter net stop vmx86 in cmd and enter enter
5. Enter net start vmx86 in cmd to start the virtual machine!
(13) use yum to install MySQL under Linux
Install MySQL using yum under Linux, and launch, log in, and remotely access the MySQL database.
1 install mysql
1.1 check to see if it is installed
Yum list installed mysql
Rpm-qa | grep mysql
1.2 check to see if there is a package installed
Yum list mysql
1.3 install the mysql client
Yum install mysql
1.4 install the mysql server side
Yum install mysql-server
Yum install mysql-devel
2 start and stop services
2.1 Database character set settings
Add default-character-set=utf8 to mysql configuration file / etc/my.cnf
2.2 start the mysql service
Service mysqld start or / etc/init.d/mysqld start
2.3 set up boot boot
Chkconfig-add mysqld
Chkconfig mysqld on
2.4 check whether the boot settings are successful
Chkconfig-- list | grep mysql
Mysqld 0: off 1: off 2: enable 3: enable 4: enable 5: enable 6: close
2.5 commands to stop the service
Service mysqld stop
3 mysql authorized access
Mysql-uroot-p # (execute the following statement.: all tables under all libraries%: any IP address or host can connect, 'root123456' password) GRANT ALL PRIVILEGES ON. TO 'root'@'%' IDENTIFIED BY' root123456' WITH GRANT OPTION;FLUSH PRIVILEGES
4 login
Create a root administrator: mysqladmin-u root password root123456
Login: mysql-u root-p enter your password.
Reset password after forgetting password: service mysqld stop
Mysqld_safe-user=root-skip-grant-tables
Mysql-u root
Use mysql
Update user set password=password ("123456") where user= "root"
Flush privileges
5 remote access
Port number of the open firewall
Mysql added permissions: add a record to the user table in the mysql library: host is "%" and user is "root".
6 several important catalogs of Linux MySQL
Database directory: / var/lib/mysql/
Configuration file: / usr/share/mysql (mysql.server command and configuration file)
Related commands: / usr/bin (mysqladmin mysqldump, etc.)
Startup script: / etc/rc.d/init.d/ (directory of startup script file mysql)
(14) usage of mysql
1 # Log in to database
Mysql-h localhost-u root-p
Mysql-u root-p
2 # change password
Mysqladmin-uroot-pold password new
3 # display database
Show databases
4 # display data sheet
Show tables
5 # Select a database
Use examples
6 mysql authorized access
Mysql-uroot-p # (execute the following statement.: all tables under all libraries%: any IP address or host can connect) GRANT ALL PRIVILEGES ON. TO 'root'@'%' IDENTIFIED BY' root123456' WITH GRANT OPTION;FLUSH PRIVILEGES
7 # create database and set encoding utf-8 multi-language
Create database examples default character set utf8 collate utf8_general_ci
8 # Delete database
Drop database examples
9 # create a table
Create table test (
Id int (10) unsigned zerofill not null auto_increment
Email varchar (40) not null
Ip varchar (15) not null
State int (10) not null default'- 1'
Primary key (id)
);
10 # display table structure
Describe
11 # Delete table
Drop table test
12 # rename form
Alter table test_old rename test_new
13 # add column
Alter table test add cn int (4) not null
14 # modify column
Alter table test change id id1 varchar (10) not null
15 # Delete columns
Alter table test drop cn
16 # create an index
Alter table test add index (cn,id)
17 # Delete index
Alter table test drop index cn
18 # insert data
Insert into test (id,email,ip,state) values (127.0.0.1) values (127.0.0.1)
19 # Delete data
Delete from test where id = 1
20 # modify data
Update test set id='1',email='q@qq.com' where id=1
21 # check data
Select from test; # fetch all data
Select from test limit 0pr 2; # fetch the first two pieces of data
Select from test email like'% qq%' # lookup contains the qq character _ for one% for multiple
Select from test order by id asc;# descending desc
Select from test id not in ('2 minutes and 3'); # id does not contain 2 or remove not to indicate that it contains
Select from test timer between 1 and 10 position # data is between 1 and 10
#-knowledge of table joins
# equivalent join also known as inner link inner join only returns rows with equal join fields in two tables
Select from An inner join B on A.id = B.ID; # write 1
Select from A Magi B where A.id = B.ID; # Writing 2
Select a.idpene a.title from An an inner join B b on a.id=b.id and a.idquarter1witz # temporary name of table 3
Select a.id as ID,a.title as title from An inner join B on A. idler B.idscape # add as sentence
# left join is also called external join left join returns all records in the left table that are equal to the join fields in the right table
Select * from A left join B on A.id = B.id
Select * from A left join (Bjens Cpene D) on (B.i1=A.i1 and C.i2=A.i2 and D.i3 = A.i3); # complex connections
# right join also called external connection right join returns all records in the right table that are equal to the join fields in the left table
Select * from A right join B on A.id = B.id
# full external link full join returns all the data in the left and right tables
Select * from A full join B on A.id = B.id
# Cross-connect returns Qadir product without where words
Select * from A cross join B
-end of table connection-
-Index creation-
Show index from A # View Index
Alter table An add primary key (id) # Primary key Index
Alter table An add unique (name) # unique index
Alter table An add index name (name) # General Index
Alter table An add fulltext (name) # full text Index
Alter table An add index name (id,name) # Multi-column index
22 # Common functions
Abs (- 1) # absolute value
Pi () # pi value
Sqrt (2) # square root
Mod (- 5pm 3) # take residue-2
Ceil # carry + 1 result 11 ceil (10.0) result 10
Floor (10.6) # rounded 10
Round (2.5) # rounded to integer result 3
Round (2.5) # preserves two decimal places and results 2.50
Truncate (2.5234) # the last 3 decimal places are not rounded up to 2.523
Sign (- 2); # sign function returns-1 0 or 0 positive number returns 1
Pow (2), exp (2); # 2 to the third power or e to the second power
Log (2), log10 (2); # logarithm
Radians (180), degrees (0.618); # Angle Radian conversion
Sin (0.5), asin (0.5) # sinusoidal and arcsine are similar to cos acos tan atan
Length ('hi') # calculates the character length
Concat ('1merge, 1merge, merge, etc.
Insert ("12345"); # from the beginning of the first character to the end of 0, replace it with the trailing string, and 0 means to insert at the beginning
Ucase ('a'), lcase ('A') # converted to uppercase and lowercase
Left ('abcd',2), right (' abcd',2); # returns the first two characters and the last two characters
Ltrim ('0'), rtrim ('0'), trim ('0') # remove spaces
Replace ('1234567890' replacement output 12090)
Substring ('12345 characters 1, 2) # take character output 12 1 is position 2 is length
Instr ('1234'); # the position is 2.
Reverse ('1234'); # reverse output 4321
Current () # return date
Curtime () # return time
Now () # returns the date and time
Month (now ()) # current month monthname English month
Dayname (now ()) # week English dayofweek () 1 is Sunday weekday () 1 is Tuesday
Week (now ()) # more or less weeks this year
Dayofyear (now ()), dayofmonth (now ()) # Today is the most or less day of this year. Today is the day of this month.
Year (now ()), month (now ()), day (now ()), hour (now ()), minute (now ()), second (now ()) # returns the year, month, day, minute and second
Time_to_sec (now ()), sec_to_time (3600 to 8); # conversion time is seconds and restore
Version () # mysql version
Database () # the currently connected database is not null
User () # get the user name
Md5 ('a') # encrypted string
Ascii ('a') # ascii value 97
Bin, hex, oct # returns binary hexadecimal
Conv (1000-1-2-8); # conversion of various binary systems to each other
Rand () # generates random numbers between 0 and 1
Sleep (0.02) # pause seconds
23 Database optimization
. Turn on caching and try to use the php function instead of mysql
. The explain select statement can know the performance
. One row of data uses limit 1
. Re-index search fields such as keyword tags
. The table join join ensures that the field type is the same and has its index
. Random queries use php $r = mysql_query ("SELECT count () FROM user")
$d = mysql_fetch_row ($r)
$rand = mt_rand (0sperm [0]-1)
$r = mysql_query ("SELECT username FROM user LIMIT $rand, 1")
. Avoid using select should use specific fields
. Each table uses the id primary key and is unsigned int
. Fixed use of enum types for limited values, such as gender, national and ethnic sector status
. Use not null ip storage as much as possible using int (4), and use the ip conversion function ip2long () to long2ip each other ()
.delete and insert statements lock tables, so you can use split statements to operate
While (1) {Action statement; usleep (2000);}
. Choose the right storage engine; MyISAM is suitable for a large number of query write operations, multi-purpose InnoDB to support transactions
24 # stored procedure
# stored program
Delimiter # define stored procedures
Create procedure getversion (out params varchar (20)) # params is the outgoing parameter in in out out inout back
Begin
Select version () into params; # version information assignment params
End
Call getversion (@ a); # call stored procedure
Select @ a
Delimiter # defines storage functions
Create function display (w varchar (20)) returns varchar (20)
Begin
Return concat ('hello',w)
End
Select display ('world')
Drop procedure if exists spName; # Delete a stored procedure
Alter function spName []; # modify a stored procedure
Show create procedure spName;# displays stored procedure information
Declare varName type default value;# declares local variables
# if statement
If conditional then statement
Elseif conditional then statement
Else statement
End if
# case statement
Case condition
When conditional then statement
When conditional then statement
Else statement
End case
# loop statement
Fn:loop
Statement
End loop fn
Leave fn # exit the loop
# while statement
Fn:while conditional do
Statement
End while fn
25 # mysql usage help material
? Contents; # lists help types
? Data types;# lists data types
? Int;# lists specific types
? Show;#show statement
? Create table;#
26 # comparison of common tables
Myisam BDB Memory InnoDB Archive
Storage limit no no yes 64T no
Thing security support
Lock mechanism table lock page lock row lock row lock
Full-text indexing support
Foreign key support
Myisam frm storage table definition MYD storage data MYI storage index
InnoDB for transaction processing
Char and varchar have different saving and indexing
Floating-point number float (10) fixed-point number decimal (10)
When the length is fixed, the floating point number represents a more big data range, but the disadvantage is that the precision is lost and the currency is stored with a fixed point number.
The index is suitable for where sentences or join sentence columns
Use a unique index for unique values
Add a new user grant select,insert,update,delete on. To Yoby@localhost identified by 'mysql'
. Database name. Table name, restrict login to a database test.* localhost is local host network can use'% 'instead of all hosts' mysql' is password Yoby is user name all permissions can be replaced by all
View user permissions show grants for 'root'@'localhost'
Remove permission revoke all on. From root@localhost
Group by id grouping
Having restricted sentence
Select1 union select2 federated query has repeatedly removed and reserved a row
Merge all rows of select2 union all select2 into the result set
(15) detailed explanation of yum command
Yum (Yellow dog Updater, Modified) is a Shell front-end package manager in Fedora and RedHat as well as in SUSE. Based on RPM package management, RPM packages can be downloaded and installed automatically from designated servers, dependencies can be automatically handled, and all dependent software packages can be installed at once without having to download and install them again and again. Yum provides commands to find, install, and delete one, a group, or even all of the software packages, and the commands are concise and easy to remember.
The command form of yum is generally as follows: yum [options] [command] [package.]
[options] is optional, and the options include-h (help),-y (when prompted by the installation process to select all "yes"),-Q (does not show the installation process), and so on. [command] for the operation to be performed, [package...] Is the object of the operation.
Some commonly used commands are summarized as follows:
Automatically search for the fastest image plug-in: yum install yum-fastestmirror
Install the yum graphics window plug-in: yum install yumex
View a list of possible bulk installations: yum grouplist
1.1 installation
Yum install all installed
Yum install package1 installs the specified installation package package1
Yum groupinsall group1 installer group group1
1.2 updates and upgrades
Update all yum update
Yum update package1 updates the specified package package1
Yum check-update checks for updatable programs
Yum upgrade package1 upgrade specified package package1
Yum groupupdate group1 upgrader group group1
1.3 find and display
Yum info package1 displays installation package information package1
Yum list displays all packages that have been and can be installed
Yum list package1 displays the installation of the specified package package1
Yum groupinfo group1 displays the program group group1 information yum search string finds the installation package according to the keyword string
1.4 remove programs
Yum remove | erase package1 delete package package1
Yum groupremove group1 delete program group group1
Yum deplist package1 to view program package1 dependencies
1.5 clear cach
Yum clean packages clears software packages in the cache directory
Yum clean headers clears the headers in the cache directory
Yum clean oldheaders clears the old headers in the cache directory
Yum clean, yum clean all (= yum clean packages; yum clean oldheaders) clears the software packages in the cache directory and the old headers
1.6 for example, to install a game program group
Look for it first:
#: yum grouplist
As you can see, the name of the installable game package is "Games and Entertainment" so that it can be installed:
#: yum groupinstall "Games and Entertainment"
All the game packages will be installed automatically. Here the name of Games and Entertainment must be selected in double quotation marks, because the space encountered under linux will think that the file name is over, so you must tell the system that the name of the installed package is "Games and Entertainment" rather than "Games".
In addition, you can modify the configuration file / etc/yum.conf to select the installation source. You can see how convenient it is for yum to configure the program. More detailed options and commands, of course, at the command prompt: man yum
Yum groupinstall "KDE (K Desktop Environment)"
Yum install pirut k3b mikmod
Yum groupinstall "Server Configuration Tools"
Yum groupinstall "Sound and Video"
# yum groupinstall "GNOME Desktop Environment"
Yum groupinstall "Legacy Software Support"
Yum groupinstall "Development Libraries"
Yum groupinstall "Development Tools"
# yum groupinstall "Windows File Server"
Yum groupinstall "System Tools"
Yum groupinstall "X Window System"
Yum install php-gd
Yum install gd-devel
Yum groupinstall "Chinese Support"
# yum install samba-common / / this execution will install samba-client together
# yum install samba
Yum install gcc
Yum install cpp
Yum install gcc-c++
Yum install ncurses
Yum install ncurses-devel
Yum install gd-devel php-gd
Yum install gd-devel
Yum install gcc
Yum install cpp
Yum install gcc-c++
Yum install ncurses
Yum install ncurses-devel
Yum install gd-devel php-gd
Yum install gd-devel
Yum install zlib-devel
Yum install freetype-devel freetype-demos freetype-utils
Yum install libpng-devel libpng10 libpng10-devel
Yum install libjpeg-devel
Yum install ImageMagick
Yum install php-gd
Yum install flex
Yum install ImageMagick-devel
# yum install system-config-bind
# yum groupinstall "DNS Name Server" / / install bind and bind-chroot suites
Yum groupinstall "MySQL Database"'
Yum clean all
It's tricky to install a fedora linux that can't be typed in Chinese, and you can't even search the solution. I can only try my luck with a few pinyin to see if Google can recognize it. And that's what happened to me.
Solution:
Yum install scim*-y
2 yum command details 2:
Redhat and Fedora software installation command is rpm, but the biggest trouble to install software with rpm is the need to manually find a series of dependencies needed to install the software, not to mention the super trouble, if the software does not need to be uninstalled, it is very annoying that other software cannot be used due to uninstalling a dependency. Happily, Fedora finally launched a command yum similar to apt in ubuntu, making the installation of Fedora software simple and easy. Yum has the following characteristics:
Multiple repositories can be configured simultaneously (Repository)
Concise configuration file (/ etc/yum.conf)
Automatically resolve dependency issues encountered when adding or deleting rpm packages
Easy to use
* maintain consistency with RPM database
Yum, short for Yellow dog Updater Modified, was originally developed by Terra Soft, the developer of the yellow dog distribution, and written in python. At that time, it was also called yup (yellow dog updater), and later improved by the Linux@Duke development team at Duke University. The purpose of yum is to automatically upgrade, install / remove rpm packages, collect information about rpm packages, check dependencies, and automatically prompt users for resolution. The key point of yum is to have a reliable repository, as the name implies, this is a software repository, it can be a http or ftp site, it can also be a local software pool, but it must contain the header of rpm. Header includes all kinds of information about rpm packages, including descriptions, functions, provided files, dependencies, etc. It is the collection and analysis of these header that automates the remaining tasks.
All the configuration information of 1.yum is stored in a configuration file called yum.conf, which is usually located in the / etc directory, which is the top priority of the entire yum system. I have looked at this file in F9. Let's take a look at this file:
[hanlong@localhost F9 commonly used documents] $sudo more / etc/yum.conf
[main]
Cachedir=/var/cache/yum
Keepcache=0
Debuglevel=2
Logfile=/var/log/yum.log
Exactarch=1
Obsoletes=1
Gpgcheck=1
Plugins=1
Metadata_expire=1800
PUT YOUR REPOS HERE OR IN separate files named file.repoin / etc/yum.repos.d
The following is a brief description of this document:
The directory of the cachedir:yum cache, where yum stores downloaded rpm packages and databases, usually / var/cache/yum.
Debuglevel: debug level, 0 ── 10, default is 2
The log file for logfile:yum. The default is / var/log/yum.log.
Exactarch, there are two options 1 and 0, indicating whether to upgrade only packages that are consistent with your installation package cpu. If set to 1, then if you install an i386 rpm, yum will not upgrade with 686 packages.
Gpgchkeck= has two choices of 1 and 0, which represent whether or not to perform a gpg check. if not, it seems to be checked by default.
two。 All right, next is the use of yum, first of all, use yum to upgrade the software, most of the operations of yum must have superuser permissions, of course, you can use sudo.
Yum update, this step is necessary. Yum will download rpm's header from the server's header directory and put it in the local cache, which may take some time, but what is the cost of this time compared to the convenience brought to us by yum? Header download is complete, yum will determine whether there is an updatable software package, if so, it will ask your opinion, whether to update, or y, it is always good to up to date the system all the time, then yum starts to download the software package and use to call rpm installation, which may take a certain time, depending on the number of software to be updated and the network condition, in case the network is down, it doesn't matter, just do it again. After the upgrade, just use yum check-update every day to check whether it is up-to-date, and if so, use yum update to keep the system up-to-date and plug all loopholes found. Upgrade a separate package with yum update packagename.
Now simply list some commands for yum software upgrades:
Update: I install wine with rpm one by one, first install the relationship, and then install the main package of wine, but I just found a good post on the forum, which is the local installation of yum. Parameter is-localinstall
$yum localinstall wine-
In this way, yum will automatically install all dependencies instead of installing rpm one by one, saving a lot of work.
There is also a parameter similar to his:
$yum localupdate wine-
If you have a new version of wine and you download it locally, you can update wine locally.)
2.1 make a list of all updatable software
Command: yum check-update
2.2 install all updated software
Command: yum update
2.3 install only the specified software
Command: yum install
2.4 Update only the specified software
Command: yum update
2.5 make a list of all installable software
Command: yum list
3 use yum to install and uninstall software
There is a premise that all packages installed by yum are in rpm format.
The installation command is that yum install xxx,yum will query the database to see if there is a software package, and if so, check its dependency conflict relationship. If there is no dependency conflict, it is best to download and install it; if so, it will prompt you to ask whether you want to install the dependency at the same time, or delete the conflicting package, and you can make your own judgment.
The delete command is yum remove xxx, and just like the installation, yum queries the database and gives tips for resolving dependencies.
3.1 install the software package with YUM
Command: yum install
3.2Delete software packages with YUM
Command: yum remove
3.3 use yum to query the software you want to install
We often encounter such a situation, want to install a software, only know that it is related to some aspect, but can not know its name. At this point, the query function of yum works. You can use commands like yum search keyword to search, for example, if we want to install an Instant Messenger, but we don't know what it is, we might as well use an instruction like yum search messenger to search, yum will search the descriptions of all available rpm and list all the rpm packages related to messeger in the description, so we may get gaim,kopete and so on, and choose from them.
Sometimes we come across the installation of a package, but do not know its purpose, we can use the yum info packagename instruction to get information.
1. Use YUM to find software packages
Command: yum search
two。 List all installable software packages
Command: yum list
3. List all updatable software packages
Command: yum list updates
4. List all installed packages
Command: yum list installed
5. List all packages that are installed but not within Yum Repository
Command: yum list extras
6. List the specified software packages
Command: yum list 7. Use YUM to get package information
Command: yum info 8. List information for all software packages
Command: yum info
9. List all updatable package information
Command: yum info updates
10. List all installed package information
Command: yum info installed
11. List all software packages installed but not within Yum Repository
Command: yum info extras
twelve。 List the files provided by the software package
Command: yum provides
3.4 clear the YUM cache
Yum stores downloaded packages and header in cache instead of automatically deleting them. If we think they take up disk space, we can clear them using the yum clean directive. More precisely, yum clean headers clears header,yum clean packages clears downloaded rpm packages, yum clean all clears all
1. Clear the software packages under the cache directory (/ var/cache/yum)
Command: yum clean packages
two。 Clear the headers under the cache directory (/ var/cache/yum)
Command: yum clean headers
3. Clear the old headers under the cache directory (/ var/cache/yum)
Command: yum clean oldheaders
4. Clear the software packages under the cache directory (/ var/cache/yum) and the old headers
Command: yum clean, yum clean all (= yum clean packages; yum clean oldheaders)
The use of all the above command parameters can be viewed with man:
1. Install graphical version of yumex:yum install yumex.
2. Install additional software repositories:
Rpm.livna.org 's software package repository:
Rpm-ivh http://livna-dl.reloumirrors.net... Ease-7-2.noarch.rpm
Freshrpms.net 's software package repository:
Rpm-ivh http://ftp.freshrpms.net/pub/fre... 1.1-1.fc.noarch.rpm
3. Install the fastest source yum install yum-fastestmirror
Resources are really very rich, from Centos to Ubuntu,ISO mirrors, upgrade packages, everything, handed in brothers are really happy, envy ah. But fortunately, we are at least in the education network, make do can also get some light, download some.
The website is ftp://ftp.sjtu.edu.cn/
The repo of the corresponding yum is
[updates]
Name=Fedora updates
Baseurl= ftp://ftp.sjtu.edu.cn/fedora/linux/updates/$releasever/$basearch/
Enabled=1
Gpgcheck=0
[fedora]
Name=Fedora $releasever-$basearch
Baseurl= ftp://ftp.sjtu.edu.cn/fedora/linux/releases/$releasever/Everything/$basearch/os/
Enabled=1
Gpgcheck=1
Gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY
If apt Manager is installed on the machine, the corresponding source is
Repomd ftp://ftp.sjtu.edu.cn/ fedora/linux/updates/$ (VERSION) / $(ARCH) /
Repomd ftp://ftp.sjtu.edu.cn/ fedora/linux/releases/$ (VERSION) / Everything/$ (ARCH) / os/
This is somewhat different from the format of the previous yum source and needs to be noted.
Here's how to install scim under fedora.
1. What input method suits me?
Fcitx and scim are good input methods at present, but their characteristics are different. Fcitx can only input Chinese, while scim can use different code tables to achieve Chinese, English and Japanese. And so on, the input of various languages. If you only know Chinese, or can only type in English-Chinese, then fcitx is a good choice because it is beautiful, small and practical. If you also need to enter Japanese or other languages, you should install scim. With a reasonable configuration, it allows you to enter whatever language you want to enter, and use whatever input method you want to use in the same language, just like in windows. Scim is very expandable and stable, so I chose scim.
2. What preparations are required before installing a new input method?
If you choose fcitx or scim, then I suggest you delete the Chinese input method that comes with the system. The methods are as follows:
Rpm-qa | grep iiimf | xargs rpm-e
Rpm-qa | grep Chinput | xargs rpm-e
If any line prompts rpm: no packages given for erase, it means you don't have the input method in your system, don't worry, just read on.
To be clear: rpm-qa lists all installed rpm packages, grep iiimf selects those packages whose names contain iiimf, and xargs rpm-e means to delete the packages listed above. The function of Xargs is to take the data passed through | as the parameter of the following command. It's like a filter that first holds all the installation packages, then grep leaves only rpm packages with certain keywords, and then deletes the rest of these packages containing certain keywords through a combination of xargs and rpm-e. In this way, the purpose of deleting the input method and related packages is achieved. The same is true of the following Chinput, which will not be repeated here. If you also install other input methods, such as you originally installed fcitx, now want to install scim, then you'd better imitate the above to delete fcitx, the way is to change the location of iiimf to fcitx.
It is best to do this before installing a new input method, because it is not good for multiple input methods to exist in one system at the same time, you can only use one, and they may have problems at the same time. You also know that they compete with each other. So after that, you should make sure that there is no Chinese input method in the system. Verify in a way similar to the following:
Whereis fcitx
Whereis scim
Whereis miniChinput
...
3. When is the input method called by the system?
Many people don't know when the input method is entered by load, and of course they don't know why sometimes they can't call out the input method (because it may not be called in at all) and certainly don't know how to configure it to meet their own requirements.
As everyone knows, there are two desktop systems commonly used under linux, gnome and kde. It doesn't matter, they are actually built on top of the X system. To put it simply, the X system is a core and lowest-level desktop system. Gnome, kde, or other fvwm is just another layer of software between the X system and the user. So in order to achieve that no matter what desktop system you use, you can call in the input method, that is, when the X system starts, the input method can be started, so after that, no matter what desktop you are using, whether you are using gnome or kde or any other desktop, you can call in the input method. Because when it is their turn to start, the X system has been started and the input method has been called in by the system. So how does the X system start? Let's start with startx.
No matter what desktop system you use, it is started through startx, so what on earth is startx? An application or a script file? Why can it start various desktop systems and set it up according to the corresponding configuration file? With doubt, I typed whereis startx in console.
After finding the path to the startx, open it with an editor and find that it turned out to be a script file. The content of this script file may vary depending on the release, if you know some shell language, then you can try to have a look, not necessarily understand all, but you will find that after a rough look, there is a xinit command, and then follow some parameters. I try to type xinit under console (note, do not do this in the graphical interface)
Found that the graphical interface starts to pull, but it is very ugly, there is no function, the mouse can be moved, and there is a small window where you can enter commands. How do you get out? Ctrl+alt+backspace. I see, startx is just a script, which analyzes the settings of a series of configuration files and finally uses the xinit command to start the graphical interface. Both kde and gnome are done in this script. So let's open the startx script again and see what else is done in it. If you take a closer look, you will find that one thing is very conspicuous, that is, / etc/X11/xinit / xinitrc. This xinitrc seems to be familiar. You can always see it in other posts that configure the input method. There must be this script running inside. Look at some other things, in fact, they all use shell to configure a xinit startup parameter, which is used to configure the desktop system, regardless of it. What is known so far is that when startx executes a / etc/X11 / xinit/xinitrc script, let's open it and see what's inside.
When I open it, one of the paragraphs I find most valuable is a for loop that executes all the scripts under / etc / X11/xinit/xinitrc.d/ in turn. You can look for it patiently, and you will find it. So what is in this catalog? There is a file that is related to input by looking at the name. His name is xinput. Wait, let's figure out how to get from startx to xinput.
The first is to execute the startx script file, in which he will execute the xinitrc script, and then the xinitrc script is called xinput. OK, let's go ahead and open the xinput.
4. Install the package
Rpm-Uvh scim-0.8.2-1.i586.rpm
Rpm-Uvh scim-chinese-0.2.6-1.i586.rpm
5. Modify the configuration file
The next important step is to modify it.
/ etc / X11/xinit/xinitrc.d/xinput file, so that SCIM also starts when X starts. I read a lot of articles on the Internet also said, but always misses the point, after their own test, the simplest thing is to replace all the Chinput in the xinput file with SCIM,chinput and scim, and save and restart X.
Zh_CN*)
If [- e / usr/bin/scim]; then
XIM= "SCIM"
Elif [- e / usr/X11R6/bin/xcin]; then
Export LC_CTYPE=zh_CN.GB2312
XIM= "xcin-zh_CN.GB2312"
Fi
..
SCIM)
XIM_PROGRAM=scim
XIM_ARGS= "- d"
Then modify / etc/gtk-2.0/gtk.immodules to find this line:
"xim"X Input Method"gtk20"/ usr/share/locale"ko:ja:zh"
Change to:
"xim"X Input Method"gtk20"/ usr/share/locale"en:ko:ja:zh"
It may indicate that the input method is also used when entering English.
After installation, run scim-setup and change the switch key of the input method to ctrl+space
(16) linux Firewall Settings
1.1 Common operations
shuts down iptables and sets its boot / non-startup
Service iptables stop, turn off the firewall
Chkconfig iptables on setting to boot boot firewall
Chkconfig iptables off setting to power on and turn off the firewall
1.2 View help
Iptables-h
Man iptables
1.3List iptables rules
Iptables-L-n
List the iptables rules and display the rule number
Iptables-L-n-- line-numbers
List iptables nat rules (default is filter)
Iptables-L-n-t nat
1.4 clear default rules
(note that the default is filter table. If you want to add-t nat to the nat table)
# know all the rules
Iptables-F
# restart iptables found that the rule still exists because it is not saved
Service iptables restart
# Save configuration
Service iptables save
# disable ssh login (if the server is in the computer room, be careful)
Iptables-An INPUT-p tcp-- dport 22-j DROP
# deleting a rule
Iptables-D INPUT-p tcp-- dport 22-j DROP
-A,-- append chain appends to the last rule
-D,-- delete chain [rulenum] Delete rule rulenum (1 = first) from chain
-I,-- insert chain [rulenum] Insert in chain as rulenum (default 1=first) is added to the first rule
-p,-proto protoprotocol: by number or name, eg. Tcp', commonly used protocols include tcp, udp, icmp and all
-j,-- there are three common behaviors of jump target: ACCEPT, DROP and REJECT, but generally without REJECT, it will bring security risks.
Note: keywords such as INPUT and DROP need to be capitalized
# prohibit access to the 192.168.33.0 network segment from the eth0 network card
Iptables-An INPUT-p tcp-I eth0-s 192.168.33.0-j DROP
Iptables-An INPUT-p tcp-- dport 22-I eth0-s 192.168.33.61-j ACCEPT
# prohibit all types of data access with ip addresses other than 192.168.10.10
Iptables-An INPUT!-s 192.168.10.10-j DROP
# prohibit ping requests with ip addresses other than 192.168.10.10
Iptables-I INPUT-p icmp--icmp-type 8-s 192.168.50.100-j DROP
# extended matching: 1. Implicit extension 2. Show extension
# implicit extension
-p tcp
-- sport PORT source port
-- dport PORT target port
# display extension: use additional matching rules
-m EXTENSTION-- SUB-OPT
-p tcp-- dport 22 has the same function as-p tcp-m tcp-- dport 22
State: state extension, interface ip_contrack tracking session state
NEW: new connection request
ESTABLISHED: established connection request
INVALID: illegal connection
RELATED: associated connection
# match port range
Iptables-I INPUT-p tcp-- dport 22:80-j DROP
# match multiple ports
Iptables-I INPUT-p tcp-m multiport-- dport 22, 80, 80, 3306-j ACCEPT
# data with source port 80 is not allowed to flow out
Iptables-I OUTPUT-p tcp-- sport 80-j DROP
(17) braking script deployment
1.1 preparation work
1.1.1 httpd was installed in 192.168.133.61
1.1.2 httpd services and ports are started
1.1.3 Sftp uploaded jdk-7u45-linux-x64.tar.gz to / root directory
1.1.4 expect is installed locally
Yum install expect
1.1.5 the secret key is generated locally:
Ssh-keygen
1.2 make wget installation source
Put the software to be installed in Httpd:
On 192.68.33.61:
Cd / var/www/html
Mkdir soft/
Cp / root/jdk-7u45-linux-x64.tar.gz / var/www/html/soft/
Browser opens http://192.168.33.61/soft/
1.3 make automatic installation scripts
1.3.1 point the yum installation source of min2,min3 locally
Execute the following command on min2,min3:
Cd / etc/yum.repos.d/
Rename .repo .repo.bak * .repo
Mv CentOS-Media.repo.bak CentOS-Media.repo
Vi CentOS-Media.repo
Modify to
[c6-media] name=CentOS-$releasever-Mediabaseurl= http://192.168.33.61/repo# file:///media/CentOS/# file:///media/cdrom/# file:///media/cdrecorder/gpgcheck=1enabled=1#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6gpgkey=http://192.168.33.61/repo/RPM-GPG-KEY-CentOS-6
Or
[c6-media] name=CentOS-$releasever-Mediabaseurl= http://192.168.33.61/repo# file:///media/CentOS/# file:///media/cdrom/# file:///media/cdrecorder/gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Check whether the local source is made successfully:
Yum repolist all
1.3.2 Openssh installation
Problems with minimal installed system: lack of various commands, lack of various dependencies when installing software
There is no scp command: yum install-y openssh-clients
It has to be installed on every machine.
1.3.3 Wget installation
Yum install-y wget
1.3.4 Install_jdk.sh install a single JDK script
Vi / root/install_jdk.sh
Enter as follows:
#! / bin/bashBASE_SERVER=192.168.33.61yum install-y wgetwget $BASE_SERVER/soft/jdk-7u45-linux-x64.tar.gztar-zxvf jdk-7u45-linux-x64.tar.gz-C / usr/localcat > > / etc/profile = 1)
$# indicates the number of parameters, which is often used in loops
Both $and $@ represent a list of parameters
1.4.4 difference between $and $@
Both $and $@ denote all arguments passed to a function or script and, when not contained in double quotes, are represented by $1 $2. Output all parameters in the form of $n
When they are enclosed in double quotes, "$" takes all the parameters as a whole and outputs all parameters in the form of "$1 $2 … $n"; "$@" separates the parameters as "$1"$2". Output all parameters in the form of "$n"
1.5 operator
format: expr m _ n or $((m _ n)). Note that there should be spaces between expr operators
, for example, calculates the value of (2 + 3) × 4
1. Step by step calculation
S=expr 2 + 3
Expr $S * 4
two。 Complete the calculation in one step
Expr expr 2 + 3 * 4
Echo expr\ expr 2 + 3` * 4`
Or
$(2x3) * 4))
1.6 for cycle
The first kind:
For N in 1 2 3
Do
Echo $N
Done
Or
For N in 1 2 3; do echo $N; done
Or
For N in {1.. 3}; do echo $N; done
For cycle
The second kind:
For ((I = 0; I myid)
Mkdir / root/zklog
1.10 operate myid on min3:
Cd / root
Mkdir zkdata
Cd / root/zkdata
Echo 3 > myid
Mkdir / root/zklog
1.11 turn off three server firewalls:
Service iptables stop
1.12 three servers start the service
Cd / root/apps/zookeeper/
/ root/apps/zookeeper/bin/zkServer.sh start
Send in batches in secureCRT
1.13 View cluster status
/ root/apps/zookeeper/bin/zkServer.sh status
1. Jps (View process)
2. ZkServer.sh status (view cluster status, master-slave information)
Min1:
[root@min1 zookeeper] # zkServer.sh status
JMX enabled by default
Using config: / root/apps/zookeeper/bin/../conf/zoo.cfg
Mode: follower
Min2:
[root@min2 zkdata] # zkServer.sh status
JMX enabled by default
Using config: / root/apps/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@min3 zkdata] # zkServer.sh status
JMX enabled by default
Using config: / root/apps/zookeeper/bin/../conf/zoo.cfg
Mode: leader
1.14 Test: stop min3 and observe the new voting results
Execute on min3:
[root@min3 zkdata] # jps
2183 Jps
2079 QuorumPeerMain
[root@min3 zkdata] # kill-9 2079
Execute: zkServer.sh status
Min1:
[root@min1 zookeeper] # zkServer.sh status
JMX enabled by default
Using config: / root/apps/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[change to leader]
Min2:
[root@min2 zkdata] # zkServer.sh status
JMX enabled by default
Using config: / root/apps/zookeeper/bin/../conf/zoo.cfg
Mode: follower
Min3:
[root@min3 zkdata] # zkServer.sh status
JMX enabled by default
Using config: / root/apps/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
(22) zookeeper structure and commands
1.1 two main functions of zookeeper:
Read and write data: often status information or configuration information
Provide snooping: discover changes in data
1.2 zookeeper featur
1. Zookeeper: a cluster composed of leader and multiple follower
2. Global data consistency: each server keeps a copy of the same data. No matter which server the client connects to, the data is consistent.
3. Distributed read and write, and update request forwarding, implemented by leader
4. Update requests are carried out in order, and update requests from the same client are executed in the order in which they are sent.
5. Data update is atomic. Either a data update succeeds or fails.
6. Real-time, client can read the latest data within a certain time range.
1.3 zookeeper data structure
1. Hierarchical directory structure, named in accordance with the general file system specification (see figure below)
2. Each node is called znode in zookeeper, and it has a unique path identification
3. Node Znode can contain data and child nodes (but nodes of EPHEMERAL type cannot have child nodes, which will be explained in more detail on the next page)
4. Client applications can set monitors on the node (explained in more detail later)
1.4 data structure diagram
1.5 read and write node data:
1.5.1 Command Line to connect to the zk server
ZkCli.sh
The following information is returned:
[root@min1] # zkCli.shConnecting to localhost:21812018-11-130730 myid:]-INFO [main:Environment@100]-Client environment:zookeeper.version=3.4.5-1392090 Built on 09Action30Univer.2012 17:52 GMT2018-11-13 07 myid [myid:]-INFO [main:Environment@100]-Client environment:host.name=min12018-11-13 07 Discovery 30 myid 14095 [myid:]-INFO [main:Environment@100]-Client environment:java.version=1.7.0_452018-11-13 07 30 myid 14099 [myid:]-INFO [main:Environment@100]-Client environment:java.vendor=Oracle Corporation2018-11-13 07 30 Swiss 14099 [myid:]-INFO [main:Environment@100]-Client environment:java.home=/root/apps/jdk1.7.0_45/jre2018-11-13 07 main:Environment@100 30 Client environment:java.home=/root/apps/jdk1.7.0_45/jre2018 14 100 [myid:]-INFO [main:Environment@100]-Client environment:java.class.path=/root/apps/zookeeper/bin/../build/classes:/root/apps/zookeeper/bin/../build/lib/.jar:/root/apps/zookeeper/bin/../lib/slf4j- Log4j12-1.6.1.JarVERGUTERGUTERAPHER-1.6.1.JarVERGER appssZOOKEPER BINGER 3.2.Final.jarJARJUR UBREX rootGOOKEPEREBING BINGER. . / zookeeper-3.4.5.jar:/root/apps/zookeeper/bin/../src/java/lib/.jar:/root/apps/zookeeper/bin/../conf:2018-11-13 07 30 main:Environment@100 14 100 [myid:]-INFO [main:Environment@100]-Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib2018-11-13 07 30 main:Environment@100 14 101 [myid:] -INFO [main:Environment@100]-Client environment:java.io.tmpdir=/tmp2018-11-13 07 myid [myid:]-INFO [main:Environment@100]-Client environment:java.compiler=2018-11-13 07 myid [myid:]-INFO [main:Environment@100]-Client environment:os.name=Linux2018-11-13 07 30 myid [myid:]-INFO [main:Environment@100]-Client environment:os.arch=amd642018-11-13 07 30 Client environment:os.version=2.6.32 14103 [myid:]-INFO [main:Environment@100]-Client environment:os.version=2.6.32-573.el6.x86_642018-11-13 07 main:Environment@100 30 INFO 14 104 [myid:]-INFO [main:Environment@100]-Client environment:user.name=root2018-11-13 07 30 main:Environment@100 14 105 [myid:]-INFO [main:Environment@100]-Client environment:user.home=/root2018-11-13 07 30 main:Environment@100 [myid:]-INFO [main : Environment@100]-Client environment:user.dir=/root2018-11-13 07 myid 30 myid:]-INFO [main:ZooKeeper@438]-Initiating client connection ConnectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5cf2baacWelcome to myid:]-INFO [main-SendThread (localhost:2181): ClientCnxn$SendThread@966]-Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 2018-11-13 07 main-SendThread 30 main-SendThread 14149 [myid:]-INFO [main-SendThread (localhost:2181): ClientCnxn$SendThread@849]-Socket connection established to localhost/127.0.0.1:2181, initiating sessionJLine support is enabled2018-11-13 07 30 v 14 179 [myid:]-INFO [main-SendThread (localhost:2181): ClientCnxn$SendThread@1207]-Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1670a2f4010000a Negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181 (CONNECTED) 0]
1.5.2 switching connected servers
Connect 192.168.33.62:2181 connect min2:2181
Return:
[zk: localhost:2181 (CONNECTED) 1] connect min2:21812018-11-1307 31D 44978 [myid:]-INFO [main-EventThread:ClientCnxn$EventThread@509]-EventThread shut down2018-11-130731D 44979 [myid:]-INFO [main:ZooKeeper@684]-Session: 0x1670a2f4010000a closed2018-11-130731mer [myid:]-INFO [main:ZooKeeper@438]-Initiating client connection ConnectString=min2:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7bae9cec2018-11-1307 main-SendThread 31 INFO 44988 [myid:]-INFO [main-SendThread (min2:2181): ClientCnxn$SendThread@966]-Opening socket connection to server min2/192.168.33.62:2181. Will not attempt to authenticate using SASL (unknown error) ZooKeeper-server host:port cmd args connect host:port get path [watch] ls path [watch] set path data [version] rmr path delquota [- n |-b] path quit printwatches on | off create [- s] [- e] path data acl stat path [watch] close ls2 path [watch] history listquota path setAcl path acl getAcl path sync path redo cmdno addauth scheme auth delete path [version] setquota-n |-b val path [zk: min2:2181 (CONNECTING) 2] 2018-11-13 07 : 31 min2:2181 44990 [myid:]-INFO [main-SendThread (min2:2181): ClientCnxn$SendThread@849]-Socket connection established to min2/192.168.33.62:2181 Initiating session2018-11-13 07 INFO 31 INFO 44996 [myid:]-INFO [main-SendThread (min2:2181): ClientCnxn$SendThread@1207]-Session establishment complete on server min2/192.168.33.62:2181, sessionid = 0x2670a2f1b430005, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: min2:2181 (CONNECTED) 2]
1.5.3 View nodes
Ls
[zk: min2:2181 (CONNECTED) 7] ls / [zookeeper]
1.5.4 create a node
Create / app1 "this is app1 servers parent"
[zk: min2:2181 (CONNECTED) 8] create / app1 "this is app1 servers parent" Created / app1
Ls
[zk: min2:2181 (CONNECTED) 10] ls / [app1, zookeeper]
Create / app1/server01 "192.168.33.61100"
[zk: min2:2181 (CONNECTED) 11] create / app1/server01 "192.168.33.61100" Created / app1/server01
[zk: min2:2181 (CONNECTED) 12] ls / app1 [server01]
1.5.5 get node data
Get / app1/server01
[zk: localhost:2181 (CONNECTED) 0] get / app1/server01 "192.168.33.61100" cZxid = 0x200000023 # Internal transaction number ctime = Tue Nov 13 07:58:10 CST 2018 # creation time mZxid = Tue Nov 13 07:58:10 CST 2018 # Modification time pZxid = 0x200000023 # persistent transaction cversion = 0 # create version dataVersion = 0 # data version aclVersion = 0ephemeralOwner = 0x0dataLength = 19 # data length numChildren = 0 # number of child nodes
1.5.6 create a transient node
1.5.6.1 create a transient node
[zk: localhost:2181 (CONNECTED) 2] create-e / app-emphemeral 181818Created / app-emphemeral
1.5.6.2 View Node Information
[zk: localhost:2181 (CONNECTED) 4] ls / [app1, app-emphemeral, zookeeper] # temporary nodes can be seen
1.5.6.3 exit and then link in to view node information
QuitzkCli.shls / [zk: localhost:2181 (CONNECTED) 0] ls / [app1, zookeeper] # temporary node is no longer available
1.5.7 create a node with a sequence number
[zk: localhost:2181 (CONNECTED) 18] create / test 888Created / test [zk: localhost:2181 (CONNECTED) 19] create-s / test/aa 999Created / test/aa0000000000
Continue to create
[zk: localhost:2181 (CONNECTED) 20] create-s / test/aa 999Created / test/aa0000000001 # will automatically increase the sequence number to add nodes [zk: localhost:2181 (CONNECTED) 21] create-s / test/aa 999Created / test/aa0000000002 [zk: localhost:2181 (CONNECTED) 22] create-s / test/aa 999Created / test/aa0000000003 [zk: localhost:2181 (CONNECTED) 23] create-s / test/aa 999Created / test/aa0000000004 [zk: localhost:2181 (CONNECTED) 24] create-s / test / aa 999Created / test/aa0000000005 [zk: localhost:2181 (CONNECTED) 25] create-s / test/aa 999Created / test/aa0000000006 [zk: localhost:2181 (CONNECTED) 26] create-s / test/aa 999Created / test/aa0000000007 [zk: localhost:2181 (CONNECTED) 27] create-s / test/bb 999Created / test/bb0000000008 [zk: localhost:2181 (CONNECTED) 28] create-s / test/bb 999Created / test/bb0000000009 [zk: localhost:2181 (CONNECTED) 29] create-s / test/cc 999Created / test / cc0000000010 [zk: localhost:2181 (CONNECTED) 30] create-s / test/cc 999
Create a temporary node with a sequence number
[zk: localhost:2181 (CONNECTED) 31] create-e-s / test/cc 999Created / test/cc0000000012
1.5.8 Multi-server update data synchronization
Operation on 61:
[zk: localhost:2181 (CONNECTED) 33] set / app1111cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000041mtime = Tue Nov 13 08:41:24 CST 2018pZxid = 0x200000023cversion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1 [zk: localhost:2181 (CONNECTED) 34] get / app1111cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000041mtime = Tue Nov 13 08:41:24 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1 [zk: localhost:2181 (localhost:2181) 35]
Log in 62, do:
ZkCli.sh # Login 62 [zk: localhost:2181 (CONNECTED) 0] get / app1111cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000041mtime = Tue Nov 13 08:41:24 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1 [zk: localhost:2181 (CONNECTED) 1] set / app1 222cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000046mtime = Tue Nov 13 08:43:54 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 2aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1 [zk : localhost:2181 (CONNECTED) 2] get / app1222cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000046mtime = Tue Nov 13 08:43:54 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 2aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1
View on 61
[zk: localhost:2181 (CONNECTED) 0] get / app1222cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000046mtime = Tue Nov 13 08:43:54 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 2aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1
1.6 listening for events
1.6.1 data change monitoring
61 listening:
[zk: localhost:2181 (CONNECTED) 1] get / app1 watch322cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000046mtime = Tue Nov 13 08:43:54 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 2aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1 [zk: localhost:2181 (CONNECTED) 2] WATCHER::
Modified on 62
[zk: localhost:2181 (CONNECTED) 3] set / app1 333cZxid = 0x200000022ctime = Tue Nov 13 07:55:17 CST 2018mZxid = 0x200000048mtime = Tue Nov 13 08:55:45 CST 2018pZxid = 0x200000023cversion = 1dataVersion = 3aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 1
Change on 61: note that the event is accepted only once; if you modify it, it will not be monitored.
[zk: localhost:2181 (CONNECTED) 2] WATCHER::WatchedEvent state:SyncConnected type:NodeDataChanged path:/app1
1.6.2 Child Node change listening
Turn on node listening on 61
[zk: localhost:2181 (CONNECTED) 4] ls / app1 watch [server01]
Operation on 62, add nodes
[zk: localhost:2181 (CONNECTED) 4] create / app1/app2 222Created / app1/app2
View 61
[zk: localhost:2181 (CONNECTED) 5] WATCHER:: WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/app1
[zk: localhost:2181 (CONNECTED) 5] ls / app1 [app2, server01]
1.7 Node type
1.7.1 there are two types of Znode:
Temporary (ephemeral) (disconnect and delete by yourself)
If the created client is disconnected, it will be automatically deleted
For automatic sensing of server disconnection, automatically delete after disconnection, then you will know that it does not exist.
Persistent (persistent) (disconnected without deletion)
If the created client is disconnected, it will not be automatically deleted
1.7.2 Znode has four forms of directory nodes (default is persistent)
PERSISTENT (persistent node)
PERSISTENT_SEQUENTIAL (persistent sequence / test0000000019)
EPHEMERAL (temporary node)
EPHEMERAL_SEQUENTIAL (temporary sequence / test0000000019)
The sequence identity is set when the znode is created, and a value is appended to the znode name. The sequence number is a monotonously increasing counter maintained by the parent node.
In a distributed system, the sequence number can be used to globally sort all events so that the client can infer the order of events from the sequence number
(23) zookeeper client command
Zookeeper command line operation
Run zkCli.sh-server to enter the command line tool
1. Use the ls command to view what is contained in the current ZooKeeper:
[zk: 202.115.36.251 ls 2181 (CONNECTED) 1]
2. Create a new znode, using create / zk myData. This command creates a new znode node "zk" and the string associated with it:
[zk: 202.115.36.251 create / zk "myData"
3. We run the get command to confirm whether the znode contains the string we created:
[zk: 202.115.36.251 get 2181 (CONNECTED) 3] zk
# listen for changes in this node, and when another client changes / zk, it will type the following
# WATCHER::
# WatchedEvent state:SyncConnected type:NodeDataChanged path:/zk
[zk: localhost:2181 (CONNECTED) 4] get / zk watch
4. Let's set the string associated with zk through the set command:
[zk: 202.115.36.251 set / zk "zsl"
5. Let's delete the znode we just created:
[zk: 202.115.36.251 delete / zk
6. Delete node: rmr
[zk: 202.115.36.251 rmr / zk
Zookeeper command line operation
Run zkCli.sh-server to enter the command line tool
1. Use the ls command to view what is contained in the current ZooKeeper:
[zk: 202.115.36.251 ls 2181 (CONNECTED) 1]
2. Create a new znode, using create / zk myData. This command creates a new znode node "zk" and the string associated with it:
[zk: 202.115.36.251 create / zk "myData"
3. We run the get command to confirm whether the znode contains the string we created:
[zk: 202.115.36.251 get 2181 (CONNECTED) 3] zk
# listen for changes in this node, and when another client changes / zk, it will type the following
# WATCHER::
# WatchedEvent state:SyncConnected type:NodeDataChanged path:/zk
[zk: localhost:2181 (CONNECTED) 4] get / zk watch
4. Let's set the string associated with zk through the set command:
[zk: 202.115.36.251 set / zk "zsl"
5. Let's delete the znode we just created:
[zk: 202.115.36.251 delete / zk
6. Delete node: rmr
[zk: 202.115.36.251 rmr / zk
Rmr delete node command. The rmr command differs from the delete command in that delete cannot delete a node with child nodes, but the rmr command can delete it. Note that the path is absolute.
(24) zookeeper principle
Although Zookeeper does not specify master and slave in the configuration file
However, when zookeeper works, one node is leader and the other is follower
Leader is temporarily elected through an internal election mechanism.
1.1 zookeeper's election mechanism (new cluster paxos)
A simple example is given to illustrate the whole election process.
Suppose you have a zookeeper cluster of five servers with an id of 1-5, and they are all newly started, that is, there is no historical data, and they are all the same in terms of the amount of data stored. Suppose these servers start in order and see what happens.
1) Server 1 starts, at this time, only one server is started, and the packets it sends out do not respond, so its election status has always been LOOKING.
2) Server 2 starts, and it communicates with server 1 that starts at the beginning, exchanging its election results with each other. Because neither of them has historical data, server 2 with higher id value wins, but since not more than half of the servers agree to elect it (in this case, more than half of them are 3), server 1 will continue to maintain LOOKING status.
3) Server 3 starts, and according to the previous theoretical analysis, server 3 becomes the boss of server 1Magne2, but unlike the above, three servers elected it at this time, so it became the leader of this election.
4) Server 4 starts, according to the previous analysis, server 4 should be the largest in server 1, 2, 3, 4, but since more than half of the servers have elected server 3, it can only accept the life of a younger brother.
5) Server 5 starts up, just like 4, when the younger brother.
1.2 Election mechanism for non-brand-new clusters (data recovery)
So, during initialization, the election is conducted in accordance with the above instructions, but when the zookeeper runs for a period of time, the machine down falls off and the election is re-elected, the election process is relatively complicated.
Data id, leader id and logical clock need to be added.
Data id: the new id of the data is large, and the id is updated every time the data is updated.
Leader id: this is the value in the myid we configured, one for each machine.
Logical clock: this value increases from 0, and each election corresponds to a value, that is to say: if in the same election, then this value should be consistent; the higher the logical clock value, the process update of this election leader.
The criteria for the election will be:
1. The election results with small logic clock are ignored and revoted.
2. After unifying the logic clock, the data id wins.
3. When the data id is the same, the leader id wins.
Leader is selected according to this rule.
(25) zookeeper Automated maintenance script
1.1 export and source
The usage of export
Export axi1
Export: variables are valid for this process and child processes
The usage of source
Source / etc/profile
Source: it is valid to put the variables of the script file into the current process
1.2 remote launch of zookeeper
Ssh min2 "source / etc/profile;/root/apps/zookeeper/bin/zkServer.sh start"
[root@min1 ~] # ssh min2 "source / etc/profile;/root/apps/zookeeper/bin/zkServer.sh start" JMX enabled by defaultUsing config: / root/apps/zookeeper/bin/../conf/zoo.cfgStarting zookeeper. STARTED
1.3Startup script startzk.sh
[root@min1 ~] # vi startzk.shangxinxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Log in without secret and execute
Ssh-copy-id min1
Ssh-copy-id min2
Ssh-copy-id min2
Chmod + x startzk.sh
. / startzk.sh
1.4 script stopzk.sh to stop the service
[root@min1 ~] # vi stopzk.shrunk done done "stop zkServer..." for I in1 2 3dossh min$i "source / etc/profile;/root/apps/zookeeper/bin/zkServer.sh stop"
Chmod + x stopzk.sh
. / stopzk.sh
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.