Zimri

Zimri - xlog

生活就像海洋 🌊
github

Setting up a Factorio server on Centos

"Factorio" is a simulation and management game developed and published by slpwnd. In the game, players' spaceship crashes on an alien planet, and they need to survive and establish a factory using the resources on the planet.

Collect resources, upgrade your equipment, build infrastructure, automate production, and defeat your enemies.

Environment Preparation: Centos7.x
System Update, Change Aliyun Source for Domestic Servers, Update System Directly for Overseas Servers

1. System Update and Source Replacement#

First, backup the original source in case of unpredictable errors.

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

Import Aliyun Centos7 source.

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

or

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

Add EPEL.

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

curl -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Clear YUM cache.

yum clean all

Cache Aliyun source.

yum makecache

At this point, the source has been successfully replaced, and you can update the system (not necessary, takes a long time).

yum -y update

Remember to restart if the system is updated.

2. Centos glibc-2.18 Environment Compilation#

Install gcc and wget.

yum install gcc -y
yum install wget -y

Download glibc-2.18.tar.gz.

wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz

Private acceleration address (China).

wget https://webstation.zimri.online/share/Game/factorio/server/glibc-2.18.tar.gz

Unzip and enter glibc-2.18.

tar -xvf glibc-2.18.tar.gz
cd glibc-2.18

Create a build folder.

mkdir build

cd build

Compile.

../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

make -j4

make install

ldd --version

3. Install screen#

Screen is a full-screen window manager that allows multiplexing of a physical terminal between multiple processes.

Users can create multiple screen sessions in one screen session (or sub-session), and each screen session (or sub-session) operates like a real telnet/SSH connection window.

yum install screen -y

4. Firewall Exception#

By default, CentOS7 uses the firewalld firewall.

Check the firewall status.

firewall-cmd --state 
or
systemctl status firewalld

If "success" is returned, it means it is enabled.
If the status is "closed", the following steps can be skipped. You can choose whether to continue or not. By default, we open the firewall for security.

If the status is closed, start the firewall.

systemctl start firewalld

Enable on startup.

systemctl enable firewalld

Open the specified port for Factorio.

firewall-cmd --zone=public --add-port=34197/udp --permanent

Also add the SSH port just in case.

sudo firewall-cmd --zone=public --permanent --add-service=ssh
  1. Reload to make the configuration effective.
    Reload the firewall.
sudo firewall-cmd --reload

5. Factorio Server Preparation#

1. Download the program (latest version or as needed).#

cd ~
wget https://www.factorio.com/get-download/0.17.79/headless/linux64

2. Private acceleration address (China).#

wget https://webstation.zimri.online/share/Game/factorio/server/0.17.79/linux64

3. Unzip the compressed package.#

tar -xvf linux64
mv -f /root/factorio /opt/factorio

5. Edit the configuration file.#

Go to the /opt/factorio/data folder and edit the server-settings.example.json file.

cd /opt/factorio/data
cp server-settings.example.json server-settings.json

Some necessary settings.

"name": "[CN]Server Name",
  "description": "Server Description",
  "username": "Factorio Official Website Registered Account",
  "password": "Factorio Password",
  "token": "Set Token, format similar to b50704b226ab50704b226ab50704b226a",
  ...

6. Generate the map*#

When setting up the server for the first time, regardless of whether there is a map or not, you need to execute the command to generate the map to load it correctly.

cd /opt/factorio
./bin/x64/factorio --create ./saves/test1.zip

7. Start the server#

Because Factorio SSH commands are exclusive, use the screen command installed earlier to run it in the background.

screen -S factorio

Start the server with the specified map command.

/opt/factorio/bin/x64/factorio --config /opt/factorio/config/config.ini --port 34197 --start-server /opt/factorio/saves/test1.zip --server-settings /opt/factorio/data/server-settings.json

Start the server with the latest map in the saves folder.

/opt/factorio/bin/x64/factorio --start-server-load-latest --server-settings /opt/factorio/data/server-settings.json

Then simply exit the SSH window.

8. Management commands#

Log in to the server#

After connecting via SSH, display the SSH command line for the background execution.

screen -ls

Output

There is a screen on:
        1051.factorio_auto      (Attached)
1 Socket in /var/run/screen/S-root.

Connect to the screen session using the process ID displayed in front (the ID is dynamic).

screen -r 1051

Save immediately#

After logging in to the screen session, simply enter:

/server-save

to save the game.

Exit the Factorio server#

After logging in to the screen session, simply press Ctrl + C to shut down the server.

6. Auto Start on Boot#

Because Factorio SSH commands are exclusive, use the screen command with the latest map in the saves folder as the startup command.

Create a startup script.

cd /opt/factorio
mkdir start
cd start
touch screen.sh
vi screen.sh

Insert the following content:

screen_name="factorio_auto"
screen -dmS $screen_name

cmd="/opt/factorio/start/factorio-run.sh";
screen -x -S $screen_name -p 0 -X stuff "$cmd"
screen -x -S $screen_name -p 0 -X stuff '\n'

Save by typing

touch factorio-run.sh
vi screen.sh

Insert the following content:

/opt/factorio/bin/x64/factorio --start-server-load-latest --server-settings /opt/factorio/data/server-settings.json

Save by typing

Grant execution permissions.

chmod +x factorio-run.sh
chmod +x screen.sh

Edit rc.local and add the script created above to the last line.

vi /etc/rc.d/rc.local
... ...
/opt/factorio/start/screen.sh

Grant execution permissions.

chmod +x /etc/rc.d/rc.local
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.