Tuning the magnetic properties of beryllium chains