Linux boot self-boot Redis service

Source: Internet
Author: User
Tags redis server


The following is how the Linux Open port command is used.

Nc-lp & (Open 23 port, Telnet)

Netstat-an | grep 23 (see if 23 ports are open)


When you do Redis, you want to boot from the 6379 port: (Essentially, the service you want to start the port from)

1. Modify the/etc/redis.confto open the background run option:

# By default, Redis does not run as a daemon. Use the ' yes ' if you need it.
# Note that Redis would write a PID file in/var/run/redis.pid when daemonized.
Daemonize Yes

2. Scripting, Vim/etc/init.d/redis: (into a shell script)

#!/bin/sh #一定要这句
# chkconfig:2345 10 90
# Description:start and Stop Redis

Path=/usr/local/bin:/sbin:/usr/bin:/bin

redisport=6379 #实际环境而定
Exec=/opt/redis-2.4.6/src/redis-server #实际环境而定
REDIS_CLI=/OPT/REDIS-2.4.6/SRC/REDIS-CLI #实际环境而定

Pidfile=/var/run/redis.pid
conf= "/opt/redis-2.4.6/redis.conf" #实际环境而定

Case "$" in
Start
If [-F $PIDFILE]
Then
echo "$PIDFILE exists, process is already running or crashed."
Else
echo "Starting Redis server ..."
$EXEC $CONF
Fi
If ["$?" = "0"]
Then
echo "Redis is running ..."
Fi
;;
Stop
if [!-F $PIDFILE]
Then
echo "$PIDFILE exists, process is not running."
Else
pid=$ (Cat $PIDFILE)
echo "Stopping ..."
$REDIS _cli-p $REDISPORT SHUTDOWN
While [-X $PIDFILE]
Do
echo "Waiting for Redis to shutdown ..."
Sleep 1
Done
echo "Redis stopped"
Fi
;;
Restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >&2
Exit 1
Esac


3. Execute Permissions:


chmod +x/etc/init.d/redis

Boot from:


# try to start or stop Redis
Service Redis Start
Service Redis Stop

# turn on Service self-boot
Chkconfig Redis on


Theoretical knowledge: (excerpt)

I. Relationship of ports and services
The port number corresponds to the corresponding service in the/etc/services file, where most of the ports can be found. Using the netstat command
The service name that is displayed is also found in this file. Some people say that the corresponding port number in this file is commented out, you can disable the port.
I tried but it didn't work, this method should be useless, is misinformation! Comment out the corresponding port number, the only function is to use Netsat
command, the service name (such as FTP) is not displayed, but the port number (such as 21) is displayed. The principle is simple: netstat cannot be/etc/services
The service name of the port number found in the file will not be displayed naturally. So the/etc/services file is just the port number and the corresponding service
Mapping relationship is not related to port startup and shutdown!
Second, check the open port of the machine
1. Netstat view ports and connections
Netstat lists the service names that are currently connected
NETSTAT-A lists the currently connected and listening service names
Netstat-an lists the port numbers that are currently connected and listening (as with the command function above, just not explaining the service name for the port number)
NETSTAT-AP lists the connected PID (process number) based on the above command, using this PID, you can use Kill to kill the connection
For example: a connected pid=111 that wants to kick out uses KILL-9 111. Ok!
NETSTAT-RN Output Routing Table
2, Nmap
Nmap 127.0.0.1 View native open ports, scan all ports
Nmap-p 1024 65535? 127.0.0.1 Scan specified port range
Nmap-pt 192.168.1.1-111? Scan a range of computers
Three, close and open ports (service)
Ways to close ports:
1, because each port has a corresponding service, so to shut down the port as long as the corresponding service to close.
2, using iptable to limit the port, so that the port can not be accessed, but the port itself is not closed.
Here only the method of shutting down the service is introduced, and the application of iptable is discussed later.
Linux boot auto-start services are generally stored in two places:
Services under the/etc/init.d/folder:
The services under this folder can be started or closed by running the appropriate script.
Example: Start the SendMail service./sendmail Start (TCP 25 port is turned on)
Close the SendMail service./sendmail Stop (Close TCP 25 port)
View the current status of the SendMail service./sendmail? Status (see if the service is running)
Services under the/etc/xinetd.d/folder:
The service under this folder needs to be changed by changing the service configuration file and restarting xinetd.
For example: To start the Auth service, open the/etc/xinetd.d/auth profile, change the "Disable=no", and save the exit. Run/etc/rc.d/init.d/xinetd restart
To stop the Auth service, open the/etc/xinetd.d/auth configuration file, change the "Disable=yes", and save the exit. Run/etc/rc.d/init.d/xinetd restart
Four, control the start-up service automatically
The above-mentioned Control service switch method is to operate after starting Linux, if I want to control which services start at Linux boot, which services shut down how to do
There are 3 ways to start a control service automatically:
1, change the corresponding folder under/ETC/RC.D:
If you login the default interface is the character interface, then modify the Rc.3 folder, if the login interface by default is a graphical interface, then modify the rc.5.
In the folder, each service is preceded by the name "K" or "s", s on behalf of the service automatically run the boot, delete it or prefix to "K" will not start the next time.
2. Use the NTSYSV command:
Enter the NTSYSV command, there will be a list of services, need to start the hit "*", simple.
3. Use the Chkconfig command:
Let a service not start automatically: for example Httpd:chkconfig--level httpd? Off; 35 refers to the operating level
Let a service start automatically: for example Httpd:chkconfig--level httpd? On;
To view the startup status of all services: Chkconfig--list
To view the startup status of a service: Chkconfig--list |grep httpd
The port and service operations are here.

Linux boot self-boot Redis service

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.