With the rapid proliferation of IoT devices, the volume of data generated has reached unprecedented levels, necessitating efficient management strategies. Fog computing, complemented by 5G technologies, offers promising solutions to reduce service latency and enhance Quality of Service (QoS). However, allocating resources effectively remains challenging due to factors such as uncertainty, mobility, heterogeneity, and limited resources in fog computing environments. Traditional resource allocation (RA) algorithms often fall short of addressing these complexities. This study proposes a novel approach to RA in fog computing, utilizing a non-linear function to optimize resource allocation. An objective function is introduced, incorporating multi constraints such as resource utilization, service response rate, makespan, migration cost, and communication cost. The methodology emphasizes efficient resource allocation in crucial scenarios, facilitating rapid resource distribution where needed. The novel Coati Integrated Beluga Whale Optimization (CI-BWO) strategy is proposed to achieve optimal resource allocation in fog computing environments. By leveraging CI-BWO, this research aims to overcome the limitations of traditional RA methods and enhance the performance and scalability of fog computing applications. Finally, the superiority of the suggested strategy is assessed by comparison with many existing methods. When the task count is 200, the developed CI-BWO attained less migration cost of around 1.287, while existing models have acquired higher migration costs.