Building E5SubBot under Linux is 365 E5 renewal (including database installation process)

 wallpaper

preface

Some time ago, E5SubBot was used to renew 365 E5. After use, it was found that the E5SubBot project was indeed effective. Because the program was previously run in the background using nohup, the program will stop after running for a period of time. In order to solve this problem, I wrote a shell script myself, and then solved this problem with the help of the planned task. Later, I found that I had made a detour again. Wouldn't it be better to use systemd services?

However, I still need to record what I have written. It's meaningless to delete it directly. Here is my first script.

 #!/ bin/bash pid=`ps -aux | grep E5SubBot | grep -v 'grep' | awk '{print $2}'` if [ "$pid" != "" ]; then echo "running ..." else echo "$(date '+%Y/%m/%d %H:%M:%S'):no run,starting..." >> /root/e5cron.log echo "no run" cd /root/e5sub/ && nohup /root/e5sub/E5SubBot >> /root/e5sub/e5sub-$(date +%Y%m%d%H%M%S).log & fi

Then, in coordination with the scheduled task, execute the shell written by yourself every two hours to determine whether it has stopped running. If it has stopped, start it. If it has not stopped, ignore it.

 * */2 * * * /root/e5bot.sh

However, the above method is not a perfect solution. Later, I changed the scheme of scheduling tasks to the system d service mode. The operating system of the server I used is Centos 7. The specific process is as follows.

setup script

The following is my specific installation process in Centos 7 operating system.

Access E5SubBot project address

E5SubBot Project Github Address: https://github.com/iyear/E5SubBot/releases

Select the appropriate version

Select the corresponding version to download according to the specific situation of your server. Here I choose the E5SubBot_Linux_64bit version, which is currently used by most servers.

 wget  https://github.com/iyear/E5SubBot/releases/download/v0.2.1/E5SubBot_Linux_64bit.tar.gz

Unzip files

Unzip the file you just downloaded.

 tar xvf E5SubBot_Linux_64bit.tar.gz

The following four files are obtained, and we need to use the binary file E5SubBot.

 LICENSE README.md README_zhCN.md E5SubBot

Create folders and move files

Move the extracted file E5SubBot to the corresponding directory.

 #Create Folder mkdir /opt/e5sub #Move files mv E5SubBot /opt/e5sub/E5SubBot #Add execution permission to the file chmod a+x /opt/e5sub/E5SubBot

Installing the MYSQL database

If you have already installed the database, please go to the next step. Here I choose MYSQL5.7. If your server memory is too small, you can use MYSQL5.6 or choose to use remote MYSQL.

 #Download and install the MYSQL source wget  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm rpm -ivh mysql57-community-release-el7-10.noarch.rpm #Install Database yum install -y mysql-community-server

Select a different version database:

 #If mysql57 is not used, please select the rpm of the corresponding version at the following address #  https://repo.mysql.com/yum/ #You can also execute the following command to query all available versions yum repolist enabled | grep mysql #Disable the currently used 57 version yum-config-manager --disable mysql57-community #Select to enable using version 56 yum-config-manager --enable mysql56-community #Finally, perform the installation yum install -y mysql-community-server

Start the MySQL database:

 systemctl start mysqld.service

Get the default password of MYSQL:

 #Obtain the password automatically generated by MySQL grep password /var/log/mysqld.log

Next you should see the following text, in which t; uY? tk&S2bT Your password:

 2020-12-10T06:38:17.070043Z 1 [Note] A temporary password is generated for  root@localhost : t; uY? tk&S2bT

Login database:

 Mysql - uroot - p 'password'

Because of the default password policy of MYSQL57, the password is too simple to set:

 --Query the current password verification policy using the following SQL mysql> show variables like 'validate_password%'; --Set the MYSQL password verification policy to low mysql> set global validate_password_policy=0;

To create an e5sub database:

 --Create the e5sub database and set the code mysql> CREATE DATABASE `e5sub` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';

Create roles and assign permissions:

 --Create e5sub user and set password mysql> CREATE USER `e5sub`@`localhost` IDENTIFIED BY 'e5sub'; --Authorize all permissions of the e5sub database to the e5sub user mysql> GRANT all ON `e5sub`.* TO `e5sub`@`localhost`; --Refresh Permissions mysql> FLUSH PRIVILEGES;

The data table does not need to be created by itself. E5SubBot will automatically create a data table when it starts.

Configure E5Subbot

Create a config.yml file in the/opt/e5sub directory to configure the details of the telegram bot and mysql. If you don't know how to configure, please read the Configuration

 vim /opt/e5sub/config.yml

The configuration file contents are as follows:

 Bot_token: TOKEN of your TG robot Notice: "Here you can fill in the notification information of the robot" Admin: fill in your tg ID as administrator #socks5: 127.0.0.1:1080 errlimit: 15 cron: "1 */1 * * *" bindmax: 5 mysql: host: localhost port: 3306  user: e5sub password: e5sub database: e5sub

Of course, if you use a domestic server, you need to specify the socks5 attribute to use the proxy server. The following is a description of specific attributes.

attribute explain
bot_token The token of tg robot can be obtained through @ BotFather
socks5 [Optional] It is used to specify the socks5 proxy, for example, 127.0.0.1:1080
notice Announcement, displayed when using/help
admin Administrator tgid can be accessed through @userinfobot Get, which is used to manually execute/task tasks and get feedback on overall task execution
errlimit The maximum number of errors in a single account. When the number of errors in a single account reaches the specified number, the system will automatically unbind and send a notification. If it is set to - 1, there is no limit
bindmax Maximum number of accounts bound to a single account
cron The frequency of calling the api, using cron expressions
mysql Connection information of MySQL database

Write Systemd unit file

Edit the cell file using the vim editor.

 vim /etc/systemd/system/e5sub.service

Copy the following contents into it.

 [Unit] Description=Telegram E5Sub Bot [Service] Type=simple WorkingDirectory=/opt/e5sub ExecStart=/opt/e5sub/E5SubBot Restart=always RestartSec=30 [Install] WantedBy=multi-user.target

Set automatic startup

After editing the systemd unit file, you need to reload the service configuration file.

 systemctl daemon-reload

Then start the service.

 systemctl start e5sub

View service status.

 systemctl status e5sub

Finally, set the service auto start.

 systemctl enable e5sub

Reference Documents

systemd.service — Service unit configuration

E5SubBot#configuration

Comment area
 head portrait
     head portrait

    Thanks for sharing like one

       head portrait
      jdhdj
        
     head portrait

    The landlord, you have arranged all the tutorials for a long time, strong 👍🏻